xxxxxxxxxx
84
// Engineer: jWilliamDunn 2020
// Experimenting with multiple instances of RoverCam
// Issues:
let view1, view2, view3;
function keyPressed() { // cameras are numbered
if (key == "1" || key == "2" || key == "3"){
view1.setActive(false);
view2.setActive(false);
view3.setActive(false);
}
if (key == "1") view1.setActive(true);
if (key == "2") view2.setActive(true);
if (key == "3") view3.setActive(true);
}
function setup() {
let r = createCanvas(windowWidth, windowHeight, WEBGL);
view1 = new RoverCam();
view2 = new RoverCam();
view3 = new RoverCam();
view1.setState({
active: true,
fov: 1,
rotation: [PI/4,0,0],
position: [-30,0,-10]
});
view2.setState({
active: false,
fov: 1,
rotation: [PI/4,PI/8,0],
position: [-10,0,-30]
});
view3.setState({
active: false,
fov: 2,
rotation: [PI/4,PI/4,0],
position: [-10,-10,-10]
});
view1.usePointerLock();
frameRate(60);
strokeWeight(2);
}
function windowResized() {
resizeCanvas(window.innerWidth, window.innerHeight, WEBGL);
}
let i = 0;
function draw() {
background(0, 0, 51);
drawAxes();
lights();
translate(10, 10, 10);
rotateX(i);
rotateY(i);
i += 0.01;
box(5);
}
function drawAxes() {
push();
noStroke();
fill(127, 0, 0); // X red
translate(75, 0.5, 0.5);
box(150, 1, 1);
pop();
push();
noStroke();
fill(0, 127, 0); // Y green
translate(0.5, 75, 0.5);
box(1, 150, 1);
pop();
push();
noStroke();
fill(0, 0, 127); // Z blue
translate(0.5, 0.5, 75);
box(1, 1, 150);
pop();
}