xxxxxxxxxx
80
// Issues:
// no touch device support (maybe use p5.touchgui)
// This is the scene to be rendered, common to all sketches
let r=0; // rotation should be incremented by only one of the instances
function renderScene(p){
p.lights();
p.push();
p.noFill();
p.stroke(255);
p.translate(0, 100);
p.rotateX(p.radians(90));
p.rotateZ(p.radians(90));
p.plane(p.width/2, p.height/2);
p.pop();
p.fill(255);
p.rotateX(r);
p.rotateY(r);
p.box(100);
}
// This section tests RoverCam using multiple instances of p5
// use the space-bar key to toggle control between cameras
let sketch1 = function(p) {
let v;
p.setup = function() {
p.createCanvas(p.windowWidth, p.windowHeight/2, p.WEBGL);
v = p.createRoverCam();
v.usePointerLock(p); // p is required here in instance mode
v.setState({position:[-200,0,0]});
};
p.keyPressed = function(){
if(p.key == " ") v.enableControl = !v.enableControl;
};
p.draw = function() {
p.background(v.enableControl?25:0);
renderScene(p);
r+=0.005;
};
};
let myp51 = new p5(sketch1);
let sketch2 = function(p) {
let v;
p.setup = function() {
p.createCanvas(p.windowWidth, p.windowHeight/2, p.WEBGL);
v = p.createRoverCam(); // not necessary to invoke usePointerLock() again
v.setState({position:[-300,0,100]});
v.enableControl = false; // disable the controls for this instance
};
p.keyPressed = function(){
if(p.key == " ") v.enableControl = !v.enableControl;
};
p.draw = function() {
p.background(v.enableControl?25:0);
renderScene(p);
};
};
let myp52 = new p5(sketch2);
// This section tests RoverCam with a global instance of p5
/*
let v;
setup = function() {
createCanvas(windowWidth, windowHeight, WEBGL);
v = createRoverCam();
v.usePointerLock();
v.setState({position:[-400,0,0]});
};
draw = function() {
background(v.enableControl?25:0);
renderScene(this);
r+=0.005;
}
*/