Ya I kept the matrices out of there as to not make it more complicated than it already is
Still yes you can write the final coordinate system E as:
E = P * Y * R * I
Where P, Y, R are the rotation matrices for the p, y, r angles, * represents matrix multiplication and I is your base matrix, if it is { (1 0 0), (0 1 0), (0 0 1) } it may be omited.
Matrix multiplication is defined as:
A * B = C
A =
| a11 a12 a13 |
| a21 a22 a23 |
| a31 a32 a33 |
B =
| b11 b12 b13 |
| b21 b22 b23 |
| b31 b32 b33 |
Then C =
| (a11b11 + a12b21 + a13b31) (a11b12 + a12b22 + a13b32) (a11b13 + a12b23 + a13b33) |
| (a21b11 + a22b21 + a23b31) (a21b12 + a22b22 + a23b32) (a21b13 + a22b23 + a23b33) |
| (a31b11 + a32b21 + a33b31) (a31b12 + a32b22 + a33b32) (a31b13 + a32b23 + a33b33) |
Note that A * B != B * A, so order is important.
If you calc the matrix E all the way then its three columns will give you the unit vectors forward, left and up.
Now you only need to know P, Y and R, which are rotation matrices. Every rotation matrix has 2 fundamental properties:
- If you square all entries in the matrix, then the sum of all squared entries in a single column will be 1; similarly the sum all squared entries in a single row will equal 1. This is because each matrix contains unit vectors which are mutually orthogonal.
- The matrix is anti-symmetrical, meaning that on each side of the main diagonal you will find the same entries, except with a - sign.
Now what the hell are my rotation matrixes?
Well they can be derived relatively easily, although it requires some knowledge of geometry.
Code: Select all
y' ^ y
^ |
| |
| |
| | ___-> x'
||___---- ) yaw angle 'a'
---------------> x
Pardon my horrible drawing but it's supposed to show 2 orthogonal vectors x and y which are rotated by an angle 'a' to form vectors x',y'.
Then basic geometry says:
x' = x * cos(a) + y * sin(a)
y' = y * cos(a) - x * sin(a)
Which can be written in matrix form like this:
Code: Select all
| x' | | cos(a) sin(a) 0 | | x |
| y' | = |-sin(a) cos(a) 0 | | y |
| z' | | 0 0 1 | | z |
Where (x,y,z) is a vector of vectors.
A nicer form is:
Code: Select all
| cos(a) sin(a) 0 |
| x' y' z' | = |-sin(a) cos(a) 0 | | x y z |
| 0 0 1 |
Where [x' y' z'] and [x y z] are matrices, their columns formed by the entries of the vectors x',y',z' or x,y,z.
Hence the matrix Y is the matrix above.
Code: Select all
Y =
| cos(a) sin(a) 0 |
|-sin(a) cos(a) 0 |
| 0 0 1 |
Similar matrices can be derived for pitch and roll as well, and multiplying em all together (in the right order!) gives you a pile of crap aka the rotated coordinate system matrix E, which depends only on the values of p,y,r. I presume the game uses this matrix to calculate vertex locations etc for rotated objects.