Added coins and changed scene

This commit is contained in:
Thomas FORGIONE
2015-05-11 12:04:37 +02:00
parent b1cf8afaaf
commit 687b84f438
7 changed files with 569 additions and 39 deletions

View File

@@ -94,7 +94,7 @@ PointerCamera.prototype.hermiteMotion = function() {
this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t));
this.t += 0.005;
this.t += 0.01;
if (this.t > 1) {
this.movingHermite = false;
@@ -155,8 +155,15 @@ PointerCamera.prototype.normalMotion = function() {
}
PointerCamera.prototype.reset = function() {
this.position.copy(new THREE.Vector3(-8.849933489419644, 9.050627639459208, 0.6192960680432451));
this.target.copy(new THREE.Vector3(17.945323228767702, -15.156828589982375, -16.585740412769756));
this.resetBobomb();
// this.position.copy(new THREE.Vector3(-8.849933489419644, 9.050627639459208, 0.6192960680432451));
// this.target.copy(new THREE.Vector3(17.945323228767702, -15.156828589982375, -16.585740412769756));
// this.anglesFromVectors();
}
PointerCamera.prototype.resetBobomb = function() {
this.position.copy(new THREE.Vector3(34.51854618261728,10.038879540840306,-21.772598201888613));
this.target.copy(new THREE.Vector3(-2.593404107644737,8.039712770013185,-6.983870133675925));
this.anglesFromVectors();
}
@@ -238,7 +245,7 @@ PointerCamera.prototype.isColliding = function(direction) {
var intersects = this.raycaster.intersectObjects(this.collidableObjects, true);
for (var i in intersects) {
if (intersects[i].distance < 0.1) {
if (intersects[i].distance < 100*this.speed) {
return true;
}
}

View File

@@ -27,7 +27,7 @@ var ArrowCamera = function(arg1, arg2, arg3, arg4, position, target) {
this.target.add(Tools.mul(direction,20));
this.arrow = new THREE.Mesh(new THREE.Geometry(), new THREE.MeshLambertMaterial({color: 0xff0000, side:THREE.BackSide}));
this.arrow = new THREE.Mesh(new THREE.Geometry(), new THREE.MeshLambertMaterial({color: 0x00ff00, side:THREE.BackSide}));
this.object3D = new THREE.Object3D();
this.object3D.add(this.initExtremity());
@@ -72,7 +72,7 @@ ArrowCamera.prototype.initExtremity = function() {
geometry.computeFaceNormals();
var material = new THREE.MeshLambertMaterial({
color : 0xff0000,
color : 0x00ff00,
transparent : true,
opacity : 0.5,
side: THREE.FrontSide

58
static/js/prototype/Coin.js vendored Normal file
View File

@@ -0,0 +1,58 @@
var Coin = function(x,y,z) {
if (Coin.BASIC_MESH !== null) {
this.mesh = Coin.BASIC_MESH.clone();
this.mesh.position.x = x;
this.mesh.position.y = y;
this.mesh.position.z = z;
} else {
(function(self) {
setTimeout(function() {
self.mesh = Coin.BASIC_MESH.clone();
self.mesh.position.x = x;
self.mesh.position.y = y;
self.mesh.position.z = z;
},1000);
})(this);
}
}
Coin.prototype.init = function(x,y,z) {
if (Coin.BASIC_MESH !== null) {
this.mesh = Coin.BASIC_MESH.clone();
this.mesh.position.x = x;
this.mesh.position.y = y;
this.mesh.position.z = z;
} else {
(function(self,x,y,z) {
setTimeout(function() {
self.init(x,y,z);
},1000);
})(this,x,y,z);
}
}
Coin.prototype.addToScene = function(scene) {
scene.add(this.mesh);
}
Coin.prototype.update = function() {
this.mesh.rotation.y += 0.1;
}
Coin.BASIC_MESH = null;
Coin._loader = new THREE.OBJLoader();
Coin._loader.load(
static_path + 'data/coin/Coin.obj',
function(object) {
object.traverse(function (mesh) {
if (mesh instanceof THREE.Mesh) {
mesh.scale.set(0.005,0.005,0.005);
mesh.material.color.setHex(0xff0000);
mesh.geometry.computeVertexNormals();
mesh.raycastable = true;
Coin.BASIC_MESH = mesh
}
});
}
);

View File

@@ -61,6 +61,7 @@ function initPeachCastle(scene, collidableObjects, loader, static_path) {
});
}
);
}
@@ -111,7 +112,7 @@ function createPeachCameras(width, height) {
return cams;
}
function initBobombScene(scene, loader, static_path) {
function initBobombScene(scene, collidableObjects, loader, static_path) {
// Create loader if not already done
if (loader === undefined) {
loader = new THREE.OBJMTLLoader();
@@ -139,7 +140,6 @@ function initBobombScene(scene, loader, static_path) {
object.traverse(function (object) {
if (object instanceof THREE.Mesh) {
object.material.side = THREE.DoubleSide;
console.log(object.geometry.vertices.length);
object.geometry.mergeVertices();
object.geometry.computeVertexNormals();
if (object.material.name === 'Material.071_574B138E_c.bmp' ||
@@ -152,36 +152,51 @@ function initBobombScene(scene, loader, static_path) {
}
);
loader.load(
static_path + 'data/star/GrandStar.obj',
static_path + 'data/star/GrandStar.mtl',
function ( object ) {
object.position.z -= 10.9;
object.position.y += 0.555;
object.position.x += 3.23;
// loader.load(
// static_path + 'data/star/GrandStar.obj',
// static_path + 'data/star/GrandStar.mtl',
// function ( object ) {
// object.position.z -= 10.9;
// object.position.y += 0.555;
// object.position.x += 3.23;
var theta = 0.27;
object.rotation.y = Math.PI - theta;
// var theta = 0.27;
// object.rotation.y = Math.PI - theta;
object.up = new THREE.Vector3(0,0,1);
scene.add(object);
collidableObjects.push(object);
object.traverse(function (object) {
if (object instanceof THREE.Mesh) {
object.scale.set(0.005,0.005,0.005);
object.position.x = 13;
object.position.z = -35;
object.position.y = 30;
// object.up = new THREE.Vector3(0,0,1);
// scene.add(object);
// collidableObjects.push(object);
// object.traverse(function (object) {
// if (object instanceof THREE.Mesh) {
// object.scale.set(0.005,0.005,0.005);
// object.position.x = 13;
// object.position.z = -35;
// object.position.y = 30;
object.rotation.z = Math.PI/2;
object.rotation.x = Math.PI/2;
object.rotation.y = Math.PI;
object.material.side = THREE.DoubleSide;
object.geometry.mergeVertices();
object.geometry.computeVertexNormals();
object.raycastable = true;
}
});
}
);
// object.rotation.z = Math.PI/2;
// object.rotation.x = Math.PI/2;
// object.rotation.y = Math.PI;
// object.material.side = THREE.DoubleSide;
// object.geometry.mergeVertices();
// object.geometry.computeVertexNormals();
// object.raycastable = true;
// }
// });
// }
//);
}
function createBobombCoins() {
var coins = [];
coins.push(
new Coin(30.451451579494677,12.95882671478358,-4.441244895059621),
new Coin(-23.255456493345882,15.763954882327724,-11.08029248078497),
new Coin(-7.238094745133173,12.95460420281499,-3.1009487490121885),
new Coin(-17.10578612221326,24.17871082944758,-11.574224169812915),
new Coin(-19.696802461559027,29.787916906980758,17.187300848990844),
new Coin(-12.418656949661646,17.09780294217035,32.472022253887665)
);
return coins;
}

View File

@@ -10,6 +10,7 @@ var stats;
var previewer;
var loader;
var coins;
var main_section = document.getElementById('main-section');
var offset = function() {
@@ -80,7 +81,7 @@ function init() {
// Initialize pointer camera
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, container);
camera1.speed = 0.001;
camera1.reset();
camera1.resetBobomb();
camera1.save();
scene.add(camera1);
@@ -97,7 +98,11 @@ function init() {
var loader = new THREE.OBJMTLLoader();
// Load scene
initPeachCastle(scene, collidableObjects, loader, static_path);
// initPeachCastle(scene, collidableObjects, loader, static_path);
initBobombScene(scene, collidableObjects, loader, static_path);
coins = createBobombCoins();
setTimeout(function() {coins.forEach(function(coin) { coin.addToScene(scene);})}, 1000);
// Add listeners
initListeners();
@@ -194,6 +199,9 @@ function render() {
}
});
// Update coins
coins.forEach(function(coin) { coin.update(); });
// Update main camera
cameras.updateMainCamera();