Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Rotation part 3

This topic is 5234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well this is my 3rd post on the subject. I am sorry I keep spamming but each time I get a better understanding of the subject. Here is my settings. Modelspace I have in modelspace an object with a "forward" vector of (1,0,0) A rotation Quaternion storing the rotation of the model. This one is init to(0,0,0,0). In world coordinates I have a model position =(0,0,0) A velocity.(1,0,0) I move my model with eulers basic movement.
_position._x += _velocity._x *dt;
_position._y += _velocity._y *dt;
_position._z += _velocity._z *dt;
My scheme is. When ever my model is rotated I want to rotate my velocity as well. I do that by extracting the direction from the Quaternion. Todo That I use the following formula: q is rotation quaternion, x is xvector(where my ship points) q* is the congugate of q v'=qxq* This scheme works when I only do rotations about Z Axis and X axis, but not both. So a rotation of 30 degrees around z axis would work fine until I did a 30 degree upon x axis. This messes it up. What am I doing wrong, am i not including the current rotated velocity into my calcuations?. If I rotate around x and then y, then I should do the same to velocity?. As you can see I am overwriting my velocity for every rotation done.
		Quaternion	vel = new Quaternion(xVector);
		Quaternion conjugate = _currentRotation.getCongugate();
		Quaternion q =_currentRotation.mult(vel).mult(conjugate);
		Vector3 v= q.getVector();
[edited by - middy on March 22, 2004 10:13:43 AM]

Share this post

Link to post
Share on other sites
The only things I see that might be wrong are these:
The identity quaternion should be (0,0,0,1), not (0,0,0,0).
The line
Quaternion	vel = new Quaternion(xVector);  
should be
Quaternion	vel = new Quaternion(_velocity);  

[edited by - JohnBolton on March 22, 2004 6:13:15 PM]

Share this post

Link to post
Share on other sites
hey JohnBolton... Well It seemed I lied my quat was init to (0,1,0,0). I tried our changes and it made it even worse (z axis messes up too)

Maybe I need a good debugging scheme?

Share this post

Link to post
Share on other sites
well, if it works for one axis at a time, then it''s on the right tracks. you have to remember that, when you rotate the ship with one axis, you need to update the ship''s orientation as well, so the next rotation can be performed using the current X axis or Y axis.

anyway, I''ve tried it, as I said in a previous post, and Here is the code

Vector xShipPos(0, 0, 0);
Vector xShipSide(-1, 0, 0);
Vector xShipUp(0, 1, 0);
Vector xShipDir(0, 0, 1);
float fShipSpeed = 0.0f;;
float fShipPitch = 0.0f;
float fShipYaw = 0.0f;
float fShipRoll = 0.0f;

void ShipMove(float dt)
xShipPos += xShipDir * fShipSpeed * dt;

if (xShipPos.y < 10.0f)
xShipPos.y = 10.0f;

if (xShipPos.y > 1000.0f)
xShipPos.y = 1000.0f;

void ShipPitch(float dt)
Quaternion Q;
Q.FromRotation(xShipSide, fShipPitch * dt);

xShipUp = xShipUp * Q;
xShipDir = xShipDir * Q;

void ShipYaw(float dt)
Quaternion Q;
Q.FromRotation(xShipUp, fShipYaw * dt);

xShipSide = xShipSide * Q;
xShipDir = xShipDir * Q;

void ShipRoll(float dt)
Quaternion Q;
Q.FromRotation(xShipDir, fShipRoll * dt);

xShipSide = xShipSide * Q;
xShipUp = xShipUp * Q;

void GameUpdate(float dt)
xShipSide = xShipUp.Cross(xShipDir);

float fAccel = KeyPressed(''W'') - KeyPressed(''S'');
float fPitch = (mousey - 0.5f) * 2.0f;
float fYaw = KeyPressed(''A'') - KeyPressed(''D'');
float fRoll = (mousex - 0.5f) * 2.0f;

fShipSpeed = Clamp(fShipSpeed + fAccel * 0.04f, -20.0f, 20.0f);
fShipPitch = fPitch * 0.4f;
fShipYaw = fYaw * 0.2f;
fShipRoll = fRoll * 0.6f;

ShipYaw (dt);
ShipRoll (dt);
ShipMove (dt);

xShipSide = xShipUp.Cross(xShipDir);
xShipDir = xShipSide.Cross(xShipUp);

void GameRender(void)
GLfloat fog[] = { 0.2f, 0.2f, 0.2f, 0.2f };
glClearColor (fog[0], fog[1], fog[2], fog[3]);
glFogfv (GL_FOG_COLOR, fog);
glFogf (GL_FOG_DENSITY, 0.75f);
glFogf (GL_FOG_START, 10.0f);
glFogf (GL_FOG_END, 200.0f);
glEnable (GL_FOG);

Vector xEye = xShipPos;
Vector xUp = xShipUp;
Vector xTarget = xShipPos + xShipDir * 10.0f;

gluLookAt(xEye.x, xEye.y, xEye.z, xTarget.x, xTarget.y, xTarget.z, xUp.x, xUp.y, xUp.z);



if you want the demo, mail me.

also, I''m slightly concerened about you doing "new" all other the place. do you actually delete as well? And is it necessary?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!