socal swimmer Posted November 12, 2007 Share Posted November 12, 2007 .... I hate radians. I hate degrees too. why cant we just use one system? Do you know how much trouble it causes me that there are 2 systems? AAGGHHHHHHH..... The sin() and cos() functions needed radians, i gave them degrees. ie undefined behavior. so nevermind on this whole post. ok so pretty much i have been staring at this forever and i dont know what is wrong. I am using objective-C (with some C++, but not here) to write openGL apps. Currently, I have a wine glass type of object that can rotate around the Y axis (the global one, but the object is at the origin) when you press < or >. Then, y and h rotate it around the X axis (the global X, assuming the the oject is at the origin. I'm using XCode 2.4.1 /* important variables: camz is how far away the object is drawn from the camera rotx is its orientation around the y axis (its rotation on the horizontal plane) rotz is its orientation around the X. */ // this resets everything, then rotates and translates to the orientation/position i want it drawn at - (void) loadIdentity { glLoadIdentity(); glTranslatef(-camx, -camy, -camz); glRotatef(rotx, 0, 1, 0); glRotatef(rotz, cos(rotx), 0, sin(rotx)); } /* * Called when the system thinks we need to draw. */ - (void) drawRect:(NSRect)rect { // Clear the screen and depth buffer glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); [self loadIdentity]; glBegin(GL_TRIANGLES); glCallList(tube); //tube is the oject i am drawing glEnd(); [ [ self openGLContext ] flushBuffer ]; } /* ***************************** these next functions handle key presses, ie when i hit a key, these get called accordingly ******************************** */ //rotates around Y (up-down) axis - (void) moveItLeft:(BOOL)left { if (left) { rotx += 5; } else { rotx -= 5; } } //moves the object closer and farther away - (void) moveItUp:(BOOL)up { if (up) { camz -= .2; } else { camz += .2; } } //this actually rotates around the X axis, but i was too lazy to make it right - (void) rotateAroundZAxis:(BOOL)up { if (up) { rotz += 5; } else { rotz -= 5; } } so here is the problem. It starts up and displays the object fine. When i spin it horizontally, its fine. 5 degree jumps, all good. when i then rotate it around the X axis, its all good. However, when i try to rotate it around the Y axis after rotating it around the X, it rotates to random orientations in huge jumps. if that made any sense, i would gladly appreciate your help. Link to comment Share on other sites More sharing options...
Recommended Posts