Reference for Processing version 1.2. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.



void setup() {
  size(500, 500, P3D);

void draw() {
  // start at the middle of the screen
  translate(width/2, height/2, -200);     
  // some random rotation to make things interesting
  rotateY(1.0); //yrot);
  rotateZ(2.0); //zrot);
  // rotate in X a little more each frame
  rotateX(frameCount / 100.0);
  // offset from center
  translate(0, 150, 0);
  // draw a white box outline at (0, 0, 0)
  // the box was drawn at (0, 0, 0), store that location
  float x = modelX(0, 0, 0);
  float y = modelY(0, 0, 0);
  float z = modelZ(0, 0, 0);
  // clear out all the transformations

  // draw another box at the same (x, y, z) coordinate as the other
  translate(x, y, z);
  stroke(255, 0, 0);
Description Returns the three-dimensional X, Y, Z position in model space. This returns the X value for a given coordinate based on the current set of transformations (scale, rotate, translate, etc.) The X value can be used to place an object in space relative to the location of the original point once the transformations are no longer in use.

In the example, the modelX(), modelY(), and modelZ() methods record the location of a box in space after being placed using a series of translate and rotate commands. After popMatrix() is called, those transformations no longer apply, but the (x, y, z) coordinate returned by the model functions is used to place another box in the same location.
modelZ(x, y, z)
x int or float: 3D x coordinate to be mapped
y int or float: 3D y coordinate to be mapped
z int or float: 3D z coordinate to be mapped
Returns float
Usage Web & Application
Related modelX()
Updated on June 14, 2010 12:05:29pm EDT

Creative Commons License