Jump to content
  • Advertisement
ritzmax72

Why is the benefit of using XMVectorGetX(XMVector3Dot(Origin, Look)) than just calling XMVectorGetX(Origin)

Recommended Posts

Hi All, So there are SIMD instructions provided by DirectX. There are lots of functions but there isn't a full or semi full guide on how to use them in place of conventional

arithmetic instructions. Among them I found one Walk function for Camera to move it in Z direction. The code is written like 
float x = -XMVectorGetX(XMVector3Dot(Origin, Right));

float y = -XMVectorGetX(XMVector3Dot(Origin, Up));

float z = -XMVectorGetX(XMVector3Dot(Origin,Look));

These will go into View matrix's last row form translating the Camera.
What is the benefit of calling GetX every time on appropriate DotProduct-ed vector instead of getting x,y,z coordinates of Origin like below?

float x' = XMVectorGetX(Origin);

float y' = XMVectorGetY(Origin);

float z' = XMVectorGetZ(Origin);

 

Share this post


Link to post
Share on other sites
Advertisement

XMVector3Dot returns a 4 component vector with all components set to the dot product value.

In order to get a float, you must call XMVectorGet(X/Y/Z/W) in order to extract a single float value from the vector.

Share this post


Link to post
Share on other sites

@KulSeran

2 minutes ago, KulSeran said:

XMVector3Dot returns a 4 component vector with all components set to the dot product value.

In order to get a float, you must call XMVectorGet(X/Y/Z/W) in order to extract a single float value from the vector.

I was asking what is the benefit of getting coordinates as in x y z over getting coordinates as in x' y' z'.
Look how it is getting y value. It is first doing dot product of two vectors(Origin and Up). Up being having only y component with value 1.
So the producte-ed XMVECTOR will have value of y in  x , y, z and w of output vector.
Then it is calling XMVectorGetX on output vector, indirectly getting Origin's y. 
There are like two indirection.
Why not just use
float y' = XMVectorGetY(Origin);

Share this post


Link to post
Share on other sites
Posted (edited)
4 hours ago, ritzmax72 said:

float y' = XMVectorGetY(Origin);

It is the need to transform the Origin vector in order to use it as a translation column, they are transforming it by 3x3 matrix where rows are Right,Up,Look vectors respectively

 

 

 

Edited by JohnnyCode
formatting

Share this post


Link to post
Share on other sites

 

20 hours ago, ritzmax72 said:

What is the benefit of calling GetX every time on appropriate DotProduct-ed vector instead of getting x,y,z coordinates of Origin like below?

The original form of your camera matrix in world space would be a result of a series of transformations, typically a Rotation R followed by Translation T .  so to get world space matrix, we'd need to do W = RT . But what we want is the inverse of this transform so that every object is multiplied by it  which allows us to use the camera as reference coordinate system making every object coordinates relative to camera space. to compute inverse, We can simply go ahead and compute the inverse the usual way but this won't be a good idea as it is very costly. What you'd probably want to do is use a computation that is cheaper. The easier way to go around this is decomposing R and T from the world matrix and computing inverse on R and T individually using a cheaper method. For the rotation R, We know the camera basis vectors are orthonormal, this allows us to get inverse by simply transposing the camera basis vectors so that we have the form RT  which gives us:

RT    =     |   Ux      Vx       Wx       0 |

              |   Uy      Vy       Wy       0 |

              |   Uz      Vz       Wz       0 |

              |   0        0         0         1 |

 

where U, V and W are transposed camera basis vectors derived from the original world matrix:

R    =     |   Ux      Uy      Uz       0 |

              |   Vx      Vy       Vz       0 |

              |   Wx      Wy       Wz    0 |

              |   0        0         0        1 |

 

To get the inverse of T which is a translation, we need to negate the translation potion so that we have the form T-1 :

T-1 =         |   1      0        0        0  |

                 |   0      1        0        0  |

                 |   0       0       1        0  |

                 |   -Tx    -T     -Tz    1   |

 

derived from T:

T =         |   1      0      0       0  |

              |   0      1       0      0  |

              |   0       0       1      0  |

              |   Tx    T     Tz     1   |

 

Since we have computed the inverses the easy way/ we can multiply T-1RT  to give us view space. note that when you multiply this . you end up with the scenario you just stated to get our forth row. that is when you are doing matrix multiplication in the forth row of  T-1  by  RT you are simply doing a dot product of the forth row with the basis From transposed rotation matrix.

the result view camera matrix should be:

 

T-1RT  =  |   Ux             Vx             Wx             0 |

              |   Uy             Vy              Wy            0 |

              |   Uz             Vz              Wz            0 |

              |   -Tdot U     -TdotV       -Tdot W     1  |

 

 

 

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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!