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; var dollyCam;
// EnterVRButton for rendering enter/exit UI. // EnterVRButton for rendering enter/exit UI.
var vrButton; var vrButton;
var keyPanSpeed = 1;
var broadcastCamMovement = true;
var moved = false; var moved = false;
var pressing = false; var pressing = false;
@@ -371,8 +373,10 @@
var oldUpdate = controls.update; var oldUpdate = controls.update;
controls.update = function() { controls.update = function() {
if (broadcastCamMovement) {
oldUpdate(); oldUpdate();
publishCameraLocationMessage(); publishCameraLocationMessage();
}
}; };
// The dolly has to be a PerspectiveCamera, as opposed // The dolly has to be a PerspectiveCamera, as opposed
@@ -630,7 +634,7 @@
}, { }, {
y: pos2.y, y: pos2.y,
x: pos2.x, x: pos2.x,
z: pos2.z -9 z: pos2.z - 9
}, { }, {
x: 0, x: 0,
y: 0, y: 0,
@@ -644,9 +648,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos2.y , y: pos2.y,
x: pos2.x -10, x: pos2.x - 10,
z: pos2.z -5 z: pos2.z - 5
}, { }, {
x: 0, x: 0,
y: -5, y: -5,
@@ -661,9 +665,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos2.y , y: pos2.y,
x: pos2.x + 10, x: pos2.x + 10,
z: pos2.z -5 z: pos2.z - 5
}, { }, {
x: 0, x: 0,
y: 5, y: 5,
@@ -678,9 +682,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos3.y , y: pos3.y,
x: pos3.x, x: pos3.x,
z: pos3.z -9 z: pos3.z - 9
}, { }, {
x: 0, x: 0,
y: 0, y: 0,
@@ -694,9 +698,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos3.y , y: pos3.y,
x: pos3.x -10, x: pos3.x - 10,
z: pos3.z -5 z: pos3.z - 5
}, { }, {
x: 0, x: 0,
y: -5, y: -5,
@@ -711,9 +715,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos3.y , y: pos3.y,
x: pos3.x + 10, x: pos3.x + 10,
z: pos3.z -5 z: pos3.z - 5
}, { }, {
x: 0, x: 0,
y: 5, y: 5,
@@ -728,9 +732,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos4.y , y: pos4.y,
x: pos4.x, x: pos4.x,
z: pos4.z -9 z: pos4.z - 9
}, { }, {
x: 0, x: 0,
y: 0, y: 0,
@@ -744,9 +748,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos4.y , y: pos4.y,
x: pos4.x -10, x: pos4.x - 10,
z: pos4.z -5 z: pos4.z - 5
}, { }, {
x: 0, x: 0,
y: -5, y: -5,
@@ -761,9 +765,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos4.y , y: pos4.y,
x: pos4.x + 10, x: pos4.x + 10,
z: pos4.z -5 z: pos4.z - 5
}, { }, {
x: 0, x: 0,
y: 5, y: 5,
@@ -780,9 +784,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos5.y , y: pos5.y,
x: pos5.x, x: pos5.x,
z: pos5.z -9 z: pos5.z - 9
}, { }, {
x: 0, x: 0,
y: 0, y: 0,
@@ -796,9 +800,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos5.y , y: pos5.y,
x: pos5.x -10, x: pos5.x - 10,
z: pos5.z -5 z: pos5.z - 5
}, { }, {
x: 0, x: 0,
y: -5, y: -5,
@@ -813,9 +817,9 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos5.y , y: pos5.y,
x: pos5.x + 10, x: pos5.x + 10,
z: pos5.z -5 z: pos5.z - 5
}, { }, {
x: 0, x: 0,
y: 5, y: 5,
@@ -832,8 +836,8 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos5.y , y: pos5.y,
x: pos5.x -10, x: pos5.x - 10,
z: pos5.z + 5 z: pos5.z + 5
}, { }, {
x: 0, x: 0,
@@ -849,7 +853,7 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos5.y , y: pos5.y,
x: pos5.x + 10, x: pos5.x + 10,
z: pos5.z + 5 z: pos5.z + 5
}, { }, {
@@ -866,7 +870,7 @@
height: 5, height: 5,
depth: 0.1, depth: 0.1,
}, { }, {
y: pos5.y , y: pos5.y,
x: pos5.x, x: pos5.x,
z: pos5.z + 9 z: pos5.z + 9
}, { }, {
@@ -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) { 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) { switch (buttonNumber) {
case 6: case 6:
moveForward();
dollyCam.position.add(direction.multiplyScalar(keyPanSpeed));
controls.update();
moved = true;
break; break;
case 7: case 7:
dollyCam.position.add(direction.multiplyScalar(-keyPanSpeed)); moveBackward();
controls.update();
moved = true;
break; break;
case 8: case 8:
dollyCam.position.add(strafeVector.multiplyScalar(keyPanSpeed)) strafeRight();
controls.update();
moved = true;
break; break;
case 9: case 9:
dollyCam.position.add(strafeVector.multiplyScalar(-keyPanSpeed)) strafeLeft();
controls.update();
moved = true;
break; break;
case 0: case 0:
moveToPreviousPlace(); moveToPreviousPlace();
@@ -1126,6 +1185,9 @@
case 1: case 1:
moveToNextPlace(); moveToNextPlace();
break; break;
case 2:
toggleCamMovementBroadcast();
break;
} }