A lot of cleaning... jshint likes me now !

This commit is contained in:
Thomas FORGIONE
2015-07-01 10:14:15 +02:00
parent 0af40f3484
commit fab183eaa7
68 changed files with 544 additions and 505 deletions

View File

@@ -37,7 +37,7 @@ var ArrowCamera = function(arg1, arg2, arg3, arg4, position, target) {
this.fullArrow = false;
}
};
ArrowCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
ArrowCamera.prototype.constructor = ArrowCamera;
@@ -46,7 +46,7 @@ ArrowCamera.prototype.check = function() {
if (obj instanceof THREE.Mesh)
obj.material.color.setHex(0x663366);
});
}
};
ArrowCamera.prototype.initExtremity = function() {
var geometry = new THREE.Geometry();
@@ -90,7 +90,7 @@ ArrowCamera.prototype.initExtremity = function() {
this.mesh = new THREE.Mesh(geometry, material);
return this.mesh;
}
};
ArrowCamera.prototype.updateExtremity = function() {
var direction = this.target.clone();
@@ -116,12 +116,12 @@ ArrowCamera.prototype.updateExtremity = function() {
this.mesh.geometry.computeFaceNormals();
this.mesh.geometry.verticesNeedUpdate = true;
}
};
ArrowCamera.prototype.setSize = function(size) {
this.size = size;
this.updateExtremity();
}
};
// Update function
ArrowCamera.prototype.update = function(mainCamera) {
@@ -154,10 +154,11 @@ ArrowCamera.prototype.update = function(mainCamera) {
});
this.regenerateArrow(mainCamera);
}
};
ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
var vertices = new Array();
var i;
var vertices = [];
// First point of curve
var f0 = mainCamera.position.clone();
@@ -202,7 +203,7 @@ ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
var limit = this.fullArrow ? 0.1 : 0.3;
// for (var i = this.fullArrow ? 0 : 0.5; i <= 1.001; i += 0.05) {
for (var i = 1; i > limit; i -= 0.1) {
for (i = 1; i > limit; i -= 0.1) {
point = hermite.eval(i);
deriv = hermite.prime(i);
up.cross(deriv);
@@ -224,10 +225,10 @@ ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
this.arrow.geometry.vertices = vertices;
if (this.arrow.geometry.faces.length == 0) {
var faces = new Array();
if (this.arrow.geometry.faces.length === 0) {
var faces = [];
for (var i = 0; i < vertices.length - 4; i+= 4) {
for (i = 0; i < vertices.length - 4; i+= 4) {
faces.push(new THREE.Face3(i,i+1,i+5),new THREE.Face3(i,i+5,i+4),
new THREE.Face3(i+1,i+2,i+6),new THREE.Face3(i+1,i+6,i+5),
new THREE.Face3(i+2,i+3,i+7),new THREE.Face3(i+2,i+7,i+6),
@@ -262,22 +263,22 @@ ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
this.arrow.geometry.groupsNeedUpdate = true;
this.arrow.geometry.normalsNeedUpdate = true;
}
};
// Look function
ArrowCamera.prototype.look = function() {
this.lookAt(this.target);
}
};
ArrowCamera.prototype.addToScene = function(scene) {
scene.add(this);
scene.add(this.object3D);
}
};
ArrowCamera.prototype.traverse = function(callback) {
this.object3D.traverse(callback);
}
};
ArrowCamera.prototype.containsObject = function(object) {
return object.parent === this.object3D;
}
};

View File

@@ -19,8 +19,8 @@ var ButtonManager = function(cameras, previewer) {
this.fullscreenElement.onclick = function() {fullscreen();};
(function(self) {
self.undoElement.onclick = function() {self.cameras.mainCamera().undo(); self.updateElements();}
self.redoElement.onclick = function() {self.cameras.mainCamera().redo(); self.updateElements();}
self.undoElement.onclick = function() {self.cameras.mainCamera().undo(); self.updateElements();};
self.redoElement.onclick = function() {self.cameras.mainCamera().redo(); self.updateElements();};
self.fullElement.onclick = function() {
self.cameras.map(function(camera) {
@@ -34,21 +34,21 @@ var ButtonManager = function(cameras, previewer) {
self.pointerLockElement.onchange = function() {
self.cameras.mainCamera().shouldLock = self.pointerLockElement.checked;
self.cameras.mainCamera().onPointerLockChange();
}
};
self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;}
self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;};
self.resetElement.onclick = function() {
// Reinit camera
self.cameras.mainCamera().reset();
}
};
self.recommendationElement.onchange = function() {
previewer.fixedRecommendation(self.recommendationElement.checked);
}
};
})(this);
}
};
ButtonManager.prototype.updateElements = function() {
// Update icon
@@ -63,5 +63,5 @@ ButtonManager.prototype.updateElements = function() {
} else {
this.redoElement.className = "btn btn-primary navbar-btn";
}
}
};

20
js/prototype/Coin.js vendored
View File

@@ -6,7 +6,7 @@ var Coin = function(x,y,z, callback) {
this.callback = callback;
this.rotating = true;
}
}
};
var _toto = new Audio();
Coin.extension = _toto.canPlayType("audio/x-vorbis") === "" ? ".ogg" : ".mp3";
@@ -28,7 +28,7 @@ Coin.initSize = function() {
setTimeout(100, Coin.initSize);
return;
}
}
};
Coin.update = function() {
@@ -56,7 +56,7 @@ Coin.update = function() {
Coin.ctx.stroke();
Coin.ctx.fill();
}
};
Coin.image.onload = Coin.update;
@@ -79,17 +79,17 @@ Coin.prototype.init = function(x,y,z) {
},1000);
})(this,x,y,z);
}
}
};
Coin.prototype.addToScene = function(scene) {
scene.add(this.mesh);
}
};
Coin.prototype.update = function() {
var self = this;
if (this.ready && this.rotating)
this.mesh.rotation.y += 0.1
}
this.mesh.rotation.y += 0.1;
};
Coin.prototype.get = function() {
if (!this.got) {
@@ -127,7 +127,7 @@ Coin.prototype.get = function() {
Coin.update();
}
}
};
Coin.lastSound = new Audio('/static/data/music/starappears' + Coin.extension);
Coin.lastSound.preload = "auto";
@@ -155,7 +155,7 @@ Coin.init = function(scale) {
mesh.material.color.setHex(0xff0000);
mesh.geometry.computeVertexNormals();
mesh.raycastable = true;
Coin.BASIC_MESH = mesh
Coin.BASIC_MESH = mesh;
}
});
}
@@ -163,4 +163,4 @@ Coin.init = function(scale) {
Coin.nextSound = new Audio('/static/data/music/redcoins/1' + Coin.extension);
}
}
};

View File

@@ -3,7 +3,7 @@
// class camera extends THREE.PerspectiveCamera
var FixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
ArrowCamera.apply(this, arguments);
}
};
FixedCamera.prototype = Object.create(ArrowCamera.prototype);
FixedCamera.prototype.constructor = FixedCamera;

View File

@@ -50,8 +50,8 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
(function(self, direction, left, other) {
var material = new THREE.LineBasicMaterial({ color: '0x000000'});
var geometry = new THREE.Geometry();
var direction = Tools.mul(direction, -2);
var target = Tools.sum(self.position, direction);
var tmp_direction = Tools.mul(direction, -2);
var target = Tools.sum(self.position, tmp_direction);
// geometry.vertices.push(self.position, target);
geometry.vertices.push(
Tools.sum(Tools.sum(self.position, left), other),
@@ -61,16 +61,16 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
Tools.sum(Tools.sum(self.position, left), other),
Tools.sum(Tools.diff(self.position, other), left),
Tools.sum(self.position, direction),
Tools.sum(self.position, tmp_direction),
Tools.sum(Tools.sum(self.position, left), other),
Tools.sum(self.position, direction),
Tools.sum(self.position, tmp_direction),
Tools.diff(Tools.sum(self.position, other),left),
Tools.sum(self.position, direction),
Tools.sum(self.position, tmp_direction),
Tools.diff(Tools.diff(self.position, left),other),
Tools.sum(self.position, direction),
Tools.sum(self.position, tmp_direction),
Tools.sum(Tools.diff(self.position, other), left)
);
@@ -87,13 +87,13 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
this.mesh = new THREE.Mesh(geometry, material);
this.mesh.raycastable = true;
}
};
OldFixedCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
OldFixedCamera.prototype.constructor = OldFixedCamera;
OldFixedCamera.prototype.check = function() {
this.mesh.material.color.setHex(0x663366);
}
};
// Update function
OldFixedCamera.prototype.update = function(position) {
@@ -117,25 +117,25 @@ OldFixedCamera.prototype.update = function(position) {
if (new_value < 0.1)
this.mesh.material.transparent = this.mesh.visible = false;
}
};
// Look function
OldFixedCamera.prototype.look = function() {
this.lookAt(this.target);
}
};
OldFixedCamera.prototype.addToScene = function(scene) {
scene.add(this);
scene.add(this.mesh);
scene.add(this.line);
}
};
OldFixedCamera.prototype.traverse = function(callback) {
callback(this.mesh);
callback(this.line);
}
};
OldFixedCamera.prototype.containsObject = function(object) {
return object === this.mesh;
}
};

View File

@@ -1,6 +1,6 @@
Math.clamp = Math.clamp || function(number, min, max) {
return Math.max(Math.min(number, max), min);
}
};
var Previewer = function(renderer, scene) {
this.domElement = document.createElement('canvas');
@@ -10,7 +10,7 @@ var Previewer = function(renderer, scene) {
this.scene = scene;
this.drawn = false;
this.drawnBefore = false;
}
};
Previewer.prototype.render = function(prev, container_width, container_height) {
var width, height, left, bottom;
@@ -77,20 +77,20 @@ Previewer.prototype.render = function(prev, container_width, container_height) {
this.clearNeeded = true;
}
}
};
Previewer.prototype.clear = function() {
if (this.clearNeeded) {
this.domElement.width = this.domElement.width;
this.clearNeeded = false;
}
}
};
Previewer.prototype.fixedRecommendation = function(bool) {
this.fixed = bool;
}
};
Previewer.prototype.update = function(arg) {
this.drawnBefore = this.drawn;
this.drawn = arg;
}
};

View File

@@ -2,7 +2,7 @@
var ReplayCamera = function() {
THREE.PerspectiveCamera.apply(this, arguments);
this.coins = arguments[4]
this.coins = arguments[4];
this.started = false;
this.counter = 0;
@@ -17,15 +17,14 @@ var ReplayCamera = function() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/prototype/replay_info/" + id, true);
(function(self) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
self.path = JSON.parse(xhr.responseText);
self.started = true;
self.nextEvent();
}
var self = this;
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
self.path = JSON.parse(xhr.responseText);
self.started = true;
self.nextEvent();
}
})(this);
};
xhr.send();
// Set Position
@@ -34,13 +33,13 @@ var ReplayCamera = function() {
this.resetElements = resetBobombElements();
}
};
ReplayCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
ReplayCamera.prototype.constructor = ReplayCamera;
ReplayCamera.prototype.look = function() {
this.lookAt(this.target);
}
};
// Update function
ReplayCamera.prototype.update = function(time) {
@@ -58,7 +57,7 @@ ReplayCamera.prototype.update = function(time) {
// // Nothing to do
// }
}
}
};
ReplayCamera.prototype.linearMotion = function(time) {
var tmp = Tools.sum(Tools.mul(this.old_position, 1-this.t), Tools.mul(this.new_position, this.t));
@@ -70,7 +69,7 @@ ReplayCamera.prototype.linearMotion = function(time) {
if (this.t > 1) {
this.nextEvent();
}
}
};
ReplayCamera.prototype.cameraMotion = function(time) {
@@ -84,13 +83,13 @@ ReplayCamera.prototype.cameraMotion = function(time) {
if (this.t > 1) {
this.nextEvent();
}
}
};
ReplayCamera.prototype.hermiteMotion = function(time) {
var eval = this.hermitePosition.eval(this.t);
this.position.x = eval.x;
this.position.y = eval.y;
this.position.z = eval.z;
var e = this.hermitePosition.eval(this.t);
this.position.x = e.x;
this.position.y = e.y;
this.position.z = e.z;
this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t));
@@ -99,7 +98,7 @@ ReplayCamera.prototype.hermiteMotion = function(time) {
if (this.t > 1) {
this.nextEvent();
}
}
};
ReplayCamera.prototype.nextEvent = function() {
this.counter++;
@@ -136,19 +135,19 @@ ReplayCamera.prototype.nextEvent = function() {
} else if (this.event.type == 'hovered') {
this.nextEvent();
}
}
};
ReplayCamera.prototype.reset = function() {
this.resetPosition();
this.moving = false;
this.movingHermite = false;
}
};
ReplayCamera.prototype.resetPosition = function() {
this.position.copy(this.resetElements.position);
this.target.copy(this.resetElements.target);
this.anglesFromVectors();
}
};
ReplayCamera.prototype.vectorsFromAngles = function() {
// Update direction
@@ -159,7 +158,7 @@ ReplayCamera.prototype.vectorsFromAngles = function() {
this.forward.x = cos * Math.sin(this.theta);
this.forward.normalize();
}
};
ReplayCamera.prototype.anglesFromVectors = function() {
// Update phi and theta so that return to reality does not hurt
@@ -171,7 +170,7 @@ ReplayCamera.prototype.anglesFromVectors = function() {
// Don't know why this line works... But thanks Thierry-san and
// Bastien because it seems to work...
this.theta = Math.atan2(forward.x, forward.z);
}
};
ReplayCamera.prototype.move = function(otherCamera) {
this.moving = true;
@@ -181,7 +180,7 @@ ReplayCamera.prototype.move = function(otherCamera) {
this.new_position = new THREE.Vector3(otherCamera.position.x, otherCamera.position.y, otherCamera.position.z);
this.t = 0;
}
};
ReplayCamera.prototype.moveHermite = function(otherCamera) {
this.movingHermite = true;
@@ -198,6 +197,6 @@ ReplayCamera.prototype.moveHermite = function(otherCamera) {
Tools.diff(otherCamera.target, otherCamera.position),
new THREE.Vector3()
);
}
};
ReplayCamera.prototype.save = function() {}
ReplayCamera.prototype.save = function() {};

View File

@@ -3,7 +3,7 @@
// class camera extends THREE.PerspectiveCamera
var ReverseCamera = function(arg1, arg2, arg3, arg4, position, target) {
ArrowCamera.apply(this, arguments);
}
};
ReverseCamera.prototype = Object.create(ArrowCamera.prototype);
ReverseCamera.prototype.constructor = ReverseCamera;
@@ -23,7 +23,7 @@ ReverseCamera.prototype.initExtremity = function() {
left = Tools.mul(left, this.size / 2 );
other = Tools.mul(other, this.size / 2);
var pyramidCenter = Tools.diff(this.position, Tools.mul(direction,0.25))
var pyramidCenter = Tools.diff(this.position, Tools.mul(direction,0.25));
geometry.vertices.push(
Tools.sum( Tools.sum( this.position, left), other),
Tools.diff(Tools.sum( this.position, other), left),
@@ -71,10 +71,11 @@ ReverseCamera.prototype.initExtremity = function() {
this.mesh = new THREE.Mesh(geometry, material);
return this.mesh;
}
};
ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
var vertices = new Array();
var i;
var vertices = [];
// First point of curve
var f0 = mainCamera.position.clone();
@@ -119,7 +120,7 @@ ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
var limit = this.fullArrow ? 0.1 : 0.3;
// for (var i = this.fullArrow ? 0 : 0.5; i <= 1.001; i += 0.05) {
for (var i = 1; i > limit; i -= 0.1) {
for (i = 1; i > limit; i -= 0.1) {
point = hermite.eval(i);
deriv = hermite.prime(i);
up.cross(deriv);
@@ -141,10 +142,10 @@ ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
this.arrow.geometry.vertices = vertices;
if (this.arrow.geometry.faces.length == 0) {
var faces = new Array();
if (this.arrow.geometry.faces.length === 0) {
var faces = [];
for (var i = 0; i < vertices.length - 4; i+= 4) {
for (i = 0; i < vertices.length - 4; i+= 4) {
faces.push(new THREE.Face3(i,i+1,i+5),new THREE.Face3(i,i+5,i+4),
new THREE.Face3(i+1,i+2,i+6),new THREE.Face3(i+1,i+6,i+5),
new THREE.Face3(i+2,i+3,i+7),new THREE.Face3(i+2,i+7,i+6),
@@ -155,7 +156,7 @@ ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
faces.push(new THREE.Face3(len-4,len-3,len-2), new THREE.Face3(len-4,len-2,len-1));
var max = 0;
for (var i = 0; i < faces.length; i++) {
for (i = 0; i < faces.length; i++) {
max = Math.max(max, faces[i].a, faces[i].b, faces[i].c);
}
console.log(max + '/' + len);
@@ -179,4 +180,4 @@ ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
this.arrow.geometry.groupsNeedUpdate = true;
this.arrow.geometry.normalsNeedUpdate = true;
}
};

View File

@@ -97,11 +97,11 @@ var TutorialSteps = function(tutoCamera, scene, coins, onWindowResize, container
this.scene = scene;
Coin.domElement.style.display = "none";
}
};
TutorialSteps.prototype.setCameras = function(cameras) {
this.cameras = cameras;
}
};
TutorialSteps.prototype.nextStep = function() {
console.log(this.step);
@@ -175,7 +175,7 @@ TutorialSteps.prototype.nextStep = function() {
}
this.step++;
}
}
};
TutorialSteps.prototype.nextAction = function() {
switch (this.step) {
@@ -188,18 +188,18 @@ TutorialSteps.prototype.nextAction = function() {
case 13: return 'reset-camera';
case 15: return 'recommendation';
}
}
};
TutorialSteps.prototype.tryFinish = function() {
if (this.coinNumber === 8) {
console.log("Finished");
}
}
};
TutorialSteps.prototype.alert = function(myString, justclicked) {
this.notify(myString, justclicked);
this.onWindowResize();
}
};
TutorialSteps.prototype.notify = function(myString, justclick) {
$('#alert-placeholder').html(
@@ -215,11 +215,11 @@ TutorialSteps.prototype.notify = function(myString, justclick) {
' <a href="#" onclick="setTimeout(onWindowResize, 100); nextStep();"><em>(next)</em></span>' : '' ) +
'</strong></span>' +
'</div>'
)
);
$('#toto').removeClass('alert-info').addClass('alert-danger');
setTimeout(function() {
$('#toto').removeClass('alert-danger').addClass('alert-warning');
}, 500);
}
};

View File

@@ -11,7 +11,7 @@ function addLight(scene) {
scene.add(ambient_light);
}
function initPeachCastle(scene, collidableObjects, loader, camera) {
function initPeachCastle(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry(
'/static/data/castle/princess peaches castle (outside).obj',
@@ -45,10 +45,9 @@ function resetPeachElements() {
function initPeach(camera, scene, coins) {
addLight(scene);
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initPeachCastle(scene, collidableObjects, loader, camera);
initPeachCastle(scene, collidableObjects, camera);
camera.resetElements = resetPeachElements();
camera.collidableObjects = collidableObjects;
@@ -107,7 +106,7 @@ function createPeachCameras(width, height) {
position,
target
);
}
};
cams.push(createCamera(
new THREE.Vector3(-3.349895207953063, 5.148106346852601, 0.3365943929701533),
@@ -155,7 +154,7 @@ function createPeachCameras(width, height) {
return cams;
}
function initBobombScene(scene, collidableObjects, loader, camera) {
function initBobombScene(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry(
'/static/data/bobomb/bobomb battlefeild.obj',
@@ -215,7 +214,7 @@ function createBobombCameras(width, height) {
position,
target
);
}
};
cams.push(
createCamera(
@@ -270,10 +269,9 @@ function createBobombCameras(width, height) {
function initBobomb(camera, scene, coins) {
addLight(scene);
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initBobombScene(scene, collidableObjects, loader, camera);
initBobombScene(scene, collidableObjects, camera);
camera.resetElements = resetBobombElements();
camera.collidableObjects = collidableObjects;
@@ -296,12 +294,12 @@ function initBobomb(camera, scene, coins) {
otherCams.forEach(function(cam) {cam.addToScene(scene);});
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000);
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); });}, 1000);
return cameras;
}
function initWhompScene(scene, collidableObjects, loader, camera) {
function initWhompScene(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry(
'/static/data/whomp/Whomps Fortress.obj',
@@ -331,25 +329,25 @@ function initWhompScene(scene, collidableObjects, loader, camera) {
loader.obj.rotation.z = Math.PI/2;
loader.obj.scale.set(0.1,0.1,0.1);
loader.getCamera = function() {
var ret = loader.camera.toList();
ret[0][0] *= 10;
ret[0][1] *= 10;
ret[0][2] *= 10;
// loader.getCamera = function() {
// var ret = loader.camera.toList();
// ret[0][0] *= 10;
// ret[0][1] *= 10;
// ret[0][2] *= 10;
ret[1][0] *= 10;
ret[1][1] *= 10;
ret[1][2] *= 10;
// ret[1][0] *= 10;
// ret[1][1] *= 10;
// ret[1][2] *= 10;
// Planes
for (var i = 2; i < ret.length; i++) {
// // Planes
// for (var i = 2; i < ret.length; i++) {
ret[i][3] *= 10;
// ret[i][3] *= 10;
}
// }
return ret;
}
// return ret;
// };
collidableObjects.push(loader.obj);
loader.obj.raycastable = true;
@@ -367,7 +365,7 @@ function createWhompCameras(width, height) {
position,
target
);
}
};
cams.push(
createCamera(
@@ -443,10 +441,9 @@ function resetWhompElements() {
function initWhomp(camera, scene, coins) {
addLight(scene);
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initWhompScene(scene, collidableObjects, loader, camera);
initWhompScene(scene, collidableObjects, camera);
camera.resetElements = resetWhompElements();
camera.collidableObjects = collidableObjects;
@@ -469,12 +466,12 @@ function initWhomp(camera, scene, coins) {
otherCams.forEach(function(cam) {cam.addToScene(scene);});
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000);
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); });}, 1000);
return cameras;
}
function initMountainScene(scene, collidableObjects, loader, camera) {
function initMountainScene(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry(
'/static/data/mountain/coocoolmountain.obj',
@@ -531,7 +528,7 @@ function createMountainCameras(width, height) {
position,
target
);
}
};
cams.push(
createCamera(
@@ -591,15 +588,14 @@ function resetMountainElements() {
return {
position : new THREE.Vector3(-20.558328115300082,23.601312087942762,-10.220633604814038),
target : new THREE.Vector3(11.025356711105232,11.969889531789319,11.393733425161644)
}
};
}
function initMountain(camera, scene, coins) {
addLight(scene);
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initMountainScene(scene, collidableObjects, loader, camera);
initMountainScene(scene, collidableObjects, camera);
camera.resetElements = resetMountainElements();
camera.collidableObjects = collidableObjects;
@@ -622,11 +618,11 @@ function initMountain(camera, scene, coins) {
otherCams.forEach(function(cam) {cam.addToScene(scene);});
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000);
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); });}, 1000);
return cameras;
}
function initSponzaScene(scene, collidableObjects, loader, camera) {
function initSponzaScene(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry('/static/data/sponza/sponza.obj', scene, camera, function(obj) {
if (obj.material.name === 'chain' ||
@@ -663,7 +659,7 @@ function initSponzaScene(scene, collidableObjects, loader, camera) {
}
return ret;
}
};
loader.obj.scale.set(0.1,0.1,0.1);
collidableObjects.push(loader.obj);
@@ -707,10 +703,9 @@ function resetSponzaElements() {
function initSponza(camera, scene, coins) {
addLight(scene);
var loader = new THREE.JSONLoader();
var collidableObjects = [];
initSponzaScene(scene, collidableObjects, loader, camera);
initSponzaScene(scene, collidableObjects, camera);
camera.resetElements = resetSponzaElements();
camera.collidableObjects = collidableObjects;
@@ -733,7 +728,7 @@ function initSponza(camera, scene, coins) {
otherCams.forEach(function(cam) {cam.addToScene(scene);});
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000);
setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); });}, 1000);
return cameras;

View File

@@ -7,7 +7,7 @@ var CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
this.buttonManager = buttonManager;
this.scene = scene;
this.coins = coins;
}
};
CameraSelecter.prototype.pointedCamera = function() {
var returnCamera;
@@ -64,12 +64,14 @@ CameraSelecter.prototype.pointedCamera = function() {
}
}
this.currentPointedCamera = null;
}
};
CameraSelecter.prototype.update = function(event, y) {
var e;
if (event !== undefined) {
this.mouse.x = event.offsetX == undefined ? event.layerX : event.offsetX;
this.mouse.y = event.offsetY == undefined ? event.layerY : event.offsetY;
this.mouse.x = event.offsetX === undefined ? event.layerX : event.offsetX;
this.mouse.y = event.offsetY === undefined ? event.layerY : event.offsetY;
}
if (y !== undefined) {
@@ -83,10 +85,10 @@ CameraSelecter.prototype.update = function(event, y) {
if (hovered !== undefined && !(hovered instanceof Coin)) {
if (hovered !== previousCamera) {
// log it
var event = new BD.Event.Hovered();
event.start = true;
event.arrow_id = this.cameras.cameras.indexOf(this.currentPointedCamera);
event.send();
e = new BD.Event.Hovered();
e.start = true;
e.arrow_id = this.cameras.cameras.indexOf(this.currentPointedCamera);
e.send();
this.prev.x = this.mouse.x;
this.prev.y = this.mouse.y;
@@ -96,10 +98,10 @@ CameraSelecter.prototype.update = function(event, y) {
} else {
if (this.prev.go) {
// Log if previous was not null
var event = new BD.Event.Hovered();
event.start = false;
event.arrow_id = null;
event.send();
e = new BD.Event.Hovered();
e.start = false;
e.arrow_id = null;
e.send();
}
this.prev.go = false;
}
@@ -109,44 +111,59 @@ CameraSelecter.prototype.update = function(event, y) {
if (this.cameras.mainCamera().pointerLocked)
this.cameras.mainCamera().mousePointer.render(hovered ? MousePointer.RED : MousePointer.BLACK);
}
};
CameraSelecter.prototype.click = function(event) {
var e;
var newCamera = this.pointedCamera();
if (newCamera !== undefined && !(newCamera instanceof Coin)) {
var event = new BD.Event.ArrowClicked();
event.arrow_id = this.cameras.cameras.indexOf(newCamera);
event.send();
e = new BD.Event.ArrowClicked();
e.arrow_id = this.cameras.cameras.indexOf(newCamera);
e.send();
newCamera.check();
this.cameras.mainCamera().moveHermite(newCamera);
buttonManager.updateElements();
} else if (newCamera instanceof Coin) {
// Coin found, notify server
var event = new BD.Event.CoinClicked();
event.coin_id = this.coins.indexOf(newCamera);
event.send();
e = new BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera);
e.send();
newCamera.get();
}
}
};
CameraSelecter.prototype.clickPointer = function(event) {
var e;
if (this.cameras.mainCamera().pointerLocked) {
var newCamera = this.pointedCamera();
if (newCamera !== undefined && !(newCamera instanceof Coin)) {
var event = new BD.Event.ArrowClicked();
event.arrow_id = this.cameras.cameras.indexOf(newCamera);
event.send();
e = new BD.Event.ArrowClicked();
e.arrow_id = this.cameras.cameras.indexOf(newCamera);
e.send();
newCamera.check();
this.cameras.mainCamera().moveHermite(newCamera);
buttonManager.updateElements();
} else if (newCamera instanceof Coin) {
// Coin found, notify server
var event = new BD.Event.CoinClicked();
event.coin_id = this.coins.indexOf(newCamera);
event.send();
e = new BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera);
e.send();
newCamera.get();
}
}
}
};

View File

@@ -17,7 +17,7 @@ var main_section = document.getElementById('main-section');
var container_size = {
width: function() { return 1024; },
height: function() { return 768; }
}
};
var onWindowResize = (function() {
@@ -48,7 +48,7 @@ function init() {
renderer = new THREE.WebGLRenderer({alpha:true, antialias:true});
// Collidable objects to prevent camera from traversing objects
var collidableObjects = new Array();
var collidableObjects = [];
// Initialize renderer
container = document.getElementById('container');

View File

@@ -39,7 +39,7 @@ function init() {
BD.disable();
// Collidable objects to prevent camera from traversing objects
var collidableObjects = new Array();
var collidableObjects = [];
// Initialize renderer
container = document.getElementById('container');