toggle sync & normal position control

This commit is contained in:
Senad Uka
2017-03-23 16:03:03 +01:00
parent e23e046576
commit f4abef7caa

View File

@@ -235,6 +235,8 @@
var dollyCam;
// EnterVRButton for rendering enter/exit UI.
var vrButton;
var keyPanSpeed = 1;
var broadcastCamMovement = true;
var moved = false;
var pressing = false;
@@ -371,8 +373,10 @@
var oldUpdate = controls.update;
controls.update = function() {
if (broadcastCamMovement) {
oldUpdate();
publishCameraLocationMessage();
}
};
// The dolly has to be a PerspectiveCamera, as opposed
@@ -1087,38 +1091,93 @@
}
function moveForward() {
var direction = camera.getWorldDirection();
if (!pressing) {
dollyCam.position.add(direction.multiplyScalar(keyPanSpeed));
controls.update();
moved = true;
pressing = true;
setTimeout(function() {
pressing = false;
}, 200);
}
}
function moveBackward() {
var direction = camera.getWorldDirection();
if (!pressing) {
dollyCam.position.add(direction.multiplyScalar(-keyPanSpeed));
controls.update();
moved = true;
pressing = true;
setTimeout(function() {
pressing = false;
}, 200);
}
}
function strafeLeft() {
var vectorUp = new THREE.Vector3(0, 1, 0);
var direction = camera.getWorldDirection();
var strafeVector = new THREE.Vector3().crossVectors(vectorUp, direction).normalize();
if (!pressing) {
dollyCam.position.add(strafeVector.multiplyScalar(-keyPanSpeed))
controls.update();
moved = true;
pressing = true;
setTimeout(function() {
pressing = false;
}, 200);
}
}
function strafeRight() {
var vectorUp = new THREE.Vector3(0, 1, 0);
var direction = camera.getWorldDirection();
var strafeVector = new THREE.Vector3().crossVectors(vectorUp, direction).normalize();
if (!pressing) {
dollyCam.position.add(strafeVector.multiplyScalar(keyPanSpeed))
controls.update();
moved = true;
pressing = true;
setTimeout(function() {
pressing = false;
}, 200);
}
}
function toggleCamMovementBroadcast() {
if (!pressing) {
broadcastCamMovement = !broadcastCamMovement;
pressing = true;
setTimeout(function() {
pressing = false;
}, 500);
}
};
function buttonPressed(buttonNumber) {
var keyPanSpeed = 1;
var direction = camera.getWorldDirection();
var vectorUp = new THREE.Vector3(0, 1, 0);
var strafeVector = new THREE.Vector3().crossVectors(vectorUp, direction).normalize();
switch (buttonNumber) {
case 6:
dollyCam.position.add(direction.multiplyScalar(keyPanSpeed));
controls.update();
moved = true;
moveForward();
break;
case 7:
dollyCam.position.add(direction.multiplyScalar(-keyPanSpeed));
controls.update();
moved = true;
moveBackward();
break;
case 8:
dollyCam.position.add(strafeVector.multiplyScalar(keyPanSpeed))
controls.update();
moved = true;
strafeRight();
break;
case 9:
dollyCam.position.add(strafeVector.multiplyScalar(-keyPanSpeed))
controls.update();
moved = true;
strafeLeft();
break;
case 0:
moveToPreviousPlace();
@@ -1126,6 +1185,9 @@
case 1:
moveToNextPlace();
break;
case 2:
toggleCamMovementBroadcast();
break;
}