# 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 on other sites

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

##### 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 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:

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 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.

## Create an account

Register a new account

1. 1
2. 2
Rutin
13
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633262
• Total Posts
3011128
• ### Who's Online (See full list)

There are no registered users currently online

×