DX9 Create Rotation Matrix around pivot point

Jas001 101 Jun 14, 2006 at 16:57

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));

            //Setup Rotation matrix.
            rot.RotateYawPitchRoll(change.X, change.Y, change.Z);

            //Combine Matrices.
            Matrix final = Matrix.Identity;

            return final;

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

0 Replies

Please log in or register to post a reply.

No replies have been made yet.