2016-02-03 106 views
0

我需要使用处理语言创建具有不同高度的3D块网格。如何使用处理语言创建3d块网格?

现在我停留在这样的输出: 3D block grid with varying height(Current Output)

代码上面的输出:

import peasy.*; 
import peasy.org.apache.commons.math.*; 
import peasy.org.apache.commons.math.geometry.*; 
import peasy.test.*; 
import processing.serial.*; 

PeasyCam cam; 


//float i1,i2,i3; 


void setup() { 
    size(800, 800, P3D); 
    //smooth(4); 
    cam = new PeasyCam(this, 200); 
    cam.setMinimumDistance(100); 
    cam.setMaximumDistance(200); 
} 

void draw() { 
    background(200); 
    randomSeed(30); 

    for(int x=-50;x<=50;x+=18) 
    { 
     for(int y=-50;y<=50;y+=18) 
      { 

       pushMatrix(); 
       translate(x,y,0); 

       boxT(); 


       popMatrix(); 
      } 

    } 
    } 

void boxT() 
{ 
    fill(random(255), random(255), random(255), random(255)); 
    strokeWeight(4); 
    translate(0,0,0); 
    box(10,10,random(50)); 

} 

现在,我所需的输出是高矮不一,这些3D块但一个共同基地飞机东西是这样的: 3D block grid with varying heights(Desired Output)

在此先感谢!

回答

0

处理从盒子中心处吸取盒子

如果要在同一点处绘制框的底部,则必须将框的宽度向上翻转一半。

请注意,此行不会做任何事情:

translate(0,0,0); 

相反,你会想在这里框的宽度的一半,以z轴平移。