xxxxxxxxxx
67
let cam;
let x = 0;
let y = 0;
let z = 0;
function setup() {
createCanvas(1000, 600, WEBGL);
textureWrap(REPEAT);
cam = createCamera();
perspective(PI / 3.0, width / height, 0.1, 5000);
cam.setPosition(0, -200, 0);
}
function draw() {
stroke(0);
strokeWeight(0);
background(100);
push();
rotateY(180);
translate(0, -600, 0);
loadScene();
pop();
if (mouseIsPressed) {
onMouseMove();
}
cameraMotion();
// orbitControl();
}
function cameraMotion(){
x=y=z=0;
if (keyIsDown(87)) {
z = -5;
}
if (keyIsDown(83)) {
z = 5;
}
if (keyIsDown(65)) {
x = -5;
}
if (keyIsDown(68)) {
x = 5;
}
if (keyIsDown(32)) {
if (y <= 100) {
y = y + 5
}
if (y > 100) {
//and if y < the distance between collision bodies
y = y - 5
//else y = y
}
}
cam.move(x, y, z);
}
function onMouseMove() {
let DPI = 0.002;
let horizontalPerspective = pmouseX - mouseX;
let verticalPerspective = pmouseY - mouseY;
if (cam){
cam.pan(horizontalPerspective * DPI);
cam.tilt(-verticalPerspective * DPI);
}}