I should mention that I'm pretty new to Matrices and will probably need a layman's answer to my question.

I have a 4D matrix which represents the rotation of an object in 3D space. I have a normalized 2D vector which represents the direction i want the object to be facing by rotating the Y axis.

I need to be able to change the Y axis rotation of the object only, by applying some sort of calculation to the XZ vector i have. What do i need to do to make this work? And if possible, can any answers come with an explanation of the process so that i can do it again on my own in the future!

  • \$\begingroup\$ So would you simply want to create a new matrix with the new facing direction? Or do you specifically want to rotate the matrix for other reasons? \$\endgroup\$ – RobM Sep 22 '15 at 12:03
  • \$\begingroup\$ Creating a new matrix would work fine \$\endgroup\$ – Lex Webb Sep 22 '15 at 12:33

I depends on the format of your 4d matrix. I'm guessing the orientation is in there somewhere. This is a way to recreate a matrix given a z & y


 Vector2d my2d; // assuming this is your 2d vector with x,z components.

 Vector3 z = new Vector3( my2d.x, 0, my2d.z);   // looking dir
 Vector3 y = new Vector3( 0,1,0);               // we'll make an upward y dir
 Vector3 x = y.cross(z);                        // y cross z gives us perpendicular to y&z

You then need to insert the xyz vectors into your matrix. I'm not sure of your matrix format but i guess they will be described as rows or columns depending if it is left/right handed coords.

The order of the cross product depends on left or right handed also. If you find that its not working try

x = z.cross(y);

  • 1
    \$\begingroup\$ Did it work for you? \$\endgroup\$ – Školstvo Dec 21 '15 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.