当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Processing modelZ()用法及代码示例


Processing, modelZ()用法介绍。

用法

  • modelZ(x, y, z)

参数

  • x (float) 要映射的 3D x 坐标
  • y (float) 要映射的 3D y 坐标
  • z (float) 要映射的 3D z 坐标

返回

  • float

说明

返回模型空间中的三维 X、Y、Z 位置。这会根据当前的一组变换(缩放、旋转、平移等)返回给定坐标的 Z 值。一旦变换完成,Z 值可用于将对象放置在相对于原始点位置的空间中不再使用。



在该示例中,modelX()modelY()modelZ() 函数记录了使用一系列平移和旋转命令放置框后在空间中的位置。调用popMatrix() 后,这些转换不再适用,但模型函数返回的(x, y, z) 坐标用于将另一个框放置在同一位置。

例子

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

void draw() {
  background(0);
 
  pushMatrix();
  // 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)
  stroke(255);
  box(50);
 
  // 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
  popMatrix();

  // draw another box at the same (x, y, z) coordinate as the other
  pushMatrix();
  translate(x, y, z);
  stroke(255, 0, 0);
  box(50);
  popMatrix();
} 

有关的

相关用法


注:本文由纯净天空筛选整理自processing.org大神的英文原创作品 modelZ()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。