Using the 3D camera
When you work in 3D, you can move and rotate objects in space, but you can also do this with the camera. In this example, we'll draw a simple scene and animate the camera with the camera()
function.
How to do it...
You can start by setting up an OpenGL window of 640 x 480 pixels. You also need to declare two float variables named x
and z
and assign them a value inside the setup()
function. These variables will be used to animate the camera.
import processing.opengl.*; float x; float z; void setup() { size( 640, 480, OPENGL ); x = 0; z = 0; noStroke(); }
The next thing we'll do is to draw a simple 3D scene. We'll draw a floor with a cube placed in the center of it. I've used the fill()
function before each vertex to give each corner of the floor a different color. This is probably the easiest way to draw gradients with Processing.
background( 255 ); lights(); beginShape(); fill( 255, 0, 0 ); vertex( 0, height, 0); fill( 255, 255, 0 ); vertex( 0, height...