let cameras = [];
let currCameraIndex = 0;
function
setup() {
createCanvas(600, 400, WEBGL);
helpText = createP(
"Click on the buttons to switch to the"
+
" next camera of the sketch"
);
helpText.position(20, 0);
newCameraBtn = createButton(
"Switch to Next Camera"
);
newCameraBtn.position(20, 40);
newCameraBtn.mouseClicked(switchActiveCamera);
for
(let i = 0; i < 5; i++) {
cameras[i] = createCamera();
randomX = floor(random(-100, 100));
randomY = floor(random(-100, 100));
cameras[i].setPosition(randomX, randomY, 350);
}
}
function
switchActiveCamera() {
if
(currCameraIndex < 4) currCameraIndex += 1;
else
currCameraIndex = 0;
setCamera(cameras[currCameraIndex]);
}
function
draw() {
clear();
orbitControl();
normalMaterial();
translate(-150, 0);
box(65);
translate(150, 0);
box(65);
translate(150, 0);
box(65);
}