Results 1 to 4 of 4

Thread: Rotate camera around point-of-interest in opengl

  1. #1
    Newbie Newbie
    Join Date
    Oct 2011
    Posts
    2

    Rotate camera around point-of-interest in opengl

    I want to rotate my "camera" around a point of interest. Currently the camera only rotates around the origin.

    The standard way:

    Code :
        translate(-P)
        rotate
        translate(P)

    Unfortunately, this doesn't work. My application uses a translation vector (QVector3D) as well as a quaternion (QQuaternion) to save translation and rotation of the camera.


    Currently, it is done like this, which always rotates around the origin:


    Code :
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(translation.x(),translation.y(), translation.z());
        multMatrix(accumulatedQuaternionRotation);


    where mulMatrix uses the Quaternion to build a 4x4 matrix which is passed to glMultMatrixf();


    Using something like this:


    Code :
        glTranslatef(-translation.x(),-translation.y(), -translation.z());
        multMatrix(accumulatedQuaternionRotation);
        glTranslatef(translation.x(),translation.y(), translation.z());


    results in very weird controls which I'm unable to describe further. In my application translation.z() means: move the camera forward. Changing x() and y() issues a pan like operation.

    Help is greatly appreciated. :)

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    You have to think about what is happening to you lookat point as well as the camera. Your lookat will also rotate

  3. #3
    Newbie Newbie
    Join Date
    Oct 2011
    Posts
    2
    How do I prevent the lookAt from also rotating? I really don't even know where to start to look where my problem is.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    You don't want to prevent it you want to ensure it happens - I would try calculating a new eye and lookat target for your rotation and call gluLookAt

Similar Threads

  1. Replies: 1
    Last Post: 07-12-2013, 03:41 PM
  2. rotate around arbitrary point
    By thinhare in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-03-2010, 03:24 PM
  3. Rotate around a certain point!!!!
    By angeldarkholme in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 10-14-2005, 05:51 PM
  4. Rotate around a certain point!!!!
    By angeldarkholme in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-14-2005, 01:47 PM
  5. Gimbal lock while orbiting camera around interest point
    By remedios79 in forum OpenGL: General
    Replies: 7
    Last Post: 12-01-2004, 08:49 PM

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