Game Development Reference
In-Depth Information
12.2.1.3 Combining Both Parts
Finally, augmenting A toa4 4 matrix and combining the translation
part with the rotation part yields the view transformation matrix V :
1
0
0
0
r
u
d
0
r
u
d
0
x
x
x
x
x
x
0
1
0
0
r
u
d
0
r
u
d
0
y
y
y
y
y
y
TA
V
0
0
1
0
r
u
d
0
r
u
d
0
z
z
z
z
z
z
p
p
p
1
0
0
0
1
p
r
p
u
p
d
1
x
y
z
We build this matrix in the Camera::getViewMatrix method:
void Camera::getViewMatrix(D3DXMATRIX* V)
{
// Keep camera's axes orthogonal to each other:
D3DXVec3Normalize(&_look, &_look);
D3DXVec3Cross(&_up, &_look, &_right);
D3DXVec3Normalize(&_up, &_up);
D3DXVec3Cross(&_right, &_up, &_look);
D3DXVec3Normalize(&_right, &_right);
// Build the view matrix:
float x = -D3DXVec3Dot(&_right, &_pos);
float y = -D3DXVec3Dot(&_up, &_pos);
float z = -D3DXVec3Dot(&_look, &_pos);
(*V)(0, 0) = _right.x;
(*V)(0, 1) = _up.x;
(*V)(0, 2) = _look.x;
(*V)(0, 3) = 0.0f;
(*V)(1, 0) = _right.y;
(*V)(1, 1) = _up.y;
(*V)(1, 2) = _look.y;
(*V)(1, 3) = 0.0f;
(*V)(2, 0) = _right.z;
(*V)(2, 1) = _up.z;
(*V)(2, 2) = _look.z;
(*V)(2, 3) = 0.0f;
(*V)(3, 0) = x;
(*V)(3, 1) = y;
(*V)(3, 2) = z;
(*V)(3, 3) = 1.0f;
}
You may wonder what the first few lines of the method are for. After
several rotations, the camera's axes can become non-orthogonal to
each other due to floating-point errors. Therefore, every time this func-
tion is called, we recompute the up and right vectors with respect to
Team-Fly ®
Search WWH ::




Custom Search