Creating 3D sketches on Android
In Chapter 3, Drawing in 3D–Lights, Camera, and Action! you've learned everything about drawing stuff in 3D. In this recipe, we'll take a look at how the third dimension works on your Android device.
How to do it...
You can start by typing the following code into a new sketch. The code is very straightforward. It's a white cube and a colorful quad, rotating at the center of the screen.
void setup() { size( displayWidth, displayHeight, P3D ); } void draw() { background( 0 ); translate( width/2, height/2, 0 ); pushMatrix(); rotateY( radians( frameCount ) ); fill( 255 ); noStroke(); box( 100 ); popMatrix(); pushMatrix(); rotateY( radians( frameCount ) ); rotateX( radians( frameCount ) ); beginShape(); fill( 255, 0, 255 ); vertex( -200, -200 ); fill( 0, 255, 0 ); vertex( 200, -200 ); fill( 0, 0, 255 ); vertex( 200, 200 ); fill( 255, 255, 0 ); vertex( -200, 200 ); endShape( CLOSE ); popMatrix(); }