Sign in to follow this  
Raeldor

Narrowed Down Quaternion Problem... Help Needed

Recommended Posts

Raeldor    254
Hi guys, I have finally narrowed down my quaternion problem. Max gives me Euler angles of... (mymesh.transform*(inverse mymesh.parent.transform)).rotationpart as eulerangles (eulerAngles -1.65556 -78.4954 -178.423) which when expressed in max as a quaternion gives... (mymesh.transform*(inverse mymesh.parent.transform)).rotationpart (quat -0.632702 0.00248304 -0.77439 -0.00151458) When I feed those same angles as a vector into my NWQuatFromEuler function, I get the quaternion... x=0.0024830690 y=-0.63270205 z=-0.77438986 w=0.0015145428 Ie, x and y are reversed. So either max is wrong, or my quaternion from Euler function is wrong. I got this algorithm from the Math Primer for 3D Graphics and Game Development book. Here is the code...
	__forceinline Quaternion NWQuatFromEuler(Vector3 in_euler)
	{
		// translate to hpb
		float h=in_euler.x;
		float p=in_euler.y;
		float b=in_euler.z;

		// inertial to object
//		Quaternion ret;
//		ret.w=cos(h/2)*cos(p/2)*cos(b/2)+sin(h/2)*sin(p/2)*sin(b/2);
//		ret.v.x=-cos(h/2)*sin(p/2)*cos(b/2)-sin(h/2)*cos(p/2)*sin(b/2);
//		ret.v.y=cos(h/2)*sin(p/2)*sin(b/2)-sin(h/2)*cos(p/2)*cos(b/2);
//		ret.v.z=sin(h/2)*sin(p/2)*cos(b/2)-cos(h/2)*cos(p/2)*sin(b/2);

		// object to inertial
		Quaternion ret;
		ret.w=cos(h/2)*cos(p/2)*cos(b/2)+sin(h/2)*sin(p/2)*sin(b/2);
		ret.v.x=cos(h/2)*sin(p/2)*cos(b/2)+sin(h/2)*cos(p/2)*sin(b/2);
		ret.v.y=sin(h/2)*cos(p/2)*cos(b/2)-cos(h/2)*sin(p/2)*sin(b/2);
		ret.v.z=cos(h/2)*cos(p/2)*sin(b/2)-sin(h/2)*sin(p/2)*cos(b/2);

		return ret;
	}


I have tried it with both the inertial to object and object to inertial code with various orders of x,y and z, though since Max says it uses XYZ order I think the current order should be correct. I have been tearing my hair out for days on this one, but I think I am close. Any help is much appreciated. Thanks! Ray

Share this post


Link to post
Share on other sites
Psychor    202
Hey, I'm no expert but I was harassing the guys in the math forum about quaternions the other day and got some useful help. It might be worth your while checking that thread out to see if there's any information there that's useful to you: clicky.

Share this post


Link to post
Share on other sites
Raeldor    254
OMG! I finally got this working, but this is what I had to do to my QuatFromEuler function to get it to calculate the same as max...


__forceinline Quaternion NWQuatFromEuler(Vector3 in_euler)
{
// translate to hpb
float h=in_euler.x;
float p=in_euler.y;
float b=in_euler.z;

Quaternion qx=Quaternion(sin(h/2),0,0,cos(h/2));
Quaternion qy=Quaternion(0,sin(p/2),0,cos(p/2));
Quaternion qz=Quaternion(0,0,sin(b/2),cos(b/2));
qx=qx.Conjugate();
qy=qy.Conjugate();
qz=qz.Conjugate();
Quaternion ret=qx*qy*qz;
ret=ret.Conjugate();

return ret;
}




and then when calling this with the angles exported from max, I had to use...


// convert euler angles to quaternion here
Vector3 angle1=(*m_rotFrames)[left].Value;
Vector3 angle2=(*m_rotFrames)[right].Value;
angle1.x=-angle1.x;
angle2.x=-angle2.x;
angle1.y=-angle1.y;
angle2.y=-angle2.y;
Quaternion quat1=NWQuatFromEuler(angle1*(NW_PI/180.0f));
Quaternion quat2=NWQuatFromEuler(angle2*(NW_PI/180.0f));




Can anyone enlighted me as to what the hell is going on here? Is max returning the inverse of the euler to quat conversion as the quat because it is using a right handed system? Why after I negate the x and y angles (I am guessing I am not negating the 'z' because I want to convert it to left handed?) do I still have to have all the conjugation in the NWQuatFromEuler routine for it to work?

I am SO confused!!

[Edited by - Raeldor on October 7, 2005 1:46:21 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this