From f28f0521fdffd8ad65a333a22db46a510175b116 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 28 Feb 2011 05:08:08 +0000 Subject: [PATCH] Added CameraLight example --- .../examples/CameraLight/CameraLight.pde | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 java/libraries/opengl2/examples/CameraLight/CameraLight.pde diff --git a/java/libraries/opengl2/examples/CameraLight/CameraLight.pde b/java/libraries/opengl2/examples/CameraLight/CameraLight.pde new file mode 100644 index 000000000..10d201f8b --- /dev/null +++ b/java/libraries/opengl2/examples/CameraLight/CameraLight.pde @@ -0,0 +1,44 @@ +// CameraLight, by Andres Colubri +// Simple example showing a lit rotating cube. The projection +// is set to orthographic if the mouse is pressed. + +import processing.opengl2.*; + +float spin = 0.0; + +void setup() { + size(400, 400, OPENGL2); + + noStroke(); +} + +void draw() { + background(51); + + lights(); + + if (mousePressed) { + // The arguments of ortho are specified in screen coordinates, where (0,0) + // is the upper left corner of the screen + ortho(0, width, 0, height); + } else { + + float fov = PI/3.0; + float cameraZ = (height/2.0) / tan(fov/2.0); + perspective(fov, float(width)/float(height), + cameraZ/2.0, cameraZ*2.0); + } + + spin += 0.01; + + pushMatrix(); + translate(width/2, height/2, 0); + rotateX(PI/9); + rotateY(PI/5 + spin); + box(100); + popMatrix(); +} + + + +