• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #Actualshazen

Posted 13 August 2013 - 08:30 AM

Get a hold of reflector so you can see how the Xna framework does it...

public static Matrix CreateFromAxisAngle(Vector3 axis, float angle)
{
Matrix matrix;
float x = axis.X;
float y = axis.Y;
float z = axis.Z;
float num2 = (float) Math.Sin((double) angle);
float num = (float) Math.Cos((double) angle);
float num11 = x * x;
float num10 = y * y;
float num9 = z * z;
float num8 = x * y;
float num7 = x * z;
float num6 = y * z;
matrix.M11 = num11 + (num * (1f - num11));
matrix.M12 = (num8 - (num * num8)) + (num2 * z);
matrix.M13 = (num7 - (num * num7)) - (num2 * y);
matrix.M14 = 0f;
matrix.M21 = (num8 - (num * num8)) - (num2 * z);
matrix.M22 = num10 + (num * (1f - num10));
matrix.M23 = (num6 - (num * num6)) + (num2 * x);
matrix.M24 = 0f;
matrix.M31 = (num7 - (num * num7)) + (num2 * y);
matrix.M32 = (num6 - (num * num6)) - (num2 * x);
matrix.M33 = num9 + (num * (1f - num9));
matrix.M34 = 0f;
matrix.M41 = 0f;
matrix.M42 = 0f;
matrix.M43 = 0f;
matrix.M44 = 1f;
return matrix;
}


Don't forget this depends on the axis parameter being unit length.

### #1shazen

Posted 13 August 2013 - 08:29 AM

Get a hold of reflector so you can see how the Xna framework does it...

public static Matrix CreateFromAxisAngle(Vector3 axis, float angle)
{
Matrix matrix;
float x = axis.X;
float y = axis.Y;
float z = axis.Z;
float num2 = (float) Math.Sin((double) angle);
float num = (float) Math.Cos((double) angle);
float num11 = x * x;
float num10 = y * y;
float num9 = z * z;
float num8 = x * y;
float num7 = x * z;
float num6 = y * z;
matrix.M11 = num11 + (num * (1f - num11));
matrix.M12 = (num8 - (num * num8)) + (num2 * z);
matrix.M13 = (num7 - (num * num7)) - (num2 * y);
matrix.M14 = 0f;
matrix.M21 = (num8 - (num * num8)) - (num2 * z);
matrix.M22 = num10 + (num * (1f - num10));
matrix.M23 = (num6 - (num * num6)) + (num2 * x);
matrix.M24 = 0f;
matrix.M31 = (num7 - (num * num7)) + (num2 * y);
matrix.M32 = (num6 - (num * num6)) - (num2 * x);
matrix.M33 = num9 + (num * (1f - num9));
matrix.M34 = 0f;
matrix.M41 = 0f;
matrix.M42 = 0f;
matrix.M43 = 0f;
matrix.M44 = 1f;
return matrix;
}


PARTNERS