cube algorithm不是generatin cube p5.js

时间:2017-10-25 03:28:53

标签: javascript p5.js

我使用p5.js和WEBGL了解更多信息here

我需要使用坐标(x,y,z)

绘制立方体

绘制它的函数:

 function drawCube(x,y,z,L) {
    A = new ThreeDpoint(x,    y,    z  );
    B = new ThreeDpoint(x,    y+L,  z  );
    C = new ThreeDpoint(x+L,  y+L,  z  );
    D = new ThreeDpoint(x+L,  y,    z  );
    E = new ThreeDpoint(x,    y,    z-L);
    F = new ThreeDpoint(x,    y+L,  z-L);
    G = new ThreeDpoint(x+L,  y+L,  z-L);
    H = new ThreeDpoint(x,    y,    z-L);

    line(A.x,A.y,A.z,  B.x,B.y,B.z);
    line(A.x,A.y,A.z,  D.x,D.y,D.z);
    line(A.x,A.y,A.z,  E.x,E.y,E.z);
    line(B.x,B.y,B.z,  F.x,F.y,F.z);
    line(B.x,B.y,B.z,  C.x,C.y,C.z);
    line(C.x,C.y,C.z,  G.x,G.y,G.z);
    line(C.x,C.y,C.z,  D.x,D.y,D.z);
    line(D.x,D.y,D.z,  H.x,H.y,H.z);
    line(E.x,E.y,E.z,  F.x,F.y,F.z);
    line(E.x,E.y,E.z,  H.x,H.y,H.z);
    line(F.x,F.y,F.z,  G.x,G.y,G.z);
    line(G.x,G.y,E.z,  H.x,H.y,H.z);
}

但这是我得到的结果:

Image

谢谢。

1 个答案:

答案 0 :(得分:0)

只是猜测,但E和H是同一个点

E = new ThreeDpoint(x,    y,    z-L);
H = new ThreeDpoint(x,    y,    z-L);

我想你希望H

H = new ThreeDpoint(x+L,  y,    z-L);