🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Right, Up and Forward vectors in DirectXMath

Started by
4 comments, last by ryt 6 years, 4 months ago

If we for example look at vector/matrix math in Unity3D or in SimpleMath (DirectXTK) we can see that they give us the Right, Up, Forward and Left, Down, Backward vectors.
DirectXMath doesn't have this implemented. How could I extract for example Forward vector (in DirectXMath) from some matrix that stores some object position, rotation,...?

I assume that Position vector (Translation) is stored in m41, m42, 43 in DirectXMath, since it uses row-major matrix, but extracting Forward vector seems a bit more difficult to extract.

Advertisement

I found this topic, it's for D3DX but I think it's the same for DirectXMath.

Unity is a engine/ framework, DirectXMath is just a math library. You could create a camera class yourself, and give it 3 vectors (up, right, look) and then use the DirectXMath library/functions to perform the needed calculations.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

On 1/28/2018 at 1:56 PM, ryt said:

How could I extract for example Forward vector (in DirectXMath) from some matrix that stores some object position, rotation,...?

 

You only need two orthographic (="right angle") vectors, and everything else follows.

The cross product of the forward and up vector is the right vector (or left vector, if that's your world view).  Each of those three of forward, up, and right can be negated to give you reverse, down, and left.

If you have a transformation matrix, I suggest learning a bit about how a matrix is composed.  This is for row-major:
transform_matrix_explained.PNG.7cb47cb3b73be374967871c9483fc2e3.PNG

That is, if you have a graphics transformation matrix already, the three basis functions tell you the directions for forward, up, and right, the position or offset tells you the position or offset, the flag at the bottom right should be zero for vectors (that are position-less) or one for points (that have a position).  

In the identity matrix, the forward direction or x-basis is [1,0,0] since it is fully pointing in the X direction, Y is similarly 100% in the transformed Y axis, Z is 100% in the transformed Z axis.  As you turn the basis vectors also change, so the forward is transformed to some other direction, the components in each direction change as well.

 

Thanks, nice explanation. In DirectXMath since it's a row-major representation, as you mentioned, the yellow part is x^ basis vector _11, _12, _13, but if I'm correct the right vector would be _11, _21, _31 as explained in the link.

This topic is closed to new replies.

Advertisement