0

Is there an openGL function for creating a 3D cube using it's dimensions as input parameters?
If not what algorithm would i use for generating the cube's vertex array?

What would be the easiest way to create a cube that does not require calculating the vertex array by hand?

admdrew
  • 3,790
  • 4
  • 27
  • 39
kyle k
  • 5,134
  • 10
  • 31
  • 45
  • Create a cube, using vertex unit points, and then, use scale transformation to do whatever you want – Amadeus May 05 '14 at 18:00

1 Answers1

1

Create an unitary cube. It is very easy to create it:

It's vertexes are:

GLfloat vertex[] = { -1.0, -1.0, 1.0,  // 0
                      1.0, -1.0, 1.0,  // 1
                      1.0, 1.0, 1.0,   // 2
                     -1.0, 1.0, 1.0,   // 3
                     -1.0, -1.0, -1.0, // 4
                      1.0, -1.0, -1.0, // 5
                      1.0, 1.0, -1.0,  // 6
                     -1.0, 1.0, -1.0}; // 7

Now, create an array of how the faces are connected. Using QUAD as exemple,

GLuint faces[] = { 0, 1, 2, 3,
                   1, 5, 6, 2,
                   5, 4, 7, 6,
                   7, 4, 0, 3,
                   3, 2, 6, 7,
                   0, 4, 5, 1 };

Let's say that you create a function, called cube(), in which you passed this coordinates to the driver.

Now, to have any kind of cube, just specify the scale transformation to transform this unitary cube. For example, to make a cube of 4 units:

scale(4.0, 4.0, 4.0);
cube();

and so on

Amadeus
  • 10,199
  • 3
  • 25
  • 31