Results 1 to 5 of 5

Thread: Focusing the "camera" on an object ??!

  1. #1
    Member Contributor
    Join Date
    May 2001
    Location
    Hamburg, Germany
    Posts
    63

    Focusing the "camera" on an object ??!

    Hi!
    I have a working camera, I can adjust with the mouse to look around.
    But now, I want the camera to be focused on one object all the time, no matter where the camera is.
    I use glRotatef on my whole scene to make a "camera"...
    Code :
    glRotatef(cAngle_x,1.0f,0.0f,0.0f);
    glRotatef(cAngle_z,0.0f,0.0f,1.0f);
    But how do I calculate cAngle_x and cAngle_z for my focused camera, if I have the postion of my Camera (x,y,z) and my Object(x,y,z)??
    Anybody an idea???
    Thanks in advance!

  2. #2
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    5

    Re: Focusing the "camera" on an object ??!

    How about something like this?

    o_c(x) means distance between camera and object on the x-axis e.g. o_c (y)...

    tan (angle_z) = o_c (x)/o_c(y)

    tan (angle_x) = o_c(z)/o_c (xy)

    o_c(xy) =
    squareroot of (o_c(x)*o_c(x) + o_c(y)*o_c(y))

    Maybe it works...but I'm not sure

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: Focusing the "camera" on an object ??!

    Replace those glRotatef calls with a single call to gluLookAt. That way, you can simply pass in the x,y,z coordinates of the object you want to track.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Focusing the "camera" on an object ??!

    Do you want one side of this object to always face the camera?
    Or do you want the camera to rotate around the object as if you where walking around the object looking at it?




    Originally posted by TheBlob:
    Hi!
    I have a working camera, I can adjust with the mouse to look around.
    But now, I want the camera to be focused on one object all the time, no matter where the camera is.
    I use glRotatef on my whole scene to make a "camera"...
    Code :
    glRotatef(cAngle_x,1.0f,0.0f,0.0f);
    glRotatef(cAngle_z,0.0f,0.0f,1.0f);
    But how do I calculate cAngle_x and cAngle_z for my focused camera, if I have the postion of my Camera (x,y,z) and my Object(x,y,z)??
    Anybody an idea???
    Thanks in advance!

  5. #5
    Member Contributor
    Join Date
    Jul 2001
    Location
    Sherbrooke
    Posts
    95

    Re: Focusing the "camera" on an object ??!

    I agree with Korval
    Simply use the x,y,z of the object you want to focus in the centerX, centerY, centerZ parameters of gluLookAt.
    it works just fine.

    -----------------------------------------
    Evil-Dog
    *Let's have a funny day*
    Let's have a funny day

Similar Threads

  1. Camera following object
    By Sczerzuja in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-19-2014, 06:00 AM
  2. Need Help in focusing windows..
    By Sasi_Opengl in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-18-2013, 09:14 AM
  3. How to put a camera inside an object?
    By elithin in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-05-2011, 11:34 AM
  4. Vista && OpenGL Focusing Window
    By Tontonq in forum OpenGL: Windows
    Replies: 2
    Last Post: 06-10-2007, 11:18 AM
  5. Is my object looking at the camera?
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-25-2001, 11:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean