|
Hi Silvano,
as you may know, to keep track of an object's
rotation/scale/translation, you have to use a Matrix (or a transform3D). if your
entity is rotated around say yAxis 180 degrees and you want to
translate it 1 unit (meter) along the positive xAxis, you have to translate
a temporary matrix first and then multiply it into your entity's matrix
(transform). if you try to translate the entity's matrix directly, the entity
will move to the right! (when it should move to the left). here
is document that can help you understand matrices a little
better:
_______________________________________________
Syrus Mesdaghi Full Sail Real World Education Gaming Instructor Winter Park, FL [EMAIL PROTECTED] http://www.fullsail.com _______________________________________________ Important concepts that can help you understand this document: NOTE: the fields of
matrices used in vecMath library are as
follow
m00 m01 m02 m03 m10 m11 m12 m13 m20 m21 m22 m23 m30 m31 m32 m33 in other
matrix libraries, a matrix may be in column-first
format.
m00 m10 m20 m30 m01 m11 m21 m31 m02 m12 m22 m32 m03 m13 m23 m33 1) Assume that entityMat and
delta are objects of type matrix4d:
matrix4d
entityMat,
delta; 2)
entityMat.setIdentity(); resets
the values in entityMat to become 1 0 0
0
0 1 0 0 0 0 1 0 0 0 0 1 the Identity
Matrix, represent a matrix that is at the origin (x = 0, y = 0, z =
0),
has no scale (or skew), and is oriented in such way that its Y axis is up, X axis to the right, and z axis along the Normal Vector of the screen (coming out of the screen). In Vecmath, such matrix can define the "Global" coordinate system. This is similar to OpenGL's coordinate system. X positive is to the right Y positive is up Z positive is Out of screen where as in
Multigen/Creator, the global axis
are:
X positive is to the right Y positive is into the screen Z positive is up 3) there are 16 fields in a matrix4d object. As I mentioned, the values in an Identity Matrix are as follow: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 each on of
these numbers are of type double if we use Matrix4d, and float if we use
Matrix4f.
in order to change the values in a matrix directly, you have to modify the value of one or more members variables that exist in the class matrix4d. The name of these variables are m01, m02, ... m33. the following diagram show the name of the variables and what they represent in the matrix.
1 (m00) 0
(m01) 0
(m02) 0 (m03)
(X.x r&s) (Y.x r&s) (Z.x r&s) (X position) 0 (m10) 1 (m11) 0 (m12) 0 (m13) (X.y r&s) (Y.y r&s) (Z.y r&s) (Y position) 0 (m20) 0 (m21) 1 (m22) 0 (m23) (X.z r&s) (Y.z r&s) (Z.z r&s) (Z position) 0 (m30) 0 (m31) 0 (m32) 1 (m33) (remains 0) (remains 0) (remains 0) (remains 1) to illustrate the values in an
identity matrix lets try to write down the coordinates
of the tip of each lines below. lets assume the intersection of the three lines to be at x=0, y=0, z=0 and that the length of each line is exactly 1. keep in mind that X positive is to the right, Y positive is up, and that Z positive is Out of screen (the slanted line represents a line coming out of the screen).
*2
| | | / -----*1 / *3 *1 :
x=1, y=0, z=0 : 1 0
0
*2 : x=0, y=1, z=0 : 0 1 0 *3 : x=0, y=0, z=1 : 0 0 1 as you can see these values are the same as the upper left (3x3) values in an identity matrix which represent it's Rotation and Scale (r&s). since we assumed that the intersection of the three lines are at 0,0,0 , we can place these values to the right of the values we have. we can also insert the bottom row that should not be touched. 1 0 0 0(x position,
m03)
0 1 0 0(y position, m13) 0 0 1 0(z position, m23) 0 0 0 1 (this row
should remain untouched)
lets see how we can manipulate a matrix: IMPORTANT: * the order in which you perform your translations and rotation can result in completely * different results * It is very important that you
set a matrix to identity when needed. Not paying attention to
* to this fact can introduce very tough BUGS! * All vecmath functions are
based on radians. In order to convert dx from degrees to
radians
* you can: (dx * PI)/ 180 In order to convert dx from radians to degrees * you can: (dx * 180)/ PI where PI = 3.14159 1) Translation: ============ a) Global: if entityMat is the matrix of the model, entityMat.m03 += 1 will move the object closer to the right edge of the monitor entityMat.m13 += 1 will move the object closer to the top edge of the monitor entityMat.m23 += 1 will move the object closer to our eye b) Local: if delta is a temporary matrix, delta.m03 += 1 will move the object 1 unit in it's x-positive direction delta.m13 += 1 will move the object 1 unit in it's y-positive direction delta.m23 += 1 will move the object 1 unit in it's z-positive direction
(Note that the above calls were global transformation for delta)
now,
we should multiply delta by entityMat in order to cause entityMat to transform
locally
entityMat.mul(delta); 2)
Rotation:
========= * Note that when calling rotX, rotY, and rotZ the fields of the matrix will be set to * thoss of an identity matrix. After calling delta.rotX(.f), the delta will seem to * be set to identity and then rotated 0.1 radians. * * It is very important that you set a matrix to identity when needed. Not paying attention to * to this fact can introduce very tough BUGS! Note: the
order by which you multiply two matrices determines whether the rotation is
local or global
a)
Global:
delta.rotY(.5); delta.mul(entityMat); entityMat.set(delta);
Note: the reason why I did not say entityMat.rotY(.5) is because, the
rotY()
method
rotates the matrix BUT resets any other current information in the matrix. for example, if you also had rotation around X, it would be reset when you call rotY() b) Local: delta.rotY(.5); entityMat.mul(delta); 3)
Scale:
====== a) Global: the following block causes the entityMat to Scale up Globally with respect to Z-axis entityMat.m20 *= 1.25; entityMat.m21 *= 1.25; entityMat.m22 *= 1.25; the
following block causes the entityMat to Scale Down Globally with respect to
X-axis
entityMat.m00 *= 0.8; entityMat.m01 *= 0.8; entityMat.m02 *= 0.8; b) Local: the following block causes the entityMat to Scale up Locally with respect to Z-axis: entityMat.m02 *= 1.25; entityMat.m12 *= 1.25; entityMat.m22 *= 1.25; the
following block causes the entityMat to Scale down Locally with respect to
Y-axis:
entityMat.m01 *= 0.8; entityMat.m11 *= 0.8; entityMat.m21 *= 0.8; ******************************************************************************************************** ********************************************************************************************************
----- Original Message -----
|
- [JAVA3D] Game Direction silvano
- Re: [JAVA3D] Game Direction Paraskevas Orfanides
- Syrus Mesdaghi
