Created
July 5, 2021 16:26
-
-
Save mattdesl/939f5cba6b85509c704e78cb7f983cc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List of 3D coordinates | |
const vertices = [ | |
[-0.5, 0, -0.5], | |
[0.5, 0, -0.5], | |
... | |
]; | |
// A utility that projects 3D points to 2D screen-space | |
// Using a virtual 'camera' that has a 3D position and target | |
// And viewport width and height | |
const position = [ 1, 1, 1 ]; | |
const target = [ 0, 0, 0 ]; | |
const project = createCamera({ position, target, width, height }); | |
// Project the 3D to 2D | |
const screenPoints = vertices.map(p => project(p)); | |
// ... Now draw the 2D points somehow (e.g. as paths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment