When I remove the rotation, the bike sounds correct, but when I add it, I got a very strange result, where some parts of the bike are not at the correct position and the correct orientation.
it = navigator.Select("child::*", NSManager);
while (it.MoveNext())
{
switch (it.Current.Name)
{
case "lookat":
LookAt(it.Current);
break;
case "matrix":
Matrix(it.Current);
break;
case "rotate":
Rotate(it.Current);
break;
case "scale":
Scale(it.Current);
break;
case "skew":
Skew(it.Current);
break;
case "translate":
Translate(it.Current);
break;
case "instance_geometry":
InstanceGeometry(it.Current);
break;
}
}
public void Translate(XPathNavigator navigator)
{
Node node = _nodes.Peek();
float[] translation = ConvertString2FloatArray(navigator.Value);
Vector3 transVector = new Vector3(translation[0], translation[1], translation[2]);
// Apply all the transformations to the same matrix
node.Rotation.Translation = node.Rotation.Translation + transVector;
}
public void Rotate(XPathNavigator navigator)
{
Node node = _nodes.Peek();
string sid = navigator.GetAttribute("sid", "");
float[] rotation = ConvertString2FloatArray(navigator.Value);
double angle = rotation[3] / 180 * System.Math.PI;
double theta = System.Math.Cos(angle / 2);
Quaternion q = new Quaternion(theta, rotation[0], rotation[1], rotation[2]);
// Apply all the transformations to the same matrix
node.Rotation = node.Rotation * q.ToRotationMatrix();
}