![java lwjgl drawing a 3d cube tutorial java lwjgl drawing a 3d cube tutorial](https://i.stack.imgur.com/clNbv.png)
The top point is right in the middle (zero), and the bottom points are one left from center, and one right from center. The top of the pyramid is one high from the center, the bottom of the pyramid is one down from the center.
#Java lwjgl drawing a 3d cube tutorial code#
The following code will create the pyramid around a central axis. You have to remember that the center of any object should be 0 on the X, 0 on the Y, and 0 on the Z. In order for your object to spin around an axis, it has to be designed AROUND that axis.
![java lwjgl drawing a 3d cube tutorial java lwjgl drawing a 3d cube tutorial](https://i.ytimg.com/vi/7QDz81jMsF8/maxresdefault.jpg)
One thing I've been asked quite a bit is "how come my objects are not spinning on their axis? It seems like they are spinning all over the screen".
![java lwjgl drawing a 3d cube tutorial java lwjgl drawing a 3d cube tutorial](https://i.stack.imgur.com/fAhaa.png)
GlBegin(GL_TRIANGLES) // Start Drawing The PyramidĪ few of you have taken the code from the last tutorial, and made 3D objects of your own. GlRotatef(rtri,0.0f,1.0f,0.0f) // Rotate The Pyramid On It's Y Axis GlTranslatef(-1.5f,0.0f,-6.0f) // Move Left And Into The Screen GlClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) // Clear The Screen And The Depth Buffer int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing We'll blend the colors on the pyramid, creating a smoothly colored object, and for the square we'll color each face a different color. By doing this, we turn the triangle into a pyramid, and the square into a cube. We will do this by adding a left, back, and right side to the triangle, and a left, right, back, top and bottom to the square. Expanding on the last tutorial, we'll now make the object into TRUE 3D object, rather than 2D objects in a 3D world.