Hi,
I wrote this func that initialize the camera.
I am trying to set a camera pos.It works for all cases except when:
My target point is (0,0,0), pos(0,500,0)
I have a bug when the target is set to (0,0,0)
so I get a zero matrix.
what can I do to change it?
void Matrix4f::InitCameraTransform(const Vector3f& Target, const Vector3f& Up)
{
Vector3f N = Target;
N.Normalize();
Vector3f U = Up;
U.Normalize();
U = U.Cross(N);
Vector3f V = N.Cross(U);
m[0][0] = U.x; m[0][1] = U.y; m[0][2] = U.z; m[0][3] = 0.0f;
m[1][0] = V.x; m[1][1] = V.y; m[1][2] = V.z; m[1][3] = 0.0f;
m[2][0] = N.x; m[2][1] = N.y; m[2][2] = N.z; m[2][3] = 0.0f;
m[3][0] = 0.0f; m[3][1] = 0.0f; m[3][2] = 0.0f; m[3][3] = 1.0f;
}
You have one mistake there: The matrix does not take the target point, but the target direction. So your target vector need actually be (0, -500, 0)^T.
If you try to look with the front direction of (0, 0, 0)^T, there’s no wonder you don’t see a thing
(As a consequence, all other vectors in your matrix will be (0, 0, 0)^T as well.)
Edit: Maybe you confused the function with gluLookAt() that actually takes the point you look at and the camera point, but internally computes the distance between them.
so what I have to change in this func that it will work for the case that the target is (0,0,0) . I dont want the model to be only at this point.
and when I want to look from Z negative or y positive of the camera I will see the model
what should I change in this func?
Thanks a lot