Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Calculate the Camera Transform

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    24

    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[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;
    }

  2. #2
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    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.
    Last edited by Brokenmind; 03-26-2014 at 07:27 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    24
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •