O'Reilly logo

Cardboard VR Projects for Android by Matt Schoen, Jonathan Linowes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hello, cube!

A flat triangle floating in 3D space may be amazing, but it's nothing compared to what we're going to do next: a 3D cube!

The cube model data

The triangle, with just three vertices, was declared in the MainActivity class to keep the example simple. Now, we will introduce more complex geometry. We'll put it in a class named Cube.

Okay, it's just a cube that is composed of eight distinct vertices, forming six faces, right?

Well, GPUs prefer to render triangles rather than quads, so subdivide each face into two triangles; that's 12 triangles in total. To define each triangle separately, that's a total of 36 vertices, with proper winding directions, defining our model, as shown in CUBE_COORDS. Why not just define eight vertices and reuse ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required