Looking at a Specified Point

This is a discussion on Looking at a Specified Point within the Game Programming forums, part of the General Programming Boards category; In my little game i want to be able to look at a specific point in my 3d scene. If ...

  1. #1
    Registered User gpr1me's Avatar
    Join Date
    Mar 2006
    Posts
    14

    Looking at a Specified Point

    In my little game i want to be able to look at a specific point in my 3d scene. If my camera is at (0, 0, 0) and i want to be able to look at (10, 0, 20) how would i do this.

    I understand that i need to change the gluLookAt() function. Which basically sets the camera's (eye, center, up). The Eye is the location of the camera, center is the direction the camera is pointing and up is defining what up is. So would i have to do something like this?

    gluLookAt(0.0, 0.0, 0.0, 10.0, 0.0, 20.0, 0.0, 1.0, 0.0);

    This will Make
    eye.x = 0.0, eye.y = 0.0, eye.z = 0.0
    center.x = 10.0, center.y = 0.0, center.z = 20.0
    up.x = 0.0, up.y = 1.0, up.z = 0.0

    That means the camera will be at the origin and looking at the point (10.0, 0.0, 20.0). Am i correct?

    So if i want to look at a specific point all i would have to do is change the center to that point?

  2. #2

    Join Date
    May 2005
    Posts
    1,041
    The eye point can only be a single unit away from the camera.


    Code:
    Vector3 lookat = Vector3(10,0,20) - Camera.Position; //in this case (0,0,0)
    
    lookat.normalize(); 
    
    Vector3 eye = Camera.Position + lookat;
    
    
    
    void Vector3::normalize()
    {
    float len = sqrt(x^2 + y^2 + z^2);
    
    if(len > .00001f)
    {
    len = 1.0f / len;
    x *= len;
    y *= len;
    z *= len;
    }
    
    }
    I'm not immature, I'm refined in the opposite direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help realy needed
    By ZohebN in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2008, 09:37 AM
  2. Getting a floating point exception
    By SnertyStan in forum C Programming
    Replies: 13
    Last Post: 03-25-2008, 11:00 AM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  4. floating point binary program, need help
    By ph34r me in forum C Programming
    Replies: 4
    Last Post: 11-10-2004, 06:10 AM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 03:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21