Empaler
25-02-2010 14:20:35
Hi
I have a small application where i have a player and a map with physics enabled. What im trying to do is when in moving the player i can look where i want without change its moving direction. when i stop moving my movement direction updates from my looking direction.
My problem is that im not beeing able to stop my movement direction from updating.
mPlayer->setVelocity(forwardSpeed, sideSpeed, DesaRad); set the orientation and destiny to the player. Im saving DesaRad from when the keys where not pressed.
Maybe im misunderstanding smt?
Thanks
I have a small application where i have a player and a map with physics enabled. What im trying to do is when in moving the player i can look where i want without change its moving direction. when i stop moving my movement direction updates from my looking direction.
My problem is that im not beeing able to stop my movement direction from updating.
// set player velocity from the user
if(mKeyboard->isKeyDown(OIS::KC_W))
{
forwardSpeed += 8.0*MovGain;
DesaUp = true;
}
else DesaUp = false;
if(mKeyboard->isKeyDown(OIS::KC_S))
{
forwardSpeed -= 5.0*MovGain;
DesaDown = true;
}
else DesaDown = false;
if(mKeyboard->isKeyDown(OIS::KC_A))
{
sideSpeed -= 5.0*MovGain;
DesaLeft = true;
}
else DesaLeft = false;
if(mKeyboard->isKeyDown(OIS::KC_D))
{
sideSpeed += 5.0*MovGain;
DesaRight = true;
}
else DesaRight = false;
if (Desacoplado == true)
{
if ((DesaUp == false)||(DesaDown == false)||(DesaLeft == false)||(DesaRight == false))
{
/* normal */
Real timestep = evt.timeSinceLastFrame;
Real rate = (60.0f * 3.1416f/ 180.0f) * timestep;
// calculate the camera Pitch Angle
int pitchDir = -mMouse->getMouseState().Y.rel/RotaGain;
cameraPitchAngle += pitchDir * rate;
if (cameraPitchAngle > 80.0f * 3.1416f/ 180.0f) cameraPitchAngle = 80.0f * 3.1416f/ 180.0f;
if (cameraPitchAngle < -80.0f * 3.1416f/ 180.0f) cameraPitchAngle = -80.0f * 3.1416f/ 180.0f;
Ogre::Quaternion pitch (Ogre::Radian(cameraPitchAngle), Ogre::Vector3 (1, 0, 0));
int yawDir = -mMouse->getMouseState().X.rel/RotaGain;
heading += Ogre::Radian(yawDir * rate);
mPlayer->setVelocity(forwardSpeed, sideSpeed, heading);
Ogre::Vector3 posit;
Ogre::Quaternion orient;
OgreNewt::Body* playerBody = mPlayer->getBody0();
playerBody->getVisualPositionOrientation (posit, orient);
orient = orient * pitch;
posit += orient * Ogre::Vector3 (0, 0, m_extenalViewDist);
// move eye point to be about the players head
posit.y += mPlayer->getPlayerHeight() * 0.75f;
mCamera->setPosition(posit);
mCamera->setOrientation(orient);
if ((DesaUp == true)||(DesaDown == true)||(DesaLeft == true)||(DesaRight == true))
{
Real timestep = evt.timeSinceLastFrame;
Real rate = (60.0f * 3.1416f/ 180.0f) * timestep;
// calculate the camera Pitch Angle
int pitchDir = -mMouse->getMouseState().Y.rel/RotaGain;
cameraPitchAngle += pitchDir * rate;
if (cameraPitchAngle > 80.0f * 3.1416f/ 180.0f) cameraPitchAngle = 80.0f * 3.1416f/ 180.0f;
if (cameraPitchAngle < -80.0f * 3.1416f/ 180.0f) cameraPitchAngle = -80.0f * 3.1416f/ 180.0f;
Ogre::Quaternion pitch (Ogre::Radian(cameraPitchAngle), Ogre::Vector3 (1, 0, 0));
int yawDir = -mMouse->getMouseState().X.rel/RotaGain;
heading += Ogre::Radian(yawDir * rate);
/* set old direction DesaRad */
mPlayer->setVelocity(forwardSpeed, sideSpeed, DesaRad);
Ogre::Vector3 posit;
Ogre::Quaternion orient;
OgreNewt::Body* playerBody = mPlayer->getBody0();
playerBody->getVisualPositionOrientation (posit, orient);
orient = orient * pitch;
posit += orient * Ogre::Vector3 (0, 0, m_extenalViewDist);
// move eye point to be about the players head
posit.y += mPlayer->getPlayerHeight() * 0.75f;
/* camera normal */
mCamera->setPosition(posit);
mCamera->setOrientation(orient);
}
}
Real timestep = evt.timeSinceLastFrame;
Real rate = (60.0f * 3.1416f/ 180.0f) * timestep;
// calculate the camera Pitch Angle
int pitchDir = -mMouse->getMouseState().Y.rel/RotaGain;
cameraPitchAngle += pitchDir * rate;
if (cameraPitchAngle > 80.0f * 3.1416f/ 180.0f) cameraPitchAngle = 80.0f * 3.1416f/ 180.0f;
if (cameraPitchAngle < -80.0f * 3.1416f/ 180.0f) cameraPitchAngle = -80.0f * 3.1416f/ 180.0f;
Ogre::Quaternion pitch (Ogre::Radian(cameraPitchAngle), Ogre::Vector3 (1, 0, 0));
DesaQuat = pitch;
int yawDir = -mMouse->getMouseState().X.rel/RotaGain;
heading += Ogre::Radian(yawDir * rate);
DesaRad = heading;
mPlayer->setVelocity(forwardSpeed, sideSpeed, heading);
Ogre::Vector3 posit;
Ogre::Quaternion orient;
OgreNewt::Body* playerBody = mPlayer->getBody0();
playerBody->getVisualPositionOrientation (posit, orient);
orient = orient * pitch;
posit += orient * Ogre::Vector3 (0, 0, m_extenalViewDist);
DesaQuat = orient;
// move eye point to be about the players head
posit.y += mPlayer->getPlayerHeight() * 0.75f;
mCamera->setPosition(posit);
mCamera->setOrientation(orient);
mPlayer->setVelocity(forwardSpeed, sideSpeed, DesaRad); set the orientation and destiny to the player. Im saving DesaRad from when the keys where not pressed.
Maybe im misunderstanding smt?
Thanks