xxxxxxxxxx
46
// The Coding Train / Daniel Shiffman
// Video: https://youtu.be/O1mYw-3Wl_Q
let angle = 0;
let camX, camY, camZ;
function setup() {
createCanvas(400, 300, WEBGL);
}
function draw() {
background(175);
//translate(0, 0, mouseX);
lights();
camX = map(mouseX, 0, width, -200, 200);
let posZ = height / 2 / tan(PI / 6);
camera(camX, 0, posZ, camX, 0, 0, 0, 1, 0);
// shaky camera
// camX = random(-5, 5);
// camY = random(-5, 5);
// camZ = random(-5, 5);
// camera(camX, camY, camZ + posZ, 0, 0, 0, 0, 1, 0);
push();
rotateX(angle);
rotateY(angle * 0.3);
rotateZ(angle * 1.2);
normalMaterial();
noStroke();
box(100);
pop();
// Add a plane at bottom
translate(0, 100);
rotateX(HALF_PI);
ambientMaterial(255, 255, 255);
// Add noStroke to remove wireframe
noStroke();
plane(500, 500);
angle += 0.03;
}