2015-04-30 11:25:32 +02:00
|
|
|
// Initialization
|
|
|
|
|
|
|
|
// class camera extends THREE.PerspectiveCamera
|
|
|
|
var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
|
|
|
|
THREE.PerspectiveCamera.apply(this, arguments);
|
|
|
|
|
|
|
|
// Set Position
|
|
|
|
if (position === undefined) {
|
|
|
|
this.position = new THREE.Vector3(0,0,5);
|
|
|
|
} else {
|
|
|
|
this.position.x = position.x;
|
|
|
|
this.position.y = position.y;
|
|
|
|
this.position.z = position.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target === undefined)
|
|
|
|
target = new THREE.Vector3(0,0,0);
|
|
|
|
|
|
|
|
var direction = target.clone();
|
|
|
|
direction.sub(this.position);
|
|
|
|
direction.normalize();
|
|
|
|
|
|
|
|
this.target = this.position.clone();
|
|
|
|
this.target.add(Tools.mul(direction,10));
|
|
|
|
// this.up = new THREE.Vector3(0,0,1);
|
|
|
|
|
|
|
|
// Compute corners
|
|
|
|
|
|
|
|
// Create the mesh to draw
|
|
|
|
|
|
|
|
var geometry = new THREE.Geometry();
|
|
|
|
|
|
|
|
var left = Tools.cross(direction, this.up);
|
|
|
|
var other = Tools.cross(direction, left);
|
|
|
|
left.normalize();
|
|
|
|
other.normalize();
|
|
|
|
left = Tools.mul(left, 1);
|
|
|
|
other = Tools.mul(other, 1);
|
|
|
|
|
|
|
|
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.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)
|
|
|
|
);
|
|
|
|
|
|
|
|
(function(self, direction, left, other) {
|
|
|
|
var material = new THREE.LineBasicMaterial({ color: '0x000000'});
|
|
|
|
var geometry = new THREE.Geometry();
|
2015-07-01 10:14:15 +02:00
|
|
|
var tmp_direction = Tools.mul(direction, -2);
|
|
|
|
var target = Tools.sum(self.position, tmp_direction);
|
2015-04-30 11:25:32 +02:00
|
|
|
// geometry.vertices.push(self.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),
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
Tools.sum(self.position, tmp_direction),
|
2015-04-30 11:25:32 +02:00
|
|
|
Tools.sum(Tools.sum(self.position, left), other),
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
Tools.sum(self.position, tmp_direction),
|
2015-04-30 11:25:32 +02:00
|
|
|
Tools.diff(Tools.sum(self.position, other),left),
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
Tools.sum(self.position, tmp_direction),
|
2015-04-30 11:25:32 +02:00
|
|
|
Tools.diff(Tools.diff(self.position, left),other),
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
Tools.sum(self.position, tmp_direction),
|
2015-04-30 11:25:32 +02:00
|
|
|
Tools.sum(Tools.diff(self.position, other), left)
|
|
|
|
);
|
|
|
|
|
|
|
|
self.line = new THREE.Line(geometry, material);
|
|
|
|
})(this, direction, left, other);
|
|
|
|
|
|
|
|
|
|
|
|
var material = new THREE.MeshBasicMaterial({
|
2015-05-20 17:31:30 +02:00
|
|
|
color : 0x0000ff,
|
2015-04-30 11:25:32 +02:00
|
|
|
transparent : true,
|
|
|
|
opacity : 1,
|
|
|
|
side: THREE.DoubleSide
|
|
|
|
});
|
|
|
|
|
|
|
|
this.mesh = new THREE.Mesh(geometry, material);
|
2015-05-06 14:54:02 +02:00
|
|
|
this.mesh.raycastable = true;
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-04-30 11:25:32 +02:00
|
|
|
OldFixedCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
|
|
|
|
OldFixedCamera.prototype.constructor = OldFixedCamera;
|
|
|
|
|
2015-05-20 17:31:30 +02:00
|
|
|
OldFixedCamera.prototype.check = function() {
|
|
|
|
this.mesh.material.color.setHex(0x663366);
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-05-20 17:29:42 +02:00
|
|
|
|
2015-04-30 11:25:32 +02:00
|
|
|
// Update function
|
|
|
|
OldFixedCamera.prototype.update = function(position) {
|
|
|
|
// Compute distance between center of camera and position
|
|
|
|
dist = Tools.norm2(Tools.diff(position.position, this.position));
|
|
|
|
|
|
|
|
var low_bound = 1;
|
|
|
|
var high_bound = 5;
|
|
|
|
var new_value;
|
|
|
|
var max_value = 0.5;
|
|
|
|
|
|
|
|
if (dist < low_bound)
|
|
|
|
new_value = 0;
|
|
|
|
else if (dist > high_bound)
|
|
|
|
new_value = max_value;
|
|
|
|
else
|
|
|
|
new_value = max_value * (dist - low_bound)/(high_bound - low_bound);
|
|
|
|
|
|
|
|
this.mesh.material.transparent = new_value < 0.9;
|
|
|
|
this.mesh.material.opacity = new_value;
|
|
|
|
|
|
|
|
if (new_value < 0.1)
|
|
|
|
this.mesh.material.transparent = this.mesh.visible = false;
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-04-30 11:25:32 +02:00
|
|
|
|
|
|
|
// Look function
|
|
|
|
OldFixedCamera.prototype.look = function() {
|
|
|
|
this.lookAt(this.target);
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-04-30 11:25:32 +02:00
|
|
|
|
|
|
|
OldFixedCamera.prototype.addToScene = function(scene) {
|
|
|
|
scene.add(this);
|
|
|
|
scene.add(this.mesh);
|
|
|
|
scene.add(this.line);
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-04-30 11:25:32 +02:00
|
|
|
|
|
|
|
OldFixedCamera.prototype.traverse = function(callback) {
|
|
|
|
callback(this.mesh);
|
|
|
|
callback(this.line);
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-05-11 09:31:10 +02:00
|
|
|
|
|
|
|
OldFixedCamera.prototype.containsObject = function(object) {
|
|
|
|
return object === this.mesh;
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-05-11 09:31:10 +02:00
|
|
|
|