MonoGame is an open source version of Microsoft XNA. This is the basis for building cross-platform games.
It has a number of mathematical types, such as Vector and Quaternion.
I am a little puzzled by how they use doubling and floats.
So far, I have gathered the following information:
- floats are likely to be more effective than doubles;
- doubles accuracy than float.
Here's the method that bothers me:
public static Vector2 Transform(Vector2 value, Quaternion rotation)
{
float num1 = rotation.X + rotation.X;
float num2 = rotation.Y + rotation.Y;
float num3 = rotation.Z + rotation.Z;
float num4 = rotation.W * num3;
float num5 = rotation.X * num1;
float num6 = rotation.X * num2;
float num7 = rotation.Y * num2;
float num8 = rotation.Z * num3;
float num9 = (float) ((double) value.X * (1.0 - (double) num7 - (double) num8) + (double) value.Y * ((double) num6 - (double) num4));
float num10 = (float) ((double) value.X * ((double) num6 + (double) num4) + (double) value.Y * (1.0 - (double) num5 - (double) num8));
Vector2 vector2;
vector2.X = num9;
vector2.Y = num10;
return vector2;
}
Why not use double floats (e.g. inline num1..num8 as double expressions in num9 and num10)?
source
share