Jump to content
  • Advertisement
Sign in to follow this  
ryt

Right, Up and Forward vectors in DirectXMath

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!