Movement Of Model Based On Rotation
Posted: Mon Jul 09, 2007 2:33 am
I'm having difficulty with the following code, this seems correct to me, but i'm moving in weird directions. Any help is appreciated.
core::vector3df playerpos = node->getPosition();
core::vector3df playerrot = node->getRotation();
int lastFPS = -1;
f32 angle = 0.0f;
core::vector3df billpos = bill->getPosition();
std::cout << playerrot.X << " " << playerrot.Y << " " << playerrot.Z;
while(device->run())
if (device->isWindowActive())
{
playerpos = node->getPosition();
playerrot = node->getRotation();
angle = playerrot.Y;
if (playerrot.Y < 0)
angle = 360 + angle;
//***** Craig's Event Code For KeyDown Stuff
if (receiver.isKeyPressed(KEY_KEY_W))
pspeed = 1;
if (receiver.isKeyPressed(KEY_KEY_S))
pspeed = - 1;
if (receiver.isKeyPressed(KEY_KEY_A))
playerrot.Y -= 1.0f;
if (receiver.isKeyPressed(KEY_KEY_D))
playerrot.Y += 1.0f;
if (receiver.isKeyPressed(KEY_KEY_I))
billpos.X += 1.0f;
if (receiver.isKeyPressed(KEY_KEY_K))
billpos.X -= 1.0f;
if (receiver.isKeyPressed(KEY_KEY_J))
billpos.Z += 1.0f;
if (receiver.isKeyPressed(KEY_KEY_L))
billpos.Z -= 1.0f;
if (playerrot.Y >= 360 || playerrot.Y <= -360)
playerrot.Y = 0.0f;
if (receiver.isKeyPressed(KEY_KEY_X))
std::cout << " X " << playerrot.X << " Y " << playerrot.Y << " Z " << playerrot.Z << " Angle " << angle << " PlayerX " << playerpos.X << " PlayerZ " << playerpos.Z << " BillX " << billpos.X << " BillY " << billpos.Z << std::endl;
// position code based on direction
// we move + x or - x depending on angle
if (angle > 90 && angle < 270) {
playerpos.X -= pspeed * std::cos(angle);
}
else {
playerpos.X += pspeed * std::cos(angle);
}
if (angle > 0 && angle < 180) {
playerpos.Z -= pspeed * std::sin(angle);
}
else {
playerpos.Z += pspeed * std::sin(angle);
}
// end position code
bill->setPosition(billpos);
node->setPosition(playerpos);
node->setRotation(playerrot);
camera->setRotation(playerrot);
camera->setTarget(playerpos);
pspeed = 0;
//***** End Craig's Code *******************
core::vector3df playerpos = node->getPosition();
core::vector3df playerrot = node->getRotation();
int lastFPS = -1;
f32 angle = 0.0f;
core::vector3df billpos = bill->getPosition();
std::cout << playerrot.X << " " << playerrot.Y << " " << playerrot.Z;
while(device->run())
if (device->isWindowActive())
{
playerpos = node->getPosition();
playerrot = node->getRotation();
angle = playerrot.Y;
if (playerrot.Y < 0)
angle = 360 + angle;
//***** Craig's Event Code For KeyDown Stuff
if (receiver.isKeyPressed(KEY_KEY_W))
pspeed = 1;
if (receiver.isKeyPressed(KEY_KEY_S))
pspeed = - 1;
if (receiver.isKeyPressed(KEY_KEY_A))
playerrot.Y -= 1.0f;
if (receiver.isKeyPressed(KEY_KEY_D))
playerrot.Y += 1.0f;
if (receiver.isKeyPressed(KEY_KEY_I))
billpos.X += 1.0f;
if (receiver.isKeyPressed(KEY_KEY_K))
billpos.X -= 1.0f;
if (receiver.isKeyPressed(KEY_KEY_J))
billpos.Z += 1.0f;
if (receiver.isKeyPressed(KEY_KEY_L))
billpos.Z -= 1.0f;
if (playerrot.Y >= 360 || playerrot.Y <= -360)
playerrot.Y = 0.0f;
if (receiver.isKeyPressed(KEY_KEY_X))
std::cout << " X " << playerrot.X << " Y " << playerrot.Y << " Z " << playerrot.Z << " Angle " << angle << " PlayerX " << playerpos.X << " PlayerZ " << playerpos.Z << " BillX " << billpos.X << " BillY " << billpos.Z << std::endl;
// position code based on direction
// we move + x or - x depending on angle
if (angle > 90 && angle < 270) {
playerpos.X -= pspeed * std::cos(angle);
}
else {
playerpos.X += pspeed * std::cos(angle);
}
if (angle > 0 && angle < 180) {
playerpos.Z -= pspeed * std::sin(angle);
}
else {
playerpos.Z += pspeed * std::sin(angle);
}
// end position code
bill->setPosition(billpos);
node->setPosition(playerpos);
node->setRotation(playerrot);
camera->setRotation(playerrot);
camera->setTarget(playerpos);
pspeed = 0;
//***** End Craig's Code *******************