Jump to content
  • Advertisement
Sign in to follow this  
Gl_Terminator

need and implementation of matrix.createFromAxisAngle

This topic is 2254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Did you google "axis angle matrix" and look at the first hit (wikipedia)?

 

 

Rotation matrix from axis and angle

For some applications, it is helpful to be able to make a rotation with a given axis. Given a unit vector u = (uxuyuz), where ux2 + uy2 + uz2 = 1, the matrix for a rotation by an angle of ? about an axis in the direction of u is

fbaee547c3c65ad3d48112502363378a.png[2]

 

EDIT: For a 4x4 matrix the bottom right corner will be 1 and the other entries on the 4th row and column will be 0.

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites

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.

Edited by shazen

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!