I'm posting the relevant code. Any ideas? Any help is greatly appreciated.
Code: Select all
beam=smgr->getMesh("./models/Cylinder.irrmesh"); //Cylinder.irrmesh is the beam model
u32 then = device->getTimer()->getTime(); //used for framedeltatime below
u32 lastshot = then;
vector3df dir;
vector3df rot;
vector3df pos;
vector3df shift;
beamcontrol = NULL;
while(device->run())
{
//frame delta time, so we move the same distance with respect to time, not frames
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
if ((receiver.IsKeyDown(irr::KEY_KEY_W)) && ((now - lastshot) > 200))
{
lastshot = now;
// if the beam already exists then delete it
if (beamcontrol) {beamcontrol->drop(); beamcontrol = NULL; }
printf("shot!");
pos = Camera->getPosition();
dir = Camera->getTarget() -Camera->getPosition();
rot = Camera->getRotation();
shift = rot.normalize();
rot = Camera->getRotation();
beamcontrol = smgr->addMeshSceneNode(beam,0, -1, 10000.0f*core::vector3df(shift.Z, 0.0f, -shift.X), rot,core::vector3df(500, 500, 1000));
beamcontrol->setMaterialFlag(EMF_LIGHTING,false);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_Q))
{
device->drop();
return 0;
}
driver->beginScene(true, true, SColor(255,100,101,140));
if (beamcontrol)
{
beamcontrol->setPosition(beamcontrol->getPosition() + dir * speed * frameDeltaTime);
//beamcontrolright->setPosition(beamcontrolright->getPosition() + dir * speed * frameDeltaTime);
}
smgr->drawAll();
//guienv->drawAll();
driver->endScene();
}