File tree Expand file tree Collapse file tree 1 file changed +11
-13
lines changed
112_3D_Rendering/Processing/CC_112_3D_Rendering Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change 1- // Daniel Shiffman
2- // http://youtube.com/thecodingtrain
3- // http://codingtra.in
4-
1+ // Daniel Shiffman / Coding Train
52// Coding Challenge #112: 3D Rendering with Rotation and Projection
3+ // https://thecodingtrain.com/challenges/112-3d-rendering-with-rotation-and-projection
64// https://youtu.be/p4Iz0XJY-Qk
5+ // p5: https://editor.p5js.org/codingtrain/sketches/r8l8XXD2A
76
87float angle = 0 ;
98
109PVector [] points = new PVector [8 ];
1110
12- float [][] projection = {
13- {1 , 0 , 0 },
14- {0 , 1 , 0 }
15- };
16-
1711void setup () {
1812 size (600 , 400 );
1913
@@ -57,6 +51,14 @@ void draw() {
5751 PVector rotated = matmul(rotationY, v);
5852 rotated = matmul(rotationX, rotated);
5953 rotated = matmul(rotationZ, rotated);
54+
55+ float distance = 2 ;
56+ float z = 1 / (distance - rotated. z);
57+ float [][] projection = {
58+ {z, 0 , 0 },
59+ {0 , z, 0 }
60+ };
61+
6062 PVector projected2d = matmul(projection, rotated);
6163 projected2d. mult(200 );
6264 projected[index] = projected2d;
@@ -78,10 +80,6 @@ void draw() {
7880 connect(i, i+ 4 , projected);
7981 }
8082
81-
82-
83-
84-
8583 angle += 0.03 ;
8684}
8785
You can’t perform that action at this time.
0 commit comments