ZFGC
Resources => Coding => Topic started by: Starforsaken101 on June 04, 2009, 09:58:34 pm
-
Hey guys,
So I'm writing a program in C++ with OpenGL (GLUT) and I require assistance since I'm still new to all of this.
I'm basically drawing 2D squares, right? So I draw my little points and it fills out a green or gray square, depending on what I need. However, I would like this square to kind of display on a slant/diagonally (almost looking like a diamond). This really only needs a slight rotation.
How does one rotate a square without it having like, rotating all the time? I just need to turn it a little and it should be fine.
-
glPushMatrix();
glRotatef(theta, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.8f, -0.8f);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(-0.8f, 0.8f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.8f, 0.8f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.8f, -0.8f);
glEnd();
glPopMatrix();
where theta is whatever the angle you want to rotate it by is (in Radians, obviously). So long as theta is constant, it will not be rotated any more. It should only 'spin' if you change constantly increment theta.
-
I have plenty of stock opengl 2D rendering code if you want to look through it, it has most things like scaling/rotation/etc.
-
glPushMatrix();
glRotatef(theta, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.8f, -0.8f);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(-0.8f, 0.8f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.8f, 0.8f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.8f, -0.8f);
glEnd();
glPopMatrix();
That is totally awesome! Thanks. I was under the impression that glRotatef rotated it constantly but I guess that's just due to the source code my prof wrote. Thanks!
where theta is whatever the angle you want to rotate it by is (in Radians, obviously). So long as theta is constant, it will not be rotated any more. It should only 'spin' if you change constantly increment theta.