-
Open GL rotating problem
Hello
I am doing something in Open GL and here is my problem:
I've got polygon rotating around z-axis and I want it to stop rotating at 60 degrees and then return it back to stating point.
How could i do this:
here is the code:
float angle= 1.0;
.......
glPushMatrix();
glTranslatef(-50,0.0,0.0);
glRotatef(-angle,0.0,0.0,0.1);
glBegin(GL_QUADS);
glColor3f(0,0,0); glVertex3f(0.0f, 10.0f, -10.0f);
glColor3f(0,0,0); glVertex3f(0.0f, 10.0f, 10.0f);
glColor3f(0,0,0); glVertex3f( 50.0f, 10.0f, 10.0f);
glColor3f(0,0,0); glVertex3f( 50.0f, 10.0f, -10.0f); glEnd();
glPopMatrix();
-
Don't you just need to alter the angle variable?
I mean, each time you Rotate the matrix, alter the variable to increase the angle of rotation for next time. Before you actually do it, test what the angle is - if its too big, change the value.
HD
-
OK, but what shell I put in the code, another angle variable or?..
to rotate it back?
-
Well what do you want?
For example, if you want the polygon to rotate to 60 degrees then rotate to -60 degrees etc - like its wobbling, then you can:
Code:
#define MAXANGLE 8 // Some max angle
#define MINANGLE -8 // Some min angle
float angle= 0.0;
int direction = 1; // Direction of rotation
int increment = 0.1; // Set to some value of increment
.......
glPushMatrix();
glTranslatef(-50,0.0,0.0);
if(angle > MAXANGLE)
direction = -1; // Set to reverse direction
else if(angle < MINANGLE)
direction = 1;
angle += (direction*increment);
glRotatef(-angle,0.0,0.0,0.1);
glBegin(GL_QUADS);
glColor3f(0,0,0); glVertex3f(0.0f, 10.0f, -10.0f);
glColor3f(0,0,0); glVertex3f(0.0f, 10.0f, 10.0f);
glColor3f(0,0,0); glVertex3f( 50.0f, 10.0f, 10.0f);
glColor3f(0,0,0); glVertex3f( 50.0f, 10.0f, -10.0f);
glEnd();
glPopMatrix();
Thats probably about right - the values are probably screwed up - its been quite a while since I did OpenGL.
HD
-
Thanks, this works perfectly...
the only thing is how to set the time so the rotation will occure back after for example 15 seconds...
-
You'll just have to test it. As I say, I haven't done OpenGL for a couple of years - and no graphics programming since - so I'm a bit rusty.
Trial and error, thats the key. Unless you have information on frame rates etc. in which case you 'could' work it out :D
HD
-
What do you mean trial and error... is it trial the time sequence which have to be defined and used to set when rotation will go back to....:confused: :D
NSR