Our Solar System will be constructed from spheres, representing planets, moons, and the Sun. Let's first create a Sphere
component. We are going to define a sphere as a triangle mesh of vertices that form the surface of the sphere (For more information on a triangle mesh, refer to https://en.wikipedia.org/wiki/Triangle_mesh).
Right-click on the RenderBoxExt/components
folder, select New | Java Class, and name it Sphere
. Define it as public class Sphere extends RenderObject
:
public class Sphere extends RenderObject{ private static final String TAG = "RenderBox.Sphere"; public Sphere() { super(); allocateBuffers(); } }
The constructor calls a helper method, allocateBuffers
, which allocates buffers for vertices, normals, textures, and indexes. Let's declare variables for these at the top of the class:
public static FloatBuffer vertexBuffer; public static FloatBuffer normalBuffer; public static FloatBuffer texCoordBuffer; public...