I'm working on a radiosity processor in DirectX 9. The process requires that the camera be placed at the center of a mesh face and a 'screenshot' be taken facing 5 different directions...forward...up...down...left...right...
...The problem is that when the mesh face is facing up( look vector: 0, 1, 0 )...a view matrix cannot be determined using standard trigonometry functions:
Matrix4 LookAt( Vector3 eye, Vector3 target, Vector3 up )
{
// The "look-at" vector.
Vector3 zaxis = normal(target - eye);
// The "right" vector.
Vector3 xaxis = normal(cross(up, zaxis));
// The "up" vector.
Vector3 yaxis = cross(zaxis, xaxis);
// Create a 4x4 orientation matrix from the right, up, and at vectors
Matrix4 orientation =
{
xaxis.x, yaxis.x, zaxis.x, 0,
xaxis.y, yaxis.y, zaxis.y, 0,
xaxis.z, yaxis.z, zaxis.z, 0,
0, 0, 0, 1
};
// Create a 4x4 translation matrix by negating the eye position.
Matrix4 translation =
{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
-eye.x, -eye.y, -eye.z, 1
};
// Combine the orientation and translation to compute the view matrix
return ( translation * orientation );
}
The above function comes from http://3dgep.com/?p=1700...
...Is there a mathematical approach to this problem?