Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2a9d681

Browse files
Merge pull request #10 from CodingTrain/shiffman-patch-4
updating 3D Projection code
2 parents 9ee40d1 + 64288a2 commit 2a9d681

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

‎112_3D_Rendering/Processing/CC_112_3D_Rendering/CC_112_3D_Rendering.pde‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
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

87
float angle = 0;
98

109
PVector[] points = new PVector[8];
1110

12-
float[][] projection = {
13-
{1, 0, 0},
14-
{0, 1, 0}
15-
};
16-
1711
void 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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /