xxxxxxxxxx
59
const vertices = [
[1, 1, 1],
[-1, 1, 1],
[1, -1, 1],
[-1, -1, 1],
[1, 1, -1],
[-1, 1, -1],
[1, -1, -1],
[-1, -1, -1],
];
const edges = [
[0, 1],
[0, 2],
[0, 4],
[2, 3],
[1, 3],
[2, 6],
[4, 5],
[4, 6],
[1, 5],
[6, 7],
[5, 7],
[3, 7],
];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(20);
let camera_pos = createVector(2, 3, 5);
let cx = camera_pos.x;
let cy = camera_pos.y;
let cz = camera_pos.z;
let focal_distance = 1;
stroke(255);
// translate(0, height*0.9);
scale(width);
translate(0, 1);
scale(1, -1);
strokeWeight(0.005);
for(let edge of edges) {
const [p1, p2] = edge;
line(
(vertices[p1][0] - cx)*focal_distance/(vertices[p1][2]-cz),
(vertices[p1][1] - cy)*focal_distance/(vertices[p1][2]-cz),
(vertices[p2][0] - cx)*focal_distance/(vertices[p2][2]-cz),
(vertices[p2][1] - cy)*focal_distance/(vertices[p2][2]-cz)
);
}
}