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 2 of 2

Thread: stuck with 360 camera loop

  1. #1
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98

    stuck with 360 camera loop

    hi all,

    sorry , but i just got stuck with a free 360 camera movement.
    right now i can move left / right at full 360 .. but the up and down holds at -90 / + 90 degree.
    here is what i do right now:

    Code :
          this.Control.yrotrad = (this.Control.yrot / 180.0 * 3.141592654 );
          this.Control.xrotrad = (this.Control.xrot / 180.0 * 3.141592654 );
     
          // up vector
          this.up[0]    = 0.0;
          this.up[1]    = 1.0;
          this.up[2]    = 0.0;      
     
          // eye
          this.eye[0]    = this.Control.xpos;
          this.eye[1]    = this.Control.ypos;
          this.eye[2]    = this.Control.zpos ;  
     
          // center point
          this.center[0] =  this.Control.xpos+(Math.sin(this.Control.yrotrad)*1.0);
          this.center[1] =  (this.Control.ypos-(Math.sin(this.Control.xrotrad)*1.0));
          this.center[2] =  this.Control.zpos-(Math.cos(this.Control.yrotrad)*1.0) ;    
     
          this.myWGL.CameraView     = M4x4.makeLookAt ( this.eye,  this.center, this.up );

    i guess its all about the up vector .. but i just canīt figure out what to do ...
    can someone complete the code ? or am i going the wrong way ?

    thanx
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    495
    Quote Originally Posted by uwi2k2 View Post
    i guess its all about the up vector .. but i just canīt figure out what to do ...
    can someone complete the code ? or am i going the wrong way ?
    If you want direct control over the view direction, using a "look-at" function is probably the wrong way to go about it. It's simpler to concatenate a translation, a rotation about the vertical axis and a rotation about the left-right axis. Also, the look-at approach has undefined behaviour if you're looking directly up or down.

    A pitch angle of more than +/- 90 degrees will make the view upside down, which is impossible to achieve with a fixed up vector (it will combine a 180-degree rotation about the vertical axis with a pitch wrapped to the -90..+90 range).

    But if you're committed to the look-at approach, you can just invert the up vector when the pitch is outside of that range.

Posting Permissions

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