PDA

View Full Version : Glrotatef()



Raymond
03-21-2016, 10:31 AM
hello i am still new to the gl programming so i'm asked to make a triangle rotate arround a cirlce so i used the center of the circle as a center of rotation using translated() then rotated() but the question is that when i do that it rotates fat from it... i need to adjust the distance between the translated origin and the triangle how do i do that ?

Spoops
03-21-2016, 12:13 PM
Could you post some code about the transformations you do? Maybe you are not translating back after rotating.

Try to set up different orders when doing transformations. The old pipeline is a bit annoying about that, if I recall correctly.

Raymond
03-21-2016, 03:04 PM
Could you post some code about the transformations you do? Maybe you are not translating back after rotating.

Try to set up different orders when doing transformations. The old pipeline is a bit annoying about that, if I recall correctly.

i don't quiet understand how to translate back ? this is what i only do (it's the idea of making triangles rotate around a circle"tires of a car " ) : every thing has his functions created and drawn
void Draw()
{
glClear(GL_COLOR_BUFFER_BIT); //clears the previous drawings from the window
glLoadIdentity();

glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-25, 10);
glVertex2f(-25, 30);
glVertex2f(-15, 30);
glVertex2f( -15, 10);
glVertex2f(-15, 30);
glVertex2f(10,30);
glVertex2f(10,10 );
glVertex2f(10, 30);
glVertex2f(15, 30);
glVertex2f(15, 10);
glEnd();

glBegin(GL_POLYGON);
glVertex2f(-50, 10);
glVertex2f(50, 10);
glVertex2f(50, -10);
glVertex2f(-50, -10);

glEnd();

// draw circle
Draw_Circle(15,-32,-20);
glColor3f(1.0, 1.0, 1.0);
Draw_Circle(7.5, -32, -20);
glColor3f(0.0, 0.6, 1.0);
Draw_Circle(3, -32, -20);


// draw circle 2
glColor3f(0.0, 0.0, 0.0);
Draw_Circle(15, 20, -20);
glColor3f(1.0, 1.0, 1.0);
Draw_Circle(7.5, 20, -20);
glColor3f(0.0, 0.6, 1.0);
Draw_Circle(3, 20, -20);

//glPushMatrix();

glColor3f(0.0, 1.0, 1.0);
glTranslated(50, 50, 0);
glRotated(angle, 0.0, 0.0, 1.0);
//glScaled(200, 200, 1);
glBegin(GL_TRIANGLES);
glVertex2f(-32, -12);
glVertex2f(-34,-16);
glVertex2f(-30,-16);
glEnd();
//glPopMatrix();

glutSwapBuffers();
glFlush();//execute all commands from buffers
}