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 -Ty -Tz 1 |
derived from T:
T = | 1 0 0 0 |
| 0 1 0 0 |
| 0 0 1 0 |
| Tx Ty 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 |