In RenderWare - each clump lives in its own 3 dimensional space. If
you want to change this clump's location within it's space you have to
"transform" it.
There are 4 script commands to do the transformation:
translate x y z
scale xs ys zs
rotate xr yr zr degree
transform m11 m21 m31 m41 m12 m22 m32 m42 m13 m23 m33 m43 m14
m24 m34 m44 (16 parameters total!)
Each has a different meaning:
translate - will move the objects relative to it's origin with
the given amount of the x,y and z
scale - will multiply/scale the corresponding directions with
the given values
rotate - the xr,yr,zr select the axis for the rotation and it
will rotate the clump around that axis with the given degree value.
transform - complex trasformation on the clump's vertices which
contains all three of above.
The sequence of those commands are critical - they are not reversible.
E.g.Let suppose you have a vertex 1 0 0 (x=10m, y-0 and z=0) . If you
do a translate 1 0 0 (move 10 meter to the right the clump) will move the
vertex to 2 0 0, and a scale 2 1 1 (magnify the x dimension by 2) will
result the vertex to be at 4 0 0. On the other hand if you start with the
scale 2 1 1 will move the vertex to 2 0 0 and after the translate 1 0 0
will move the vertex to 3 0 0. I don't even want to show an example for
the rotation here:)
To better understand how the transformations are take effect in RenderWare
I have to introduce you to the 101 of matrix algebra.
RW is using 4x4 matrices for all calculations. the matrix is like a
table which has 4 rows and 4 columns. Each vertex is represented in a vector
which is a 4 elements table only.
A vector looks like:
| V1 | V2 | V3 | V4 |
while a matrix looks like::
| M11 | M21 | M31 | M41 |
| M12 | M22 | M32 | M42 |
| M13 | M23 | M33 | M43 |
| M14 | M24 | M34 | M44 |
I denoted the elements of the matrix with the letter "M" suffixing with it's coordinate within the matrix.
The multiplication of a vector and the matrix defined as follows:
| W1 | W2 | W3 | W4 |
V * M = W as:
W1 = V1*M11+V2*M12+V3*M13+V4*M14
W2 = V1*M21+V2*M22+V3*M23+V4*M24
W3 = V1*M31+V2*M32+V3*M33+V4*M34
W4 = V1*M41+V2*M42+V3*M43+V4*M44
You can see that each resulting element is a sum of the original vector's elements multiplied by the corresponding columns in the matrix.
if your matrix is a so called "identity" matrix - the result will be
the same as the original vector. The identity matrix has a value 1 in it's
diagonal positions and 0 in all other elements.
| 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 1 |
You can verify my statement to replace the Mxx values in the equasions
above with the given matrix values.
W1 = V1*1+V2*0+V3*0+V4*0
== V1
W2 = V1*0+V2*1+V3*0+V4*0
== V2
W3 = V1*0+V2*0+V3*1+V4*0
== V3
W4 = V1*0+V2*0+V3*0+V4*1
== V4 - qed.
In RenderWare the vertex representation is a vector which is the following:
| x (width) coordinate | y (height) coordinate | z (depth) coordinate | 1 (fix value - never changed) |
The "translate tx ty tz" command's representation in a matrix
form is the following:
| 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| tx | ty | tz | 1 |
To get the new vertex values RW multiplies the vertex vector with the
translate matrix as follows:
x'=x*1+y*0+z*0+1*tx - effectively: x+tx
y'=x*0+y*1+z*0+1*ty -
" y+ty
z'=x*0+y*0+z*1+1*tz -
" z+tz
1'= x*0+y*0+z*0+1*1 where the 4th element of the vector is 1
again.
The "scale sx sy sz" command's representation in a matrix form
is the following:
| sx | 0 | 0 | 0 |
| 0 | sy | 0 | 0 |
| 0 | 0 | sz | 0 |
| 0 | 0 | 0 | 1 |
To scale a vertex RW multiplies the vertex vector with the translate
matrix as follows
x'=x*sx+y*0+z*0+1*0 - effectively: x'=x*sx
y'=x*0+y*sy+z*0+1*0 - effectively: y'=y*sy
z'=x*0+y*0+z*sz+1*0 - effectively: z'=z*sz
and the last element is 1 again:
1'=x*0+y*0+z*0+1*1
Now the rotate - the most complicated part:
The "rotate 1 0 0 d" (i.e. rotate around the x axis by
d degree) has the following matrix assigned:
| 1 | 0 | 0 | 0 |
| 0 | COS(d) | SIN(d) | 0 |
| 0 | -SIN(d) | COS(d) | 0 |
| 0 | 0 | 0 | 1 |
x'=x*1+y*0+z*0+1*0
y'=x*0+y*COS(d)+z*SIN(d)+1*0
z'=x*0-y*SIN(d)+z*COS(d)+1*0 and the last element is 1 again:
1'=x*0+y*0+z*0+1*1
The "rotate 0 1 0 d" (i.e. rotate around the y axis by
d degree) has the following matrix assigned:
| COS(d) | 0 | -SIN(d) | 0 |
| 0 | 1 | 0 | 0 |
| SIN(d) | 0 | COS(d) | 0 |
| 0 | 0 | 0 | 1 |
The "rotate 0 0 1 d" (i.e. rotate around the z axis by
d degree) has the following matrix assigned:
| COS(d) | SIN(d) | 0 | 0 |
| -SIN(d) | COS(d) | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 1 |
Those matrices multiplied by the vertex vector in the same manner as the previous examples.
The "transform m11 m21 m31 m41 m12 m22 m32 m42 m13 m23 m33 m43 m14
m24 m34 m44" (16 parameters total!) commands has the following
matrix assigned:
| m11 | m21 | m31 | m41 |
| m12 | m22 | m32 | m42 |
| m13 | m23 | m33 | m43 |
| m14 | m24 | m34 | m44 |
x' = x*m11+y*m12+z*m13+1*m14
y' = x*m21+y*m22+z*m23+1*m24
z' = x*m31+y*m32+z*m33+1*m34
1' = x*m41+y*m42+z*m43+1*m44 (for semantical reason this sum HAS TO
BE 1!)
That's all folks,
Andras