I was trying to animate a node using quaternions but it becomes impossible because it's Rotation property is of Coordinate type (degree rotations along x,y,z), and there are singularities when converting from Quaternion to Coordinate such that
when reaching 180 degree it will jump back to zero degree.
I tried changing the World matrix directly from the outside of the Node class but then the Rotation property would not be updated and I would also have to replicate the work done in Node::PrepareActualWork to have it work properly.
I ended up changing the Coordinate class to support another property "W", so that the Node now can have the Rotation property be a proper quaternion, and changed the PrepareActualWorld method to rotate using the given quaternion, which works perfectly.
if (_isForcePrepareMatrices || Rotation.X != 0f || Rotation.Y != 0f || Rotation.Z != 0f || Rotation.W != 0f)
var quat = new Quaternion((float)Rotation.X, (float)Rotation.Y, (float)Rotation.Z, (float)Rotation.W);
var rotationMatrix = (Matrix)quat;
//var rotationMatrix = Matrix.CreateRotation((float)Rotation.X, (float)Rotation.Y, (float)Rotation.Z);
matrix = matrix * rotationMatrix;
Another alternative includes creating another Quaternion like class which is based on the Coordinate class and changing the Node::Rotation property to be an instance of it.
For ease of use I'm using a special type converter on the Node::Rotation property so that users are still able to specify the rotation property in Xaml in a "x,y,z degree rotation way" and have it converted to quaternion automatically.
Quaternions are essential for complex animations so I believe this is the way to go. What are your thoughts?