Results 1 to 2 of 2

Thread: cannot understand the rotation

  1. #1
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    1

    Unhappy cannot understand the rotation

    Hi

    I try to write something to show rotation, but I cannot understand why the whole rotating process is repeated again and again when I run the project.

    I run it on Windows using codeblocks. Can anyone please help me?

    Here is my code:
    Code :
    #include <GL/glut.h>
    #include <stdlib.h>
    #include <Windows.h>
    void init (void)
    {
        glClearColor (1.0, 1.0, 1.0, 0.0);
        glMatrixMode (GL_PROJECTION);
        gluOrtho2D (-5.0, 5.0, -5.0, 5.0);
        glMatrixMode (GL_MODELVIEW);
    }
     
    void drawSquare(void)
    {
        glBegin (GL_POLYGON);
        glVertex2f (-1.0f,-1.0f);
        glVertex2f (1.0f,-1.0f);
        glVertex2f (1.0f, 1.0f);
    //    glVertex2f (0.0f, 1.2f);
        glVertex2f (-1.0f,1.0f);
        glEnd ( );
    }
     
    void rotate()
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glLoadIdentity();
        glColor3f(1.0, 0.0, 0.0);
        drawSquare();
        glFlush();
        Sleep(1000);
        glClear(GL_COLOR_BUFFER_BIT);
        for(int i = 0; i < 30; i++)
        {
            glTranslatef(2.0 / 30, 3.0 / 30, 0.0);
            glRotatef(1, 0.0, 0.0, 1.0);
            glColor3f(0.0, 1.0, 0.0);
            drawSquare();
            glFlush();
            Sleep(100);
            glClear(GL_COLOR_BUFFER_BIT);
        }
    }
     
    int main (int argc, char** argv)
    {
        glutInit (&argc, argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
        glutInitWindowPosition (100, 100);
        glutInitWindowSize (600, 600);
        glutCreateWindow ("Geometrical Transfromation");
        init();
        glutDisplayFunc (rotate);
        glutMainLoop ( );
    }

  2. #2
    Senior Member Frequent Contributor ehsan2004's Avatar
    Join Date
    Jun 2004
    Location
    Iran
    Posts
    645
    The method you have used is not suitable to show rotation. Use glut to set a timer and use double buffers. Then draw the quad including its translation and rotation once per frame.

    Beside this point, you are not using glLoadIdentity() before glTranslate()/glRotate() command. Since OpenGL glare in object space, your 3D geometry is translated and rotated in each loop 'reiterative to its current translation/rotation status'.
    Instead, use something like this:

    void Render()
    {
    //Activate identity matrix
    //load identity matrix
    //translate
    //use an incremental variable for glRotate
    //Rotate the square using incremental variable
    //draw the square
    }

Similar Threads

  1. I don't understand how to use Buffers
    By aligator in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-08-2015, 12:23 PM
  2. I can't understand what is wrong exactly...
    By BCKong in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-12-2009, 06:25 AM
  3. I am new in GL. I can not understand MatrixMode
    By ebekir in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-11-2008, 02:27 AM
  4. Could somebody help me understand...
    By raybones in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-28-2004, 10:26 PM
  5. Please help me understand CVAs
    By WhatEver in forum OpenGL: User Software
    Replies: 0
    Last Post: 02-15-2001, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean