Jump to content


DX9 Create Rotation Matrix around pivot point


  • You cannot reply to this topic
No replies to this topic

#1 Jas001

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 June 2006 - 04:57 PM

Im having some trouble rotating around a pivot point.

Would the process be to create the following Matrices and multiply them:
Offset1: Create a translation matrix based on pivot.Multiply(-1)
Offset2: Create a translation matrix based on pivot to move it back.
Create a rotate matrix by multiplying
(Offset1 * myrotation * Offset2) * existing rotation matrix

This sample code takes the original matrix, pivot point, and a vector change and creates a new matrix based on the above logic:
   private Matrix GetRotateMatrix(Matrix inmat, Vector3 pivot, Vector3 change)

        {

            Matrix offset1 = Matrix.Identity;

            Matrix offset2 = Matrix.Identity;

            Matrix rot = Matrix.Identity;


            // Setup offsets.

            offset1.Translate(Vector3.Multiply(pivot, -1));

            offset2.Translate(pivot);


            //Setup Rotation matrix.

            rot.RotateYawPitchRoll(change.X, change.Y, change.Z);


            //Combine Matrices.

            Matrix final = Matrix.Identity;

            final.Multiply(offset1);

            final.Multiply(rot);

            final.Multiply(offset2);

            final.Multiply(inmat);


            return final;

        }

It seems to work but I have problems with objects that don't have a pivot at the origin. ANy ideas?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users