Game Development Reference
In-Depth Information
'
about that axis will make the teapot appear as if it is sitting on a potter
s wheel. How
do you calculate the angle? Go back to your unit circle to figure it out. The angle you
want is 45 degrees, or
/4. We also know that the angle should be negative. Here
'
s
π
why: If you were looking along the Y-axis, you
'
d be underneath the teapot looking
straight up. The teapot
s spout needs to twist clockwise to achieve the desired result,
so the angle is negative.
A rotation matrix for the Y-axis looks like this:
'
2
4
3
5
cos ð Þ 0 sin ð Þ 0
0100
sin ð Þ 0 cos ð Þ 0
0001
Here
'
s the code to create this matrix in DirectX:
float angle = -D3DX_PI / 4.0f;
D3DXMATRIX rotateY;
D3DXMatrixRotationY(&rotateY, angle);
Let
'
s transform a vector with this matrix and see what happens. Since the teapot
'
s
spout is pointing down the X-axis, let
'
s transform (x=1, y=0, z=0):
D3DXVECTOR4 original(1, 0, 0, 1);
D3DXVECTOR4 result(0,0,0,0);
D3DXVec4Transform(&result, &original, &rotateY);
Here
'
s the result:
result
{...}
D3DXVECTOR4
x
0.70710677
float
y
0.00000000
float
z
0.70710677
float
w
1.0000000
float
Excellent, that
s exactly what we want. The new vector is sitting on the X-Z plane, and
both coordinates are in the positive. If we take that same transform, apply it to every
vertex of the teapot, and then redraw it, we
'
ll get the picture shown in Figure 14.8.
This matrix will create a rotation about the X-axis:
'
2
4
3
5
1
0
0
0
0
cos ð Þ
sin ð Þ
0
0 sin ð Þ
cos ð Þ 0
0
0
0
1
 
Search WWH ::




Custom Search