|
-
Dec 19th, 2002, 05:42 AM
#1
Thread Starter
New Member
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();
-
Dec 19th, 2002, 06:16 AM
#2
Addicted Member
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
-
Dec 19th, 2002, 06:24 AM
#3
Thread Starter
New Member
OK, but what shell I put in the code, another angle variable or?..
to rotate it back?
-
Dec 19th, 2002, 07:59 AM
#4
Addicted Member
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
-
Dec 20th, 2002, 03:20 AM
#5
Thread Starter
New Member
Thanks, this works perfectly...
the only thing is how to set the time so the rotation will occure back after for example 15 seconds...
-
Dec 20th, 2002, 03:47 AM
#6
Addicted Member
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
HD
-
Dec 20th, 2002, 03:55 AM
#7
Thread Starter
New Member
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....
NSR
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|