Added recommendations on Mario scene
This commit is contained in:
@@ -21,8 +21,8 @@ var FixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
|
||||
direction.normalize();
|
||||
|
||||
this.target = this.position.clone();
|
||||
this.target.add(Tools.mul(direction,10));
|
||||
this.up = new THREE.Vector3(0,0,1);
|
||||
this.target.add(Tools.mul(direction,20));
|
||||
// this.up = new THREE.Vector3(0,0,1);
|
||||
|
||||
// Compute corners
|
||||
|
||||
@@ -30,55 +30,66 @@ var FixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
|
||||
var position = this.position.clone();
|
||||
var left = Tools.cross(direction, this.up);
|
||||
var other = Tools.cross(direction, left);
|
||||
|
||||
position.sub(direction);
|
||||
|
||||
left.normalize();
|
||||
other.normalize();
|
||||
left = Tools.mul(left, 100);
|
||||
other = Tools.mul(other, 100);
|
||||
left = Tools.mul(left, 0.2);
|
||||
other = Tools.mul(other, 0.2);
|
||||
|
||||
geometry.vertices.push(Tools.sum(Tools.sum(this.position, left), other),
|
||||
Tools.diff(Tools.sum(this.position, other),left),
|
||||
Tools.diff(Tools.diff(this.position, left),other),
|
||||
Tools.sum(Tools.diff(this.position, other), left)
|
||||
geometry.vertices.push(Tools.sum( Tools.sum( position, left), other),
|
||||
Tools.diff(Tools.sum( position, other), left),
|
||||
Tools.diff(Tools.diff(position, left), other),
|
||||
Tools.sum( Tools.diff(position, other), left),
|
||||
Tools.sum(position, direction)
|
||||
);
|
||||
|
||||
geometry.faces.push(new THREE.Face3(0,1,2), // new THREE.Face3(0,2,1),
|
||||
new THREE.Face3(0,2,3) // new THREE.Face3(0,3,2)
|
||||
new THREE.Face3(0,2,3), // new THREE.Face3(0,3,2)
|
||||
new THREE.Face3(4,1,2),
|
||||
new THREE.Face3(4,0,1),
|
||||
new THREE.Face3(4,3,0),
|
||||
new THREE.Face3(4,2,3)
|
||||
);
|
||||
|
||||
(function(self, direction, left, other) {
|
||||
var material = new THREE.LineBasicMaterial({ color: '0x000000'});
|
||||
geometry.computeFaceNormals();
|
||||
|
||||
(function(self, direction, left, other, position) {
|
||||
var material = new THREE.LineBasicMaterial({ color: '0x000000', transparent: true});
|
||||
var geometry = new THREE.Geometry();
|
||||
var direction = Tools.mul(direction, -200);
|
||||
var target = Tools.sum(self.position, direction);
|
||||
// geometry.vertices.push(self.position, target);
|
||||
// var direction = Tools.mul(direction, 1);
|
||||
var target = Tools.sum(position, direction);
|
||||
// geometry.vertices.push(position, target);
|
||||
geometry.vertices.push(
|
||||
Tools.sum(Tools.sum(self.position, left), other),
|
||||
Tools.diff(Tools.sum(self.position, other),left),
|
||||
Tools.diff(Tools.diff(self.position, left),other),
|
||||
Tools.sum(Tools.diff(self.position, other), left),
|
||||
Tools.sum(Tools.sum(self.position, left), other),
|
||||
Tools.sum(Tools.diff(self.position, other), left),
|
||||
Tools.sum(Tools.sum(position, left), other),
|
||||
Tools.diff(Tools.sum(position, other),left),
|
||||
Tools.diff(Tools.diff(position, left),other),
|
||||
Tools.sum(Tools.diff(position, other), left),
|
||||
Tools.sum(Tools.sum(position, left), other),
|
||||
Tools.sum(Tools.diff(position, other), left),
|
||||
|
||||
Tools.sum(self.position, direction),
|
||||
Tools.sum(Tools.sum(self.position, left), other),
|
||||
Tools.sum(position, direction),
|
||||
Tools.sum(Tools.sum(position, left), other),
|
||||
|
||||
Tools.sum(self.position, direction),
|
||||
Tools.diff(Tools.sum(self.position, other),left),
|
||||
Tools.sum(position, direction),
|
||||
Tools.diff(Tools.sum(position, other),left),
|
||||
|
||||
Tools.sum(self.position, direction),
|
||||
Tools.diff(Tools.diff(self.position, left),other),
|
||||
Tools.sum(position, direction),
|
||||
Tools.diff(Tools.diff(position, left),other),
|
||||
|
||||
Tools.sum(self.position, direction),
|
||||
Tools.sum(Tools.diff(self.position, other), left)
|
||||
Tools.sum(position, direction),
|
||||
Tools.sum(Tools.diff(position, other), left)
|
||||
);
|
||||
|
||||
self.line = new THREE.Line(geometry, material);
|
||||
})(this, direction, left, other);
|
||||
self.border = new THREE.Line(geometry, material);
|
||||
})(this, direction, left, other, position);
|
||||
|
||||
|
||||
var material = new THREE.MeshBasicMaterial({
|
||||
var material = new THREE.MeshLambertMaterial({
|
||||
color : 0xff0000,
|
||||
transparent : true,
|
||||
opacity : 0.5,
|
||||
@@ -95,15 +106,25 @@ FixedCamera.prototype.update = function(position) {
|
||||
// Compute distance between center of camera and position
|
||||
dist = Tools.norm2(Tools.diff(position, this.position));
|
||||
|
||||
var low_bound = 500;
|
||||
var high_bound = 500000;
|
||||
var low_bound = 1;
|
||||
var high_bound = 5;
|
||||
var new_value;
|
||||
|
||||
if (dist < 500)
|
||||
this.mesh.material.opacity = 0;
|
||||
else if (dist > 500000)
|
||||
this.mesh.material.opacity = 0.5;
|
||||
else
|
||||
this.mesh.material.opacity = (dist - 50)*0.5/(high_bound - low_bound);
|
||||
if (dist < low_bound) {
|
||||
new_value = 0;
|
||||
}
|
||||
else if (dist > high_bound) {
|
||||
new_value = 1;
|
||||
}
|
||||
else {
|
||||
new_value = (dist - low_bound)/(high_bound - low_bound);
|
||||
}
|
||||
|
||||
// Update opacity
|
||||
this.mesh.material.transparent = new_value < 0.9;
|
||||
this.border.material.transparent = new_value < 0.9;
|
||||
this.mesh.material.opacity = new_value;
|
||||
this.border.material.opacity = new_value;
|
||||
}
|
||||
|
||||
// Look function
|
||||
@@ -114,10 +135,10 @@ FixedCamera.prototype.look = function() {
|
||||
FixedCamera.prototype.addToScene = function(scene) {
|
||||
scene.add(this);
|
||||
scene.add(this.mesh);
|
||||
scene.add(this.line);
|
||||
scene.add(this.border);
|
||||
}
|
||||
|
||||
FixedCamera.prototype.traverse = function(callback) {
|
||||
callback(this.mesh);
|
||||
callback(this.line);
|
||||
callback(this.border);
|
||||
}
|
||||
|
||||
@@ -56,14 +56,15 @@ PointerCamera.prototype.constructor = PointerCamera;
|
||||
// Update function
|
||||
PointerCamera.prototype.update = function() {
|
||||
if (this.moving) {
|
||||
// Linear version
|
||||
var position_direction = Tools.diff(this.new_position, this.position);
|
||||
var target_direction = Tools.diff(this.new_target, this.target);
|
||||
|
||||
this.position.add(Tools.mul(position_direction, 0.05));
|
||||
this.target.add(Tools.mul(target_direction, 0.05));
|
||||
|
||||
if (Tools.norm2(Tools.diff(this.position, this.new_position)) < 0.1 &&
|
||||
Tools.norm2(Tools.diff(this.target, this.new_target)) < 0.1) {
|
||||
if (Tools.norm2(Tools.diff(this.position, this.new_position)) < 0.01 &&
|
||||
Tools.norm2(Tools.diff(this.target, this.new_target)) < 0.01) {
|
||||
// this.position = this.new_position.clone();
|
||||
// this.target = this.new_target.clone();
|
||||
this.moving = false;
|
||||
@@ -72,14 +73,38 @@ PointerCamera.prototype.update = function() {
|
||||
var forward = Tools.diff(this.target, this.position);
|
||||
forward.normalize();
|
||||
|
||||
this.phi = Math.asin(forward.z);
|
||||
this.phi = Math.asin(forward.y);
|
||||
|
||||
// Don't know why this line works... But thanks Thierry-san and
|
||||
// Bastien because it seems to work...
|
||||
this.theta = Math.atan2(forward.y, forward.x);
|
||||
this.theta = Math.atan2(forward.x, forward.z);
|
||||
|
||||
}
|
||||
|
||||
// Hermite polynom version
|
||||
// var eval = this.hermite.eval(this.t);
|
||||
// this.position.x = eval.x;
|
||||
// this.position.y = eval.y;
|
||||
// this.position.z = eval.z;
|
||||
|
||||
// this.target = Tools.sum(this.position, this.hermite.prime(this.t));
|
||||
|
||||
// this.t += 0.005;
|
||||
|
||||
// if (this.t > 1) {
|
||||
// this.moving = false;
|
||||
// // Update phi and theta so that return to reality does not hurt
|
||||
// var forward = Tools.diff(this.target, this.position);
|
||||
// forward.normalize();
|
||||
|
||||
// this.phi = Math.asin(forward.y);
|
||||
|
||||
// // 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);
|
||||
|
||||
// }
|
||||
|
||||
} else {
|
||||
// Update angles
|
||||
if (this.increasePhi) this.phi += this.sensitivity;
|
||||
@@ -133,6 +158,11 @@ PointerCamera.prototype.move = function(otherCamera) {
|
||||
this.moving = true;
|
||||
this.new_target = otherCamera.target.clone();
|
||||
this.new_position = otherCamera.position.clone();
|
||||
var t = [0,1];
|
||||
var f = [this.position.clone(), this.new_position];
|
||||
var fp = [Tools.diff(this.target, this.position), Tools.diff(this.new_target, this.new_position)];
|
||||
this.hermite = new Hermite.Polynom(t,f,fp);
|
||||
this.t = 0;
|
||||
}
|
||||
|
||||
// Look function
|
||||
@@ -162,6 +192,8 @@ PointerCamera.prototype.onKeyEvent = function(event, toSet) {
|
||||
case 75: case 98: this.decreasePhi = toSet; break; // 2 Down for angle
|
||||
case 74: case 100: this.increaseTheta = toSet; break; // 4 Left for angle
|
||||
case 76: case 102: this.decreaseTheta = toSet; break; // 6 Right for angle
|
||||
|
||||
case 13: if (toSet) this.log(); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +228,11 @@ PointerCamera.prototype.onMouseUp = function(event) {
|
||||
this.dragging = false;
|
||||
}
|
||||
|
||||
PointerCamera.prototype.log = function() {
|
||||
console.log(this.position.x, this.position.y, this.position.z);
|
||||
console.log(this.target.x, this.target.y, this.target.z);
|
||||
}
|
||||
|
||||
// Static members
|
||||
PointerCamera.DISTANCE_X = 1000;
|
||||
PointerCamera.DISTANCE_Z = 300;
|
||||
|
||||
Reference in New Issue
Block a user