MDX Matrix.RotateX not doing what I expected...

I wrote this code:

Matrix Test = Matrix.Identity;

Test.RotateX( (float)Math.PI/2.0f );

Test.RotateY( (float)Math.PI/2.0f );

expecting it to rotate 90 degrees in X and then in Y.

But the second rotate call (RotateY), simply replaces the matrix with a Y rotation. I expected it to post-catenate the Y rotation and createa compound rotation. Is this the intended use of RotateX etc.

The help says that Matrix.RotateX "Rotates a matrix around the x-axis."

Whereas help says that Matrix.RotationX "Builds a matrix that rotates around the x-axis."

Are these methods intended to do the same thing Meaning, replace the matrix with the given rotation

I am easily able to concatenate by using the * operator of course, I just wondered what the intent was.



Answer this question

MDX Matrix.RotateX not doing what I expected...

  • EBIZME

    That's what I thought, until I tried it and it doesn't rotate the existing contents of the matrix. It replaces the contents of the matrix with a rotation matrix.

    I'm fine multiplying matrices together, I just thought maybe the instance method optimized the post-catenate, as there are many zeroes in the rotation matrix.

    Interesting that you understand that it 'should' do the same thing I expected. Maybe the help should be clarified, or the behavior changed.


  • MWatts

    Reflector is a tool that will 'guess' the original code from the IL in a .Net assembly. Get it here http://www.aisto.com/roeder/dotnet/ then open the assembly and double click the method - there is some c#... note that whilst it knows the names of all public things it has no clue about local variable names.

    MDX 2.0 is in beta right now - it came with the Oct and Dec SDKs so if you are still using the 1.1 assmeblies (which work under .Net 2.0) you are still with the times.



  • Joe M.

    What you are seeing is expected (though confusing) behaviour.

    As Pieter says Matrix.RotationX(angle) is static and returns the relevant matrix.

    myMatrix.Rotate(angle) is instance, returns nothing and sets my matrix to the relevant matrix.

    so

    m = Matrix.RotationX(angle)

    is the same as

    m.RotateX(angle)

    If you look in the code with reflector you will see that the second one just calls into native DirectX and sets the value into 'this'. I guess technically the 2nd one will be very slightly faster since the values get written directly to m in the native code whereas the static one creates a new matrix, returns it and then copies it to m.

    This is probably why the instance methods are no longer there in the MDX 2.0 assemblies.



  • JohnLudlow

    The Matrix.Rotation(X,Y,Z) methods are static methods and allow you to build rotation matrices and return them. e.g.
    Matrix matRotX = Matrix.RotationX(Geometry.DegreeToRadian(90.0f));
    The other method you were referring to is an instance method called Matrix.Rotate(X,Y,Z) which will rotate the matrix you are referring to. e.g.
    Matrix matRotX = new Matrix();
    matRotX.RotateX(Geometry.DegreeToRadian(90.0f));
    It's best that you explicitly concatenate your matrices as it will provide more logical information as to what you are trying to do. e.g.
    Matrix matRotXY = Matrix.RotationX(Geometry.DegreeToRadian(90.0f)) * Matrix.RotationY(Geometry.DegreeToRadian(90.0f));

    I hope this helps.
    Take care.


  • htezcan

    How do you look in the code with reflector That sounds like something very useful.

    Thanks for the clarification. I have ordered a copy of VS 2005 and will get with the times - I didn't know m.RotateX had been removed.

    Paul


  • MDX Matrix.RotateX not doing what I expected...