Advertisement
Guest User

Untitled

a guest
May 9th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. void beginPerspectiveProjection(){
  2.     glMatrixMode(GL_PROJECTION);
  3.     glPushMatrix();
  4.     glMatrixMode(GL_MODELVIEW);
  5.     glPushMatrix();
  6.    
  7.     double fov, near, far;
  8.     double headX, headY, headZ;
  9.     float aspectRatio;
  10.    
  11.     near = 0.5f; far = 1000.0f;  aspectRatio = ofGetWidth()/ofGetHeight();
  12.     fov = tan(DEG_TO_RAD * 30/2); //tan accepts angle in radians. tan of the half of the fov angle
  13.     fov = 0.5;
  14.    
  15.     double msX = (double)ofGetMouseX();
  16.     double msY = (double)ofGetMouseY();
  17.     double scrWidth = (double)ofGetWidth();
  18.     double scrHeight = (double)ofGetHeight();
  19.    
  20.     headX = (msX / scrWidth) - 0.5;
  21.     headY = ((scrHeight - msY) / scrHeight) - 0.5;
  22.     headZ = -2.0;
  23.    
  24.     glMatrixMode(GL_PROJECTION);
  25.         glLoadIdentity();
  26.         glFrustum( near * (-fov * aspectRatio + headX),
  27.                    near * (fov * aspectRatio + headX),
  28.                    near * (-fov + headY),
  29.                    near * (fov + headY),
  30.                    near,
  31.                    far
  32.                   );
  33.     glMatrixMode(GL_MODELVIEW);
  34.     glLoadIdentity();
  35.     gluLookAt(headX * headZ, headY * headZ, 0, headX * headZ, headY * headZ, -1, 0, 1, 0);
  36.     glTranslatef(0.0, 0.0, headZ);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement