2011-02-15 140 views
1

我正在使用以下代碼繪製立方體。如何繪製立方體,立方體和金字塔

// Re-creates the default perspective 
size(100, 100, P3D); 
noFill(); 
smooth(); 
float fov = PI/3.0; 
fill(25, 210, 12); 
float cameraZ = (height/2.0)/tan(fov/2.0); 
perspective(fov, float(width)/float(height), 
      cameraZ/10.0, cameraZ*10.0); 
translate(50, 50, 0); 
rotateX(-PI/6); 
rotateY(PI/3.5); 
box(45); 

調用透視方法會導致立方體以虛線顯示,如何修改代碼以獲得實線。

processing.js上面是否有任何庫提供了構建這些3D形狀的簡單包裝。

回答

1

在功能筆記,你要更好的格式化代碼:

void setup() { 
    // Re-creates the default perspective 
    size(100, 100, P3D); 
    noFill(); 
    smooth(); 
    // use this if your animation is input-based, 
    // so the browser doesn't hog the cpu. 
    noLoop(); 
} 

void draw() { 
    float fov = PI/3.0; 
    fill(25, 210, 12); 
    float cameraZ = (height/2.0)/tan(fov/2.0); 
    perspective(fov, float(width)/float(height), 
       cameraZ/10.0, cameraZ*10.0); 
    translate(50, 50, 0); 
    rotateX(-PI/6); 
    rotateY(PI/3.5); 
    box(45); 
} 

但在建設性注:此代碼在Chrome 10和Firefox使用processing.js 1.1.0工作正常,我4.沒有虛線,只有漂亮的實心邊緣。