Skip to content

Commit

Permalink
Merge pull request #10 from CodingTrain/shiffman-patch-4
Browse files Browse the repository at this point in the history
updating 3D Projection code
  • Loading branch information
shiffman authored Nov 3, 2022
2 parents 9ee40d1 + 64288a2 commit 2a9d681
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
// Daniel Shiffman
// http://youtube.com/thecodingtrain
// http://codingtra.in

// Daniel Shiffman / Coding Train
// Coding Challenge #112: 3D Rendering with Rotation and Projection
// https://thecodingtrain.com/challenges/112-3d-rendering-with-rotation-and-projection
// https://youtu.be/p4Iz0XJY-Qk
// p5: https://editor.p5js.org/codingtrain/sketches/r8l8XXD2A

float angle = 0;

PVector[] points = new PVector[8];

float[][] projection = {
{1, 0, 0},
{0, 1, 0}
};

void setup() {
size(600, 400);

Expand Down Expand Up @@ -57,6 +51,14 @@ void draw() {
PVector rotated = matmul(rotationY, v);
rotated = matmul(rotationX, rotated);
rotated = matmul(rotationZ, rotated);

float distance = 2;
float z = 1 / (distance - rotated.z);
float[][] projection = {
{z, 0, 0},
{0, z, 0}
};

PVector projected2d = matmul(projection, rotated);
projected2d.mult(200);
projected[index] = projected2d;
Expand All @@ -78,10 +80,6 @@ void draw() {
connect(i, i+4, projected);
}





angle += 0.03;
}

Expand Down

0 comments on commit 2a9d681

Please sign in to comment.