2015-07-06 17:59:23 +02:00
|
|
|
/**
|
|
|
|
* Reprensents a simple rotating camera
|
|
|
|
* @constructor
|
|
|
|
* @memberof L3D
|
|
|
|
* @extends THREE.PerspectiveCamera
|
|
|
|
*/
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.Camera = function() {
|
2015-04-02 12:38:06 +02:00
|
|
|
THREE.PerspectiveCamera.apply(this, arguments);
|
|
|
|
|
2015-07-06 17:59:23 +02:00
|
|
|
/**
|
|
|
|
* @type {Number}
|
|
|
|
* @description angle of the camera
|
|
|
|
*/
|
2015-04-02 12:38:06 +02:00
|
|
|
this.theta = 0;
|
2015-07-06 17:59:23 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
this.position.x = L3D.Camera.DISTANCE_X;
|
|
|
|
this.position.z = L3D.Camera.DISTANCE_Z;
|
2015-04-02 12:38:06 +02:00
|
|
|
|
|
|
|
this.up = new THREE.Vector3(0,0,1);
|
2015-07-06 17:59:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {THREE.Vector3}
|
|
|
|
* @description Position where the camera is looking at
|
|
|
|
*/
|
2015-04-02 12:38:06 +02:00
|
|
|
this.target = new THREE.Vector3();
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.Camera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
|
2015-04-02 12:38:06 +02:00
|
|
|
|
2015-07-06 17:59:23 +02:00
|
|
|
/**
|
|
|
|
* Updates the position of the camera
|
|
|
|
* @param time {Number} time elapsed since the last update in millisec
|
|
|
|
*/
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.Camera.prototype.update = function(time) {
|
2015-06-15 08:46:35 +02:00
|
|
|
if (time === undefined) {
|
|
|
|
time = 20;
|
|
|
|
}
|
2015-06-09 17:36:21 +02:00
|
|
|
this.theta += 0.01 * time / 20;
|
2015-07-01 16:31:43 +02:00
|
|
|
this.position.x = L3D.Camera.DISTANCE_X*Math.cos(this.theta);
|
|
|
|
this.position.y = L3D.Camera.DISTANCE_X*Math.sin(this.theta);
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-04-02 12:38:06 +02:00
|
|
|
|
2015-07-06 17:59:23 +02:00
|
|
|
/**
|
|
|
|
* look function. Just like OpenGL gluLookAt
|
|
|
|
*/
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.Camera.prototype.look = function() {
|
2015-04-02 12:38:06 +02:00
|
|
|
this.lookAt(this.target);
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-04-02 12:38:06 +02:00
|
|
|
|
2015-07-06 17:59:23 +02:00
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type {Number}
|
|
|
|
* @description radiusof the circle where the camera is rotating
|
|
|
|
*/
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.Camera.DISTANCE_X = 1000;
|
2015-07-06 17:59:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type {Number}
|
|
|
|
* @description Altitude of the camera
|
|
|
|
*/
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.Camera.DISTANCE_Z = 300;
|