The simple version of my project is rotating a sphere based on user input.
However my rotations get weird after multiple rotations in certain situations due to openGL's local coordinate system. What I really need is to ro开发者_运维百科tate based on a world/fixed coordinate system. Such that when I rotate the sphere once its rotation axes are not rotated as well. This issue is explained here http://www.opengl.org/resources/faq/technical/transformations.htm at 9.070.
I understand all that. However setting up what they suggest is a bit beyond my skill level. Does anyone have any experience with this? I tried using some code I found here http:// chaosengineer.com/?cat=19 but had no luck.
Here is the basic code I am using.
glPushMatrix();
//draw in middle of the screen
glTranslatef(ofGetWidth()/2,ofGetHeight()/2,0);
glRotatef(xRot,1,0,0);
glRotatef(zRot,0,0,1);
glTranslatef(-ofGetWidth()/2,-ofGetHeight()/2,0);
ofSetColor(255, 255, 255, 255);
squirrelModel.draw();
glPopMatrix();
YOu need to store object orientation as a matrix. Or as a set of vectors (local X, local Y, local Z).
To rotate object a bit, multiply orientation matrix by rotation matrix each time. Just make sure that all vectors of orientation matrix remain perpendicular to each other.
In this case, when rendering, instead of glRotate/glTranslate you'll need to use glMultMatrix.
Or use quaternions.
I understand it is not a complete answer, but (although I have written libraries and code for doing this), explaining this will take a lot of time.
Try downloading NVidia OpenGL sdk and see how they handled object rotation in their demos. Also search for 3d orientation with google. Some papers should explain how to store object orientation using matrices, and so on.
And check euclidianspace.com
精彩评论