Creating a pyramid 3D object
Now that you have understood how to define shapes and render objects on screen, it will be comparatively easier to create our 3D object. We will follow almost the same procedure as we did to create our triangle. We will create our pyramid right besides our triangle; let's begin.
Defining the shape
As we've learned from the previous part, we will first create a class of our pyramid in order to define our shape. So create a file Pyramid.java
to define the shape of our pyramid object.
Our pyramid has five faces, so we will require five vertices to draw our pyramid. So after you create your Pyramid.java
, we will define our vertices, as follows:
//Package name of our game public class Pyramid { private float[] vp = { // 5 vertices of the pyramid in (x,y,z) -1.0f, -1.0f, -1.0f, //left-bottom-back 1.0f, -1.0f, -1.0f, //right-bottom-back 1.0f, -1.0f, 1.0f, //right-bottom-front -1.0f, -1.0f, 1.0f, //left-bottom-front...