How to make the size of the cube X, Y, Z (Width, Height, Depth)?

Here are the cube tops:

-size, -size, -size, size, -size, -size, size, size, -size, // Face 1 -size, -size, -size, -size, size, -size, size, size, -size, // Face 1 size, -size, size, size, -size, -size, size, size, -size, // Face 2 size, -size, size, size, size, size, size, size, -size, // Face 2 -size, -size, size, size, -size, size, size, -size, -size, // Face 3 -size, -size, size, -size, -size, -size, size, -size, -size, // Face 3 -size, -size, size, size, -size, size, size, size, size, // Face 4 -size, -size, size, -size, size, size, size, size, size, // Face 4 -size, -size, -size, -size, -size, size, -size, size, size, // Face 5 -size, -size, -size, -size, size, -size, -size, size, size, // Face 5 -size, size, size, size, size, size, size, size, -size, // Face 6 -size, size, size, -size, size, -size, size, size, -size // Face 6 
  • one
    Change all size to the appropriate sizeX / sizeY / sizeZ. Or use the transformation matrix =) In any case, you should learn to draw not by points, but by vertices - you define 8 vertices of the cube, and you draw triangles by their indices. - vp_arth
  • I draw GL_TRIANGLES (Vertices). And how to change them correctly on X, Y, Z if it may not work out correctly? - Labrob Labrob
  • 2
    Contract change - each line - one triangle, three points, 9 coordinates. Try xyzxyzxyz in each triangle. Theoretically, the coordinate order may be different, but it is a matter of interpretation, directions of the world matrix, etc. - vp_arth
  • vp_arth, thank you so much I wrote the answer to the question. - Labrob Labrob pm

2 answers 2

In general, I framed X, Y, Z. Thanks for the help vp_arth

The result is a code like this:

 -cX, -cY, -cZ, cX, -cY, -cZ, cX, cY, -cZ, // Face 1 -cX, -cY, -cZ, -cX, cY, -cZ, cX, cY, -cZ, // Face 1 cX, -cY, cZ, cX, -cY, -cZ, cX, cY, -cZ, // Face 2 cX, -cY, cZ, cX, cY, cZ, cX, cY, -cZ, // Face 2 -cX, -cY, cZ, cX, -cY, cZ, cX, -cY, -cZ, // Face 3 -cX, -cY, cZ, -cX, -cY, -cZ, cX, -cY, -cZ, // Face 3 -cX, -cY, cZ, cX, -cY, cZ, cX, cY, cZ, // Face 4 -cX, -cY, cZ, -cX, cY, cZ, cX, cY, cZ, // Face 4 -cX, -cY, -cZ, -cX, -cY, cZ, -cX, cY, cZ, // Face 5 -cX, -cY, -cZ, -cX, cY, -cZ, -cX, cY, cZ, // Face 5 -cX, cY, cZ, cX, cY, cZ, cX, cY, -cZ, // Face 6 -cX, cY, cZ, -cX, cY, -cZ, cX, cY, -cZ // Face 6 

    If you have a single cube (width, height, length is 1.0). So you can change to set the desired scale:

     glScalef(X, Y, Z); 

    Or apply the appropriate transformation matrix.

    • I need exactly the dimensions and not the scale (Width X, Height Y, Depth Z) - Labrob Labrob
    • one
      And what is the difference in the context of your problem? - Unick