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: Yet another camera implementation question

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    3

    Yet another camera implementation question

    Hello, I've been trying for a long time to find good resources on creating a camera that rotates and translates according to the current view, but to no avail. And gluLookAt seems to be really slow (not to mention the difficult calculating the up vector); I'd prefer to do this in pure OpenGL.

    What should I be using? glTranslatef doesn't seem to care whether I rotated first (and I've tried translating back, etc.), and it looks like it'd be really difficult to calculate exactly what axes to rotate the camera around to do what I want. I've messed around a bit with push/popmatrix. I'm sorry; I just haven't found anything, and I've put off starting a 3D game for months now because I just can't make this first step.

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Yet another camera implementation question

    gluLookAt can't be slow; or roll your own version - it's just normalization and cross product.

    Extract the 3x3 rotational matrix from the modelview, extract the translation from modelview. (below their values are used in mvrot, mvtrans)

    Code :
    vec3 strafeDir = vec3(-0.3,0,0); // if you want to go right 0.3 units
    mat3 rotateDir = ...// calculate how you want to rotate, or identity if there's no rotation to be applied
     
    vec3 newTranslation = mvtrans + mvrot * strafeDir;
    mat3 newRotation = mvrot * rotateDir;
    Merge the new results into a 4x4 matrix, upload with glLoadMatrix.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    3

    Re: Yet another camera implementation question

    I haven't used vec3 or mat3 before, but I'll get back when I try that!

Posting Permissions

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