Results 1 to 7 of 7

Thread: Open GL rotating problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    UK
    Posts
    5

    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();

  2. #2
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    UK
    Posts
    5
    OK, but what shell I put in the code, another angle variable or?..
    to rotate it back?

  4. #4
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    UK
    Posts
    5
    Thanks, this works perfectly...
    the only thing is how to set the time so the rotation will occure back after for example 15 seconds...

  6. #6
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    UK
    Posts
    5
    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
  •  



Click Here to Expand Forum to Full Width