Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created July 5, 2021 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/939f5cba6b85509c704e78cb7f983cc2 to your computer and use it in GitHub Desktop.
Save mattdesl/939f5cba6b85509c704e78cb7f983cc2 to your computer and use it in GitHub Desktop.
// 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