Results 1 to 4 of 4

Thread: Trying to transform 2 quads

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    2

    Trying to transform 2 quads

    Hello, I'm trying to transform quads : first one should rotate, second one should move. I am completely stuck with this one: either both quads are rotating and moving at once, either transformation terminates.
    my code:
    Code :
    #include <OpenGL/gl.h>
    #include <OpenGL/glu.h>
    #include <GLUT/glut.h>
    int x;
    int y;
    void basicInt(void)
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glClearColor(0,0,0,0);
    	gluOrtho2D(0,950,0,600);  	
    }
     
    void drawQ(int x, int y) 
    {
    	glColor3f(1,1,0);
    	glBegin(GL_QUADS); 
    	glVertex2d( x, y ); 
    	glColor3f(1,1,1);
    	glVertex2d( x, y+75 ); 
    	glVertex2d( x+50, y+75 ); 
    	glVertex2d(x+50, y );
    	glEnd( ); 
    }
     
    void refresh(int count)
    {
       glutPostRedisplay();
     
    }
    void myView(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glMatrixMode(GL_MODELVIEW);  
     
    	glPushMatrix(); 
    	glRotated(1,0,0,1);
    	drawQ(400, 200);  //first quad should rotate
    	glPopMatrix();
     
     
    	glPushMatrix(); 
    	glTranslated(1,1,0);
    	drawQ(600, 200); //second quad should change its position
    	glPopMatrix();
     
    	glutSwapBuffers();
        glutTimerFunc(33,refresh,1);
    }
     
    int main(int argc,char* argv[])
    {
        glutInit(&amp;argc,argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
        glutInitWindowSize(950,600);
        glutInitWindowPosition(100,100);
        glutCreateWindow("Test");
        basicInt(); 
        glutDisplayFunc(myView);
        glutMainLoop();
     
    }
    I assume something is not right with glPushMatrix/glPopMatrix
    please help!

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678

    Re: Trying to transform 2 quads

    glRotated(1,0,0,1);
    drawQ(400, 200); //first quad should rotate
    That will cause it to rotate 1 degree. That's not very much. Try something you'll notice, like 30 degrees.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    2

    Re: Trying to transform 2 quads

    it does rotate and it is noticeable when I delete lines with glPopMatrix/glPushMatrix

  4. #4
    Member Contributor
    Join Date
    Jan 2010
    Posts
    82

    Re: Trying to transform 2 quads

    void drawQ(int x, int y)
    {
    glColor3f(1,1,0);
    glBegin(GL_QUADS);
    glVertex2d( x, y );
    glColor3f(1,1,1);
    glVertex2d( x, y+75 );
    glVertex2d( x+50, y+75 );
    glVertex2d(x+50, y );
    glEnd( );
    }
    This is the reason for your problem. It's like your rotating along the edge of the rectangle which causes it to rotate and move. The other doesn't have that problem since your just moving it. I would change it to this:

    void drawQ(int x, int y)
    {
    glColor3f(1,1,0);
    glBegin(GL_QUADS);
    glVertex2d( -(x/2), -(y/2) );
    glColor3f(1,1,1);
    glVertex2d( -(x/2), (y/2) );
    glVertex2d( (x/2), (y/2) );
    glVertex2d((x/2), -(y/2) );
    glEnd( );
    }
    That way in objects center is 0 instead of somewhere else. Your going to have to move your objects in this case as they will be kinda of screen since your quad center is at [0,0]

    glPushMatrix();
    glTranslated(400,200,0);
    glRotated(dt,0,0,1);
    drawQ(400, 200); //first quad should rotate
    glPopMatrix();


    glPushMatrix();
    glTranslated(650,500,0);
    drawQ(600, 200); //second quad should change its position
    glPopMatrix();
    this works out nicely.

Similar Threads

  1. quads
    By melax in forum COLLADA
    Replies: 4
    Last Post: 12-13-2004, 05:51 PM
  2. Texturing Quads
    By kevbogsp in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 10-06-2003, 02:13 PM
  3. Quads
    By alc in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 03-03-2003, 12:19 AM
  4. Tri's vs. Quads
    By OpenGLRox in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 02-18-2002, 09:55 AM
  5. Texturing Quads
    By MButchers in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 08-23-2001, 08:53 AM

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