Creating a Sphere component

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, ...

Get Cardboard VR Projects for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.