control
control
Hey all,
I wrote this code for controling my spaceship:
if(event.KeyInput.Key == KEY_KEY_W){
vector3df Target(1,0,0);
matrix4 mat;
mat.setRotationDegrees(nodeRotation);
mat.transformVect(Target);
Target.normalize();
v+= Target;
node->setPosition(v);
}
It compiles good,when i run the program it works but when i press the W key for the movment it crashes.The debugger tells me something is wrong with node->setPosition(v);
but i can't find what.
Any ideas?
Thanks
I wrote this code for controling my spaceship:
if(event.KeyInput.Key == KEY_KEY_W){
vector3df Target(1,0,0);
matrix4 mat;
mat.setRotationDegrees(nodeRotation);
mat.transformVect(Target);
Target.normalize();
v+= Target;
node->setPosition(v);
}
It compiles good,when i run the program it works but when i press the W key for the movment it crashes.The debugger tells me something is wrong with node->setPosition(v);
but i can't find what.
Any ideas?
Thanks
ok here is the mesh i want to control:
//Loads 1st mesh
IAnimatedMesh* scout = smgr->getMesh("Data/scout.3DS");
if(scout)
{
node = smgr->addOctTreeSceneNode(scout->getMesh(0));
node->setMaterialFlag(EMF_LIGHTING, false);
};
if(node)
node->setPosition(vector3df(-2000,-230,-1249));
I delcare node as global,at the begining.
//Loads 1st mesh
IAnimatedMesh* scout = smgr->getMesh("Data/scout.3DS");
if(scout)
{
node = smgr->addOctTreeSceneNode(scout->getMesh(0));
node->setMaterialFlag(EMF_LIGHTING, false);
};
if(node)
node->setPosition(vector3df(-2000,-230,-1249));
I delcare node as global,at the begining.
-
t
-
t
Sure. Here's my code.
Dec's.
My updatePlayer Code, which is called every frame from the gameloop.
Now the main loop defined in main()
Dec's.
Code: Select all
core::vector3df shipRotation;
core::vector3df ship_velocity;
core::vector3df shipspeed(3.0,3.0,3.0);
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{ if(event.KeyInput.Key == KEY_KEY_W)
{
if (event.KeyInput.PressedDown){
core::vector3df Target(0,0,1);
core::matrix4 mat;
mat.setRotationDegrees(shipRotation);
mat.transformVect(Target);
Target.normalize();
ship_velocity+= Target * shipspeed.Z;
}
}
if(event.KeyInput.Key == KEY_KEY_A)
{
if (event.KeyInput.PressedDown)
{
shipRotation.Y -= 10;
shipnode->setRotation(shipRotation);
}
}
if(event.KeyInput.Key == KEY_KEY_D)
{
if (event.KeyInput.PressedDown)
{ shipRotation.Y += + 10;
shipnode->setRotation(shipRotation);
}
}
if (camera)
return camera->OnEvent(event);
return false;
}
};
My updatePlayer Code, which is called every frame from the gameloop.
Code: Select all
void UpdatePlayer()
{
// ......
shipnode->setPosition(shipnode->getPosition() + ship_velocity);
// ....
}
Code: Select all
while(device->run())
{
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
// switch based on game state here............
UpdatePlayer();
// ........... etc..
-
Guest