Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Created January 8, 2009 17:29
Show Gist options
  • Save AlexJWayne/44809 to your computer and use it in GitHub Desktop.
Save AlexJWayne/44809 to your computer and use it in GitHub Desktop.
// cameraPos and angle are instance vars, obviously
- (void)renderCamera {
GLfloat cameraHeightMax = 40.0;
GLfloat cameraHeightMin = 8.0;
if (cameraPos.z > cameraHeightMax) cameraPos.z = cameraHeightMax;
if (cameraPos.z < cameraHeightMin) cameraPos.z = cameraHeightMin;
// Setup camera
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Create perspective frustrum
glFrustumf(-1.5, 1.5, -1.0, 1.0, 4.0, 200.0);
// Translate it behind a bit
glTranslatef(0.0, -1.5, 0.0);
// Move camera above play plane
glTranslatef(0.0, 0.0, -cameraPos.z);
// Rotate the view to slightly down, staying pointed at origin
glRotatef(-20.0, 1.0, 0.0, 0.0);
// Spin camera to match angle of viewport
glRotatef(-angle, 0.0, 0.0, 1.0);
// Position camera
glTranslatef(-cameraPos.x, -cameraPos.y, 0.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment