Thread: how to rotate a scene in the correct way ?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    111

    how to rotate a scene in the correct way ?

    I hope i don't ask some FAQ qustion .

    I would like to rotate an object (after changing it place ).

    when i move the object (qube) and then rotate it it will rotare with a big circle around the orignal center point (0,0,0) instead of a x,yz around what it was created .

    i tried to play with glLookAt() in the next way [NEWB alert] :
    i add this code as a case statment that a key will call it :

    glMatrixMode(GL_MODELVIEW) ;
    glLoadIdentity() ;
    fTranslatey -= 0.1;
    gluLookAt(fTranslatex, fTranslatey, fTranslatez,0,0,0,0,1,1);
    glutPostRedisplay(); break;


    I guess it is reall
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    You need to translate before you rotate, ie. swap the blue with the red:
    Code:
    void disp()
    {
     glClear(GL_COLOR_BUFFER_BIT);
     glLoadIdentity();
     
     glRotatef(angle,1.0,1.0,0.0);
     glTranslatef(fTranslatex, fTranslatey, fTranslatez); 
    
     glScalef(fScale, fScale, fScale);
      drawcube();
    
    glutSwapBuffers();
    
    }

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    111
    i asked why the defrance
    and was unswared else where :

    if you call glRotate, then glTranslate, the result will be a matrix that effectively translates the object first, then rotates the translated object around the origin.

    Thank you
    Last edited by jabka; 12-18-2007 at 02:05 PM.
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 08:30 PM
  2. Is this correct : passing strings?
    By socket in forum C Programming
    Replies: 15
    Last Post: 11-25-2008, 02:03 PM
  3. correct malloc use
    By s_siouris in forum C Programming
    Replies: 10
    Last Post: 05-28-2008, 10:49 PM
  4. scene graph rendering techniques
    By ichijoji in forum Game Programming
    Replies: 7
    Last Post: 03-19-2006, 12:17 AM
  5. Scene Graph - Compiling
    By Shamino in forum Game Programming
    Replies: 17
    Last Post: 03-05-2006, 11:57 AM