# Calculate the Camera Transform

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 = U.x;   m = U.y;   m = U.z;   m = 0.0f;
m = V.x;   m = V.y;   m = V.z;   m = 0.0f;
m = N.x;   m = N.y;   m = N.z;   m = 0.0f;
m = 0.0f;  m = 0.0f;  m = 0.0f;  m = 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