3d-interface/js/Camera.js

32 lines
817 B
JavaScript
Raw Normal View History

2015-04-02 12:38:06 +02:00
// class camera extends THREE.PerspectiveCamera
var Camera = function() {
THREE.PerspectiveCamera.apply(this, arguments);
this.theta = 0;
this.position.x = Camera.DISTANCE_X;
this.position.z = Camera.DISTANCE_Z;
this.up = new THREE.Vector3(0,0,1);
this.target = new THREE.Vector3();
}
Camera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
// Update function
2015-06-09 17:36:21 +02:00
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-04-02 12:38:06 +02:00
this.position.x = Camera.DISTANCE_X*Math.cos(this.theta);
this.position.y = Camera.DISTANCE_X*Math.sin(this.theta);
}
// Look function
Camera.prototype.look = function() {
this.lookAt(this.target);
}
// Static members
Camera.DISTANCE_X = 1000;
Camera.DISTANCE_Z = 300;