Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NEWBIE: Third Person Perspective



I'm trying to teach myself OpenGL and MacOSX/Cocoa simultaneously and am enjoying the beauty of the NeXT API. However, I'm running into a rather frustrating issue with understanding OpenGL camera angles (specifically third person perspective for a basic flight sim). I'm trying to setup a camera that will look at the back of the ship and follow it around as it moves (pretty simple).

I'm using code snippets from the OpenGL "red book" (Third edition) and have come up with the following:

float trailingDist = -10.0;

glLoadIdentity();
// Position the camera behind the aircraft
glTranslatef(pos.x, pos.y, -pos.z + trailingDist);

glRotatef(-rot.z, 0.0, 0.0, 1.0);
glRotatef(-rot.x, 1.0, 0.0, 0.0);
glRotatef(rot.y, 0.0, 0.0, 1.0);

// Now position the aircraft
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
glRotatef(rot.z, 0.0, 0.0, 1.0);
glRotatef(rot.x, 1.0, 0.0, 0.0);
glRotatef(-rot.y, 0.0, 0.0, 1.0);

drawAircraft();
glPopMatrix();

drawTheRestOfTheEnvironment();

It works fine if I increment/decrement only one of the rot values, but if I increment two or more simultaneously, I end up looking at the side of the ship, not the back. Or, I start orbiting around the ship.

I've searched the net for every resource I could find, but nothing seemed to help. Could someone give me some pointers (no pun intended) on how to setup a proper 3d person perspective?

Thanks,
Geoff Grosenbach
email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.