Corrected bugs, and prepare for tutorial
This commit is contained in:
parent
9b319f3c33
commit
3c59dce3a6
|
@ -139,11 +139,21 @@ module.exports.replay_index = function(req, res, next) {
|
||||||
|
|
||||||
module.exports.tutorial = function(req, res) {
|
module.exports.tutorial = function(req, res) {
|
||||||
|
|
||||||
|
db.tryUser(req.session.user_id, function(id) {
|
||||||
|
req.session.user_id = id;
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/html');
|
// 1 is the ID of peach scene
|
||||||
res.render('tutorial.jade', res.lcals, function(err, result) {
|
db.createExp(id, 1, function(id) {
|
||||||
res.send(result);
|
req.session.exp_id = id;
|
||||||
|
req.session.save();
|
||||||
|
|
||||||
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
res.render('tutorial.jade', res.lcals, function(err, result) {
|
||||||
|
res.send(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.clicker = function(req, res, next) {
|
module.exports.clicker = function(req, res, next) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ block title
|
||||||
|
|
||||||
block mainjs
|
block mainjs
|
||||||
script initMainScene = #{scene};
|
script initMainScene = #{scene};
|
||||||
script locked = #{session.locked};
|
script locked = #{session.locked === undefined ? 'true' : session.locked};
|
||||||
script(src="/static/js/prototypeinteractive.min.js")
|
script(src="/static/js/prototypeinteractive.min.js")
|
||||||
|
|
||||||
block description
|
block description
|
||||||
|
|
|
@ -17,11 +17,6 @@ var ButtonManager = function(camera, recommendations, previewer) {
|
||||||
|
|
||||||
// this.recommendationElement = document.getElementById('recommendation');
|
// this.recommendationElement = document.getElementById('recommendation');
|
||||||
|
|
||||||
// Default option
|
|
||||||
this.pointerLockElement.checked = window.locked;;
|
|
||||||
this.camera.shouldLock = window.locked;
|
|
||||||
this.camera.onPointerLockChange();
|
|
||||||
|
|
||||||
(function(self) {
|
(function(self) {
|
||||||
self.undoElement.onclick = function() {self.camera.undo(); self.updateElements();};
|
self.undoElement.onclick = function() {self.camera.undo(); self.updateElements();};
|
||||||
self.redoElement.onclick = function() {self.camera.redo(); self.updateElements();};
|
self.redoElement.onclick = function() {self.camera.redo(); self.updateElements();};
|
||||||
|
|
|
@ -85,6 +85,11 @@ function initThreeElements() {
|
||||||
0.01, 100000, renderer, container
|
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() {
|
function initCanvases() {
|
||||||
|
|
|
@ -80,6 +80,8 @@ var TutoCamera = function() {
|
||||||
|
|
||||||
this.shouldLock = true;
|
this.shouldLock = true;
|
||||||
|
|
||||||
|
this.shouldLogCameraAngles = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
TutoCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
|
TutoCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
|
||||||
TutoCamera.prototype.constructor = TutoCamera;
|
TutoCamera.prototype.constructor = TutoCamera;
|
||||||
|
@ -114,6 +116,8 @@ TutoCamera.prototype.isLocked = function() {
|
||||||
|
|
||||||
TutoCamera.prototype.onPointerLockChange = function() {
|
TutoCamera.prototype.onPointerLockChange = function() {
|
||||||
|
|
||||||
|
var event = new L3D.DB.Event.PointerLocked();
|
||||||
|
|
||||||
if (this.isLocked()) {
|
if (this.isLocked()) {
|
||||||
|
|
||||||
// The pointer is locked : adapt the state of the camera
|
// The pointer is locked : adapt the state of the camera
|
||||||
|
@ -130,6 +134,14 @@ TutoCamera.prototype.onPointerLockChange = function() {
|
||||||
this.tutorial.nextStep();
|
this.tutorial.nextStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send event
|
||||||
|
event.locked = true;
|
||||||
|
|
||||||
|
if (this.wasLocked !== event.locked)
|
||||||
|
event.send();
|
||||||
|
|
||||||
|
this.wasLocked = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.pointerLocked = false;
|
this.pointerLocked = false;
|
||||||
|
@ -147,20 +159,30 @@ TutoCamera.prototype.onPointerLockChange = function() {
|
||||||
else
|
else
|
||||||
this.startCanvas.clear();
|
this.startCanvas.clear();
|
||||||
|
|
||||||
|
event.locked = false;
|
||||||
|
|
||||||
|
if (this.wasLocked !== event.locked)
|
||||||
|
event.send();
|
||||||
|
|
||||||
if (this.tutorial.nextAction() === 'unlock-pointer') {
|
if (this.tutorial.nextAction() === 'unlock-pointer') {
|
||||||
this.tutorial.nextStep();
|
this.tutorial.nextStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.wasLocked = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update function
|
// Update function
|
||||||
TutoCamera.prototype.update = function(time) {
|
TutoCamera.prototype.update = function(time) {
|
||||||
|
|
||||||
if (this.moving) {
|
if (this.moving) {
|
||||||
this.linearMotion(time);
|
this.linearMotion(time);
|
||||||
|
this.shouldLogCameraAngles = false;
|
||||||
} else if (this.movingHermite) {
|
} else if (this.movingHermite) {
|
||||||
this.hermiteMotion(time);
|
this.hermiteMotion(time);
|
||||||
|
this.shouldLogCameraAngles = false;
|
||||||
} else {
|
} else {
|
||||||
this.normalMotion(time);
|
this.normalMotion(time);
|
||||||
}
|
}
|
||||||
|
@ -213,6 +235,21 @@ TutoCamera.prototype.normalMotion = function(time) {
|
||||||
this.mouseMove.y = 0;
|
this.mouseMove.y = 0;
|
||||||
|
|
||||||
this.changed = true;
|
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
|
// Clamp phi and theta
|
||||||
|
|
|
@ -124,8 +124,15 @@ TutorialSteps.prototype.nextStep = function() {
|
||||||
switch (this.step) {
|
switch (this.step) {
|
||||||
case 0: break;
|
case 0: break;
|
||||||
case 3: this.camera.allowed.mouseRotate = true; 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:
|
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.domElement.style.display = "";
|
||||||
Coin.max = 1;
|
Coin.max = 1;
|
||||||
Coin.update();
|
Coin.update();
|
||||||
|
|
|
@ -59,6 +59,9 @@ function main() {
|
||||||
// Start rendering
|
// Start rendering
|
||||||
setInterval(render, 20);
|
setInterval(render, 20);
|
||||||
|
|
||||||
|
// Log fps
|
||||||
|
setInterval(function() {logfps(stats.getFps());}, 500);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initThreeElements() {
|
function initThreeElements() {
|
||||||
|
|
|
@ -248,16 +248,19 @@ L3D.PointerCamera.prototype.onPointerLockChange = function() {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.pointerLocked = false;
|
this.pointerLocked = false;
|
||||||
this.mousePointer.clear();
|
if (this.mousePointer)
|
||||||
|
this.mousePointer.clear();
|
||||||
|
|
||||||
this.mouseMove.x = 0;
|
this.mouseMove.x = 0;
|
||||||
this.mouseMove.y = 0;
|
this.mouseMove.y = 0;
|
||||||
|
|
||||||
// Draw start canvas only if should lock
|
// Draw start canvas only if should lock
|
||||||
if (this.shouldLock)
|
if (this.startCanvas) {
|
||||||
this.startCanvas.render();
|
if (this.shouldLock)
|
||||||
else
|
this.startCanvas.render();
|
||||||
this.startCanvas.clear();
|
else
|
||||||
|
this.startCanvas.clear();
|
||||||
|
}
|
||||||
|
|
||||||
event.locked = false;
|
event.locked = false;
|
||||||
|
|
||||||
|
@ -275,14 +278,14 @@ L3D.PointerCamera.prototype.onPointerLockChange = function() {
|
||||||
* @param {Number} time number of milliseconds between the previous and the next frame
|
* @param {Number} time number of milliseconds between the previous and the next frame
|
||||||
*/
|
*/
|
||||||
L3D.PointerCamera.prototype.update = function(time) {
|
L3D.PointerCamera.prototype.update = function(time) {
|
||||||
this.shouldLogCameraAngles = false;
|
|
||||||
|
|
||||||
if (this.moving) {
|
if (this.moving) {
|
||||||
|
this.shouldLogCameraAngles = false;
|
||||||
this.linearMotion(time);
|
this.linearMotion(time);
|
||||||
} else if (this.movingHermite) {
|
} else if (this.movingHermite) {
|
||||||
|
this.shouldLogCameraAngles = false;
|
||||||
this.hermiteMotion(time);
|
this.hermiteMotion(time);
|
||||||
} else {
|
} else {
|
||||||
this.shouldLogCameraAngles = true;
|
|
||||||
this.normalMotion(time);
|
this.normalMotion(time);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -94,6 +94,7 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
|
||||||
// Finished
|
// Finished
|
||||||
if (this.counter >= this.path.length) {
|
if (this.counter >= this.path.length) {
|
||||||
this.started = false;
|
this.started = false;
|
||||||
|
console.log('The replay is finished');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,20 +72,28 @@ L3D.resetPeachElements = function() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
L3D.initPeach = function(recommendation, scene, coins, clickable) {
|
L3D.initPeach = function(camera, scene, coins, clickable, coin_ids) {
|
||||||
L3D.addLight(scene);
|
L3D.addLight(scene);
|
||||||
|
|
||||||
var collidableObjects = [];
|
var collidableObjects = [];
|
||||||
L3D.initPeachCastle(scene, collidableObjects, recommendation, clickable);
|
L3D.initPeachCastle(scene, collidableObjects, camera, clickable);
|
||||||
|
|
||||||
recommendation.resetElements = L3D.resetPeachElements();
|
camera.resetElements = L3D.resetPeachElements();
|
||||||
recommendation.collidableObjects = collidableObjects;
|
camera.collidableObjects = collidableObjects;
|
||||||
|
|
||||||
recommendation.speed = 0.001;
|
camera.speed = 0.001;
|
||||||
recommendation.reset();
|
camera.reset();
|
||||||
recommendation.save();
|
camera.save();
|
||||||
|
|
||||||
scene.add(recommendation);
|
scene.add(camera);
|
||||||
|
|
||||||
|
var tmp = L3D.generateCoins(L3D.createPeachCoins(), coin_ids);
|
||||||
|
|
||||||
|
for (var i in tmp) {
|
||||||
|
coins.push(tmp[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); });}, 1000);
|
||||||
|
|
||||||
Coin.init(0.001);
|
Coin.init(0.001);
|
||||||
var recommendations = [];
|
var recommendations = [];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
L3D.ObjectClicker = (function() {
|
L3D.ObjectClicker = (function() {
|
||||||
|
|
||||||
function pointerCheck(camera) {
|
function pointerCheck(camera) {
|
||||||
return (camera instanceof L3D.PointerCamera && camera.pointerLocked);
|
return ((camera instanceof L3D.PointerCamera || camera instanceof TutoCamera) && camera.pointerLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue