Advertisement

Quaternion Questions

Started by April 27, 2001 06:20 AM
0 comments, last by gimp 23 years, 9 months ago
I''m new to quats but have spent most of today toying with other peoples code and mealting my brain on math sites. I can seem to make much sence of what I''m reading. I''m currently using Nick Capen''s quat\matrix\vector code to learn from as it seems the cleanest I''ve found(at glvelocity.gamedev.net). The way I have my system organised is each object has two quats, world and local. I think I understand how to set my Euler coordinates ~
  
	float s = Cos(X / 2);
	vector v = Sin(X / 2) * vector(1,0,0);
	m_LocalRotation *= quaternion(s, v);

	s = Cos(Y / 2);
	v = Sin(Y / 2) * vector(0,1,0);
	m_LocalRotation *= quaternion(s, v);

	s = Cos(Z / 2);
	v = Sin(Z / 2) * vector(0,0,1);
	m_LocalRotation *= quaternion(s, v);
  
I have no idea if I''m getting things right as I don''t know how to get the axis\angle back out of the quat to feed to glRotate. The other problem I seem to be having is rotated translation. If I wish to rotate a moon around a planet the moon will need to have it''s translation concatinated from it''s parent(I''m cool with that) but I can''t see how I can multiply the quat against a point that way you might multiply a point and a vector. I''m probably all mixed up on this can anyone set me straight. Ideally does anyknow know of a minimal quat demo of one object rotating around another? Many thanks Chris
Chris Brodie
I use Q''s to do movement, if you search for input and Magmai you should come across the code that i''ve posted.

Each object had a 3D Vector, which is the center of the object mesh, and a Q which is the orientation of the object.

To use a Q to rotate a moon around a planet, you''d have to make the center of the rotation, the center of the planet.

So you''d apply a translation so that the planets center is at 0,0,0. Then, you need the Q equivalent of a SLERP. Then apply the rotation to the moon. And translate the planet & moon back out to where it belongs. To apply the rotation, you need to convert the Q into a vector & an angle and call the appro. GL function.

A thing the Q''s are good for, is if you have two rotations you want to concatenate; you just multiple the Q representations. The resultant Q, when translated back into a vector & an angle, gives you the resultant rotatation.

So make an ''identity'' Q, and then create a rotation Q that represents the rotation you want. Set a w:rps (radians per second) that controls how fast the moon spins around the planet, and multiply by the elapsed time. Convert this angle into a Q (can pick any vector to rotation about... just changes which direction around the planet it goes...) and multiple the existing rotation Q by this new one. The result is the new rotation, hang onto it for next time.

Might need to worry about iteration error....

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement