From 64288a2b387d1e27fdb2c6e61ac6c8ff6366e721 Mon Sep 17 00:00:00 2001 From: Daniel Shiffman Date: Thu, 3 Nov 2022 16:51:52 -0400 Subject: [PATCH] updating 3D Projection code noticed this was missing the final step from the video! The next Apple II video covers this topic! --- .../CC_112_3D_Rendering.pde | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/112_3D_Rendering/Processing/CC_112_3D_Rendering/CC_112_3D_Rendering.pde b/112_3D_Rendering/Processing/CC_112_3D_Rendering/CC_112_3D_Rendering.pde index 33a1f52..d609c14 100644 --- a/112_3D_Rendering/Processing/CC_112_3D_Rendering/CC_112_3D_Rendering.pde +++ b/112_3D_Rendering/Processing/CC_112_3D_Rendering/CC_112_3D_Rendering.pde @@ -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); @@ -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; @@ -78,10 +80,6 @@ void draw() { connect(i, i+4, projected); } - - - - angle += 0.03; }