I've scrapped the local quaternion and 6 floats, and I'm now using only the matrix. I don't really need to know the global Euler angles, and I can easily get the global position of any entity from its matrix (M41, M42, M43).
I think I've got the following working:
Rotate()
Position()
Translate()
Move()
I also have Turn() working, but only with global angles. Turning in local space is trickier. It should work the same as Translate(), but that uses something I can't do with angles.
Also I've left scale alone for now to keep things simple I've also not done the code to update the children when a parent is altered but that shouldn't be too hard.
Here's the source for the local co-ordinates Translate() method (x/y/z describe the translation vector):
// Turn global position into local spacethis.Parent.PointToLocal(this.Transform.M41, this.Transform.M42, this.Transform.M43);// Add translation to itx = this.Parent.PointX - x;y = this.Parent.PointY - y;z = this.Parent.PointZ - z;// Set new positionMatrix M = this.Parent.Transform;M = Matrix.Translation(x, y, z) * M;this.Position(M.M41, M.M42, M.M43, true);
PointToLocal() simply runs a point through the matrix like this:
public void PointToLocal(float x, float y, float z){ Matrix M = this.Transform; M.Invert(); PointX = (M.M11 * x) + (M.M21 * y) + (M.M31 * z) + M.M41; PointY = (M.M12 * x) + (M.M22 * y) + (M.M32 * z) + M.M42; PointZ = (M.M13 * x) + (M.M23 * y) + (M.M33 * z) + M.M43;}
So - can anyone tell me if it's possible to write a QuaternionToLocal() method to run a rotation through the matrix in the same way as a point? That would enable me to finish my Turn() method.
Thanks for all the help so far!
EDIT: Tidied code.
EDIT AGAIN: I got Turn() working in local space by simply reversing the order of the matrix multiplication! However, my global Turn() doesn't seem to work quite right still.
[edited by - Rottbott on May 28, 2004 5:28:48 PM]