Rotation part 3

Started by
3 comments, last by middy 20 years ago
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();
_velocity=v;
[edited by - middy on March 22, 2004 10:13:43 AM]
Advertisement
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]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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?
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;	ShipPitch(dt);	ShipYaw  (dt);	ShipRoll (dt);	ShipMove (dt);	xShipUp.Normalise();	xShipSide = xShipUp.Cross(xShipDir);	xShipSide.Normalise();	xShipDir = xShipSide.Cross(xShipUp);	xShipDir.Normalise();}void GameRender(void){	GLfloat fog[] = { 0.2f, 0.2f, 0.2f, 0.2f };	glClearColor	(fog[0], fog[1], fog[2], fog[3]);	glFogi			(GL_FOG_MODE, GL_LINEAR);	glFogfv			(GL_FOG_COLOR, fog);	glFogf			(GL_FOG_DENSITY, 0.75f);	glHint			(GL_FOG_HINT, GL_FASTEST);	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);	GameRenderStartfield(xEye);	GameRenderTerrain(xEye);	glDisable(GL_FOG);	GameRenderStats();}


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?

Everything is better with Metal.

This works perfectly... Thanks alot!

This topic is closed to new replies.

Advertisement