Game Development Reference
In-Depth Information
D3DXVECTOR3 t(3,0,
2);
D3DXMATRIX transMatrix;
D3DXMatrixTranslation(&transMatrix, t.x,t.y,t.z);
Here
'
s how to do the same thing in DirectX:
D3DXVECTOR4 original(1, 1, 1, 1);
D3DXVECTOR4 result;
D3DXVec4Transform(&result, &original, &transMatrix);
The transform creates a new vector with values (4, 1,
1, 1). The DirectX function
D3DXVec4Transform multiplies the input vector with the transform matrix. The
result is a transformed vector.
2
3
1000
0100
0010
T:xT:yT:z 1
4
5
Make Sure You Match 4 × 4 Matrices with a 4D Vector
Did you notice my underhanded use of the D3DXVECTOR4 structure without
giving you a clue about its use? Matrix mathematics is very picky about the
dimensions of vectors and matrices that you multiply. It turns out that you
can only multiply matrices where the number of rows matches the number of
columns. This is why a 4 × 4 matrix must be multiplied with a four-dimensional
vector. Also, the last value of that 4D vector, W, should be set at 1.0, or you
'
ll
get odd results.
There are three kinds of rotation matrices, one for rotation about each axis. The most
critical thing you must get through your math-addled brain is this: Rotations always
happen around the origin. What in the heck does that mean, you ask? You ' ll
understand it better after you see an example. First, you need to get your bearings.
Figure 14.6 shows an image of a teapot sitting at the origin. The squares are one
unit across. We are looking at the origin from (X=6, Y=6, Z=6). The Y-axis points
up. The X-axis points off to the lower left, and the Z-axis points to the lower right.
If you look along the axis of rotation, an object will appear to rotate counterclockwise
if you rotate it in a positive angle. One way to remember this is by going back to the
unit circle in trig, as shown in Figure 14.7.
A special note to my high school geometry teacher, Mrs. Connally: You were right all
along
m torturing other people with it!
That means if you want to rotate the teapot so that the spout is pointing straight at
us, you
I did have use for the unit circle after all
.I
'
'
ll need to rotate it about the Y-axis. The Y-axis points up, so any rotation
 
Search WWH ::




Custom Search