00001 #include <iostream>
00002 #include "utMath.h"
00003 #include <btBulletDynamicsCommon.h>
00004 #include <cstdio>
00005
00006 #include "Game.h"
00007 #include "Bullet.h"
00008 #include "Physics.h"
00009
00022 Bullet::Bullet(Physics* physics, H3DNode parentNodeProxy, H3DRes bulletRes, const float distance) {
00023 _activeTime = 0;
00024 _distanceToFly = distance;
00025 MAX_FLY_TIME_S = 2.5f;
00026
00027
00028 _model = h3dAddNodes(parentNodeProxy, bulletRes);
00029 _bulletProxy = parentNodeProxy;
00030 float ntx, nty, ntz;
00031 float nrx, nry, nrz;
00032 float nsx, nsy, nsz;
00033 h3dGetNodeTransform(_model, &ntx, &nty, &ntz, &nrx, &nry, &nrz, &nsx, &nsy, &nsz);
00034
00035 h3dSetNodeTransform(_model,
00036 ntx + 1, nty, ntz,
00037 -90, 10, nrz,
00038 0.05f, 0.05f, 0.05f);
00039 }
00040
00041 Bullet::~Bullet() {
00042 }
00043
00049 void Bullet::update(const float timeStep) {
00050 _activeTime += timeStep;
00051
00052 float speed = ::Values::BULLET_SPEED_M_S * _activeTime;
00053
00054
00055 float ntx, nty, ntz;
00056 float nrx, nry, nrz;
00057 float nsx, nsy, nsz;
00058 h3dGetNodeTransform(_bulletProxy, &ntx, &nty, &ntz, &nrx, &nry, &nrz, &nsx, &nsy, &nsz);
00059
00060
00061 h3dSetNodeTransform(_model,
00062 0, 0, -speed,
00063 -90, 10, nrz,
00064 nsx, nsy, nsz);
00065
00066
00067
00068 }
00069
00075 bool Bullet::isActive() {
00076
00077 if(_activeTime < MAX_FLY_TIME_S && _distanceToFly > 0) {
00078 return true;
00079 }
00080
00081 h3dRemoveNode(_model);
00082 h3dRemoveNode(_bulletProxy);
00083 return false;
00084 }
00085
00086
00088
00089
00090
00091
00092
00093
00094
00095