Eldritch

26-03-2007 20:16:48

I am trying to move and rotate a SceneNode by the use of the keyboard, but it seems as if the orientation gets screwed when the node's yaw ends up between 180 and 359 degrees.

To clarify:

I have my SceneNode (with a ninja mesh). When I press W, it moves forward and S moves it backwards. I rotate it using A and D. As long as do not rotate over 180 degrees, I move in the correct directions, but as soon as I rotate more than 180 degrees, I do not move in what would have been the right direction, I keep moving in the previous direction.

To clarify the last part:

Ninja faces up +Z, rotation is 0 degrees. W moves up +Z axis.

Ninja faces down -Z, rotation is 180 degrees. W moves up +Z axis, and NOT down -Z axis as it should.

Here is the code:

Btw.. the compensation of +90 degrees in the Move function is due to the fact that the ninja faces along +Z and not +X in it's initial position, so that screws up the math a bit if I don't compensate.

To clarify:

I have my SceneNode (with a ninja mesh). When I press W, it moves forward and S moves it backwards. I rotate it using A and D. As long as do not rotate over 180 degrees, I move in the correct directions, but as soon as I rotate more than 180 degrees, I do not move in what would have been the right direction, I keep moving in the previous direction.

To clarify the last part:

Ninja faces up +Z, rotation is 0 degrees. W moves up +Z axis.

Ninja faces down -Z, rotation is 180 degrees. W moves up +Z axis, and NOT down -Z axis as it should.

Here is the code:

public void Move(float fSpeed)

{

float rot = m_refSceneNode.Orientation.Yaw.ValueRadians + (float)System.Math.PI / 2.0f;

Vector3 vec = new Vector3();

vec.x = m_refSceneNode.Position.x + (float)System.Math.Cos(rot) * fSpeed;

vec.y = m_refSceneNode.Position.y;

vec.z = m_refSceneNode.Position.z - (float)System.Math.Sin(rot) * fSpeed;

m_refSceneNode.Position = vec;

}

public void Rotate(float fSpeed)

{

m_refSceneNode.Yaw(new Radian(fSpeed));

}

Btw.. the compensation of +90 degrees in the Move function is due to the fact that the ninja faces along +Z and not +X in it's initial position, so that screws up the math a bit if I don't compensate.