Drawing Rectangular prism opengl

I am supposed to create a class of rectangular prism in opengl. I am having touble in writing my "draw()" function.

I have searched the web, and lots of the sites have:
1
2
3
4
5
6
glBegin(GL_Quads);

glVertex3f(x,y,z);
glVertex3f(...);
glVertex3f(...);
glVertex3f(...);

3d coordintaes for each face.

for my code, I am getting a value for lengths of x, y and z like "getXlength(x_length)" etc... I would like to know how I can use these values to draw the prism rather than giving values for each coordinates in each face. Thanks for the help
To make your prism, just start from the origin, and calculate the values for each side from the lengths of the prism. Then rotate and translate the prism to where you want. Also, its GL_QUADS not GL_Quads.

Here is a quick example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
glPushMatrix();
  glLoadIdentity();

  // Rotate before Translate (otherwise wierd things happen)
  glRotated(rotz, 0.0, 0.0, 1.0);
  glRotated(roty, 0.0, 1.0, 0.0);
  glRotated(rotx, 1.0, 0.0 ,0.0);
  glTranslated(xpos, ypos, zpos);

  glBegin(GL_QUADS);
    glVertex4d(0.0, 0.0, 0.0, 1.0);   // Start from Origin
    glVertex4d(0.0, yLen, 0.0, 1.0);
    glVertex4d(xLen, yLen, 0.0, 1.0);
    glVertex4d(xLen, 0.0, 0.0, 1.0);

    glVertex4d(0.0, 0.0, 0.0, 1.0);  // Start new face
    glVertex4d(0.0, 0.0, zLen, 1.0);
    glVertex4d(0.0, yLen, zLen, 1.0);
    glVertex4d(0.0, yLen, 0.0, 1.0);

    //etc...
  glEnd();
glPopMatrix();
Topic archived. No new replies allowed.