# OpenGL Problems drawing and rotating planes

This topic is 3268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to draw some 2-d plane and then rotate them in OpenGL. To draw the planes I have the following method:  virtual void makePlane (Plane* c,int ct) { glBegin(GL_QUADS); { cout << "DRAWING PLANE " << ct << endl; cout << "Vertex: " << c->getCol() << "," << c->getRow() << endl; glVertex3f(c->getCol(), c->getRow(), 0); cout << "Vertex: " << c->getCol()+1 << "," << c->getRow() << endl; glVertex3f(c->getCol()+1,c->getRow()+1, 0); cout << "Vertex: " << c->getCol()+1 << "," << c->getRow()+1 << endl; glVertex3f(c->getCol(),c->getRow()+1, 0); cout << "Vertex: " << c->getCol() << "," << c->getRow()+1 << endl; glVertex3f(c->getCol()+1,c->getRow(), 0); } glEnd(); }  Each plane is 1 unit by 1 unit represented by its row and column number that I give it. The problem is that the planes are getting drawn as five sided figures instead of four. Instead of a line connecting the right top to right bottom, there are lines from right top and right bottom to the center. I'm also trying to rotate the planes but I'm not sure how to. I can't call rotate before I call makePlanes because that rotates the entire group of planes.

##### Share on other sites
For GL_QUADS, you have to render your points in a clockwise or counter-clockwise pattern. By going from [col, row] to [col + 1][row + 1] in your first two instructions, you're cutting diagonally across the face. Assuming you are working under the OpenGL default that counter-clockwise is the front face, you should render in this pattern:

col, row
col + 1, row
col + 1, row + 1
col, row + 1

Regarding rotation, change your method to look like this:

vitual void makePlane (Plane* c, int ct){glPushMatrix();glRotate.../* NOW your plane-rendering code */glPopMatrix();}

The glPushMatrix adds a layer of calculation onto the stack. (Sorry I don't have more accurate terminology, I'm sure someone will correct me.) When you call glRotate* you're rotating that layer. When you call glPopMatrix you are disposing of any rotations or translations made to that layer. So only the plane you are currently rendering gets rotated.

##### Share on other sites
The planes are drawn correctly now but they still aren't rotating correctly.

Here is my plane drawing code:

virtual void display()
{
int ct = 0;
for(int row = 0; row < myScreensTall; row++)
{
for(int col = 0; col < myScreensWide; col++)
{
glPushMatrix();
makePlane(myGrid[row][col],ct);
glPopMatrix();
ct++;
}
}
}

/*
* Create a plane
*/
virtual void makePlane (Card* c,int ct)
{
glPushMatrix();
glRotatef(myAngle,0,1,0);
{
cout << "DRAWING PLANE " << ct << endl;
cout << "Vertex: " << c->getCol() << "," << c->getRow() << endl;
glVertex3f(c->getCol(), c->getRow(), 0);
cout << "Vertex: " << c->getCol()+1 << "," << c->getRow() << endl;
glVertex3f(c->getCol()+1,c->getRow(), 0);
cout << "Vertex: " << c->getCol()+1 << "," << c->getRow()+1 << endl;
glVertex3f(c->getCol()+1,c->getRow()+1, 0);
cout << "Vertex: " << c->getCol() << "," << c->getRow()+1 << endl;
glVertex3f(c->getCol(),c->getRow()+1, 0);
}
glEnd();
glPopMatrix();
}

They all rotate in one big block, which makes sense because the axis rotates first and then the translations to draw the shape occur. I need the translation to occur before the rotation.

To fix this I can do something like this:
/*
* Display all objects in the scene.
*
* Lighting values should generally be set first, before scene objects.
*/
virtual void display()
{
int ct = 0;
for(int row = 0; row < myScreensTall; row++)
{
for(int col = 0; col < myScreensWide; col++)
{
glPushMatrix();
glTranslated((2*col+1)/2,(2*row+1)/2,0);
glRotatef(myAngle, 0, 1, 0);
makePlane(myGrid[row][col],ct);
glPopMatrix();
ct++;
}
}
}

/*
* Create a plane
*/
virtual void makePlane (Card* c,int ct)
{
{
glVertex3f(-.5,-.5, 0);
glVertex3f(-.5,.5, 0);
glVertex3f(.5,.5, 0);
glVertex3f(.5,-.5, 0);
}
glEnd();
}

which makes the planes rotate independently but they seem to be rotating at different speeds...

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 12
• 15
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632655
• Total Posts
3007674
• ### Who's Online (See full list)

There are no registered users currently online

×