Corrected bugs, and prepare for tutorial

This commit is contained in:
Thomas FORGIONE
2015-07-22 14:48:14 +02:00
parent 9b319f3c33
commit 3c59dce3a6
11 changed files with 95 additions and 26 deletions

View File

@@ -17,11 +17,6 @@ var ButtonManager = function(camera, recommendations, previewer) {
// this.recommendationElement = document.getElementById('recommendation');
// Default option
this.pointerLockElement.checked = window.locked;;
this.camera.shouldLock = window.locked;
this.camera.onPointerLockChange();
(function(self) {
self.undoElement.onclick = function() {self.camera.undo(); self.updateElements();};
self.redoElement.onclick = function() {self.camera.redo(); self.updateElements();};

View File

@@ -85,6 +85,11 @@ function initThreeElements() {
0.01, 100000, renderer, container
);
// Get default param for camera lock
document.getElementById('lock').checked = window.locked;
camera1.shouldLock = window.locked;
camera1.onPointerLockChange();
}
function initCanvases() {

View File

@@ -80,6 +80,8 @@ var TutoCamera = function() {
this.shouldLock = true;
this.shouldLogCameraAngles = true;
};
TutoCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
TutoCamera.prototype.constructor = TutoCamera;
@@ -114,6 +116,8 @@ TutoCamera.prototype.isLocked = function() {
TutoCamera.prototype.onPointerLockChange = function() {
var event = new L3D.DB.Event.PointerLocked();
if (this.isLocked()) {
// The pointer is locked : adapt the state of the camera
@@ -130,6 +134,14 @@ TutoCamera.prototype.onPointerLockChange = function() {
this.tutorial.nextStep();
}
// Send event
event.locked = true;
if (this.wasLocked !== event.locked)
event.send();
this.wasLocked = true;
} else {
this.pointerLocked = false;
@@ -147,20 +159,30 @@ TutoCamera.prototype.onPointerLockChange = function() {
else
this.startCanvas.clear();
event.locked = false;
if (this.wasLocked !== event.locked)
event.send();
if (this.tutorial.nextAction() === 'unlock-pointer') {
this.tutorial.nextStep();
}
this.wasLocked = false;
}
};
// Update function
TutoCamera.prototype.update = function(time) {
if (this.moving) {
this.linearMotion(time);
this.shouldLogCameraAngles = false;
} else if (this.movingHermite) {
this.hermiteMotion(time);
this.shouldLogCameraAngles = false;
} else {
this.normalMotion(time);
}
@@ -213,6 +235,21 @@ TutoCamera.prototype.normalMotion = function(time) {
this.mouseMove.y = 0;
this.changed = true;
if (this.shouldLogCameraAngles) {
this.shouldLogCameraAngles = false;
var self = this;
setTimeout(function() {
self.shouldLogCameraAngles = true;
}, 500);
var event = new L3D.DB.Event.KeyboardEvent();
event.camera = this;
event.send();
}
}
// Clamp phi and theta

View File

@@ -124,8 +124,15 @@ TutorialSteps.prototype.nextStep = function() {
switch (this.step) {
case 0: break;
case 3: this.camera.allowed.mouseRotate = true; break;
case 4: this.camera.allowed.keyboardRotate = true; break;
case 4:
this.camera.allowed.keyboardRotate = true;
break;
case 5:
if (!confirm('Do you want to keep pointer lock disabled ?')) {
document.getElementById('lock').checked = true;
this.camera.shouldLock = true;
this.camera.onPointerLockChange();
}
Coin.domElement.style.display = "";
Coin.max = 1;
Coin.update();

View File

@@ -59,6 +59,9 @@ function main() {
// Start rendering
setInterval(render, 20);
// Log fps
setInterval(function() {logfps(stats.getFps());}, 500);
}
function initThreeElements() {