// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 14-3: A rectangle moving along the z-axis

// A variable for the Z (depth) coordinate
float z = 0;

void setup() {
  // When using (x,y,z) coordinates, we must tell Processing we want a 3D sketch. 
  // This is done by adding a third argument, P3D (or OPENGL), to the size() function. 

void draw() {
  // Translate to a point before displaying a shape there
  // Increment z (i.e. move the shape toward the viewer)
  z++ ;
  // Restart rectangle
  if (z > 200) {
    z = 0;
  • http://www.ccttours.com/blog ww

    When I run this on my Mac (MB134),

    Using P3D: when z = 200, it turns back to 0 slowly, so the triangle reduces slowly, not as instant as the example above.

    Using OPENGL: accompanying with the increasing of the triangle, there has following image, as the track of the increasing, and its width only grow to about 70, then it returns back.

    Could you tell me what’s wrong?

  • admin

    There are some subtle differences between P3D and opengl. I believe this is due to where the renderer chooses to “clip” the shape, i.e. it’s moved far enough along the z-axis that you can’t see it anymore. There are options in openGL to move the clipping plane.

  • Manuel Almeida

    When I try to run this example I get an error:
    A fatal error has been detected by the Java Runtime Environment:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000690954cf, pid=4672, tid=2040