Code: Select all
Move(node, vector)
Code: Select all
Rotate(node, rotation_vector)
Code: Select all
Move(node, vector)
Code: Select all
Rotate(node, rotation_vector)
Code: Select all
void Move(ISceneNode node, vector3df vector)
{
// you need only 1 line below, choose:
node->setPosition(vector); // this changes position relatively to node's parent
node->setPosition(node->getPosition() + vector); // this changes position relatively to previous position
}
Code: Select all
void Move( ISceneNode* node, const float &distance )
{
vector3df pos = node->getPosition();
float rot = node->getRotation().Y;
pos.X += distance * cos(rot * DEGTORAD);
pos.Z -= distance * sin(rot * DEGTORAD);
node->setPosition( pos );
}
void Strafe( ISceneNode* node, const float &distance )
{
vector3df pos = node->getPosition();
float rot = node->getRotation().Y - 90;
pos.X += distance * cos(rot * DEGTORAD);
pos.Z -= distance * sin(rot * DEGTORAD);
node->setPosition( pos );
}
void MovingNode( ISceneNode* node )
{
if(keys[KEY_KEY_W]) // move in the rotation'Y' direction
{
Move(node, 2);
}
if(keys[KEY_KEY_S])
{
Move(node, -2);
}
if(keys[KEY_KEY_A])
{
Strafe(node, 2);
}
if(keys[KEY_KEY_D])
{
Strafe(node, -2);
}
if(keys[KEY_KEY_Z]) // rotate
{
vector3df rot =node->getRotation();
rot.Y += 1; node->setRotation( rot )
}
if(keys[KEY_KEY_X])
{
vector3df rot = node->getRotation();
rot.Y-= 1; node->setRotation( rot );
}
}