Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void beginPerspectiveProjection(){
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- double fov, near, far;
- double headX, headY, headZ;
- float aspectRatio;
- near = 0.5f; far = 1000.0f; aspectRatio = ofGetWidth()/ofGetHeight();
- fov = tan(DEG_TO_RAD * 30/2); //tan accepts angle in radians. tan of the half of the fov angle
- fov = 0.5;
- double msX = (double)ofGetMouseX();
- double msY = (double)ofGetMouseY();
- double scrWidth = (double)ofGetWidth();
- double scrHeight = (double)ofGetHeight();
- headX = (msX / scrWidth) - 0.5;
- headY = ((scrHeight - msY) / scrHeight) - 0.5;
- headZ = -2.0;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum( near * (-fov * aspectRatio + headX),
- near * (fov * aspectRatio + headX),
- near * (-fov + headY),
- near * (fov + headY),
- near,
- far
- );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(headX * headZ, headY * headZ, 0, headX * headZ, headY * headZ, -1, 0, 1, 0);
- glTranslatef(0.0, 0.0, headZ);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement