Note that there are some explanatory texts on larger screens.

plurals
  1. POrotating objects in opengl
    text
    copied!<p>I need to rotate the scene in an axis when I press a key. Here's how I implemented it</p> <pre><code> int rotateFlag; void rotateScene(int x){ if(x)//rotate 45 deg on x axis glRotatef(45,1,0,0); else // roatate 45 deg on y axis glRotatef(45,0,1,0); } //this is the function I call in glutDisplayFunc void drawScene(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //I'm looking at the origin (center of my scene) gluLookAt (x, y, z, 0,0,0, 0.0, 1.0, 0.0); rotateScene(rotateFlag); drawObjects();//draw Objects in Scene } </code></pre> <p>I assign value to rotateFlag when i press left key or up key. It rotates the scene once only since my function rotateScene <strong>always</strong> applies glRotatef on the original arrangement of the scene which I should avoid. Does somebody knows how I can save the rotated scene so I can apply my function on it(the rotated scene) and rotate the scene everytime I press an arrow key? I hope I made myself clear.</p> <p>I tried another solution by incrementing the angle in X and Y as I press the key</p> <pre><code> If keypress left angleX+=45; else if keypress up angleY+=45; </code></pre> <p>and adjust my rotateScene to </p> <pre><code> void rotateScene(){ glRotatef(angleX,1,0,0); glRotatef(angleY,0,1,0); } </code></pre> <p>Everything is going right when i performed rotation on individual axis, however, when I do Rotate on Y first then I perform rotate on X, the rotation of the scene is incorrect. Maybe this is because opengl executed rotate on X first before rotate on Y because of the ordering in the function call. I can't use this function properly since order in rotating the scene is important in my application.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload