Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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