3d-interface/static/js/CameraContainer.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-04-02 12:38:06 +02:00
var CameraContainer = function () {
this.cameras = new Array();
}
CameraContainer.prototype.mainCamera = function(id) {
if (id === undefined) {
2015-04-22 10:17:54 +02:00
return this.pointerCamera;
2015-04-02 12:38:06 +02:00
}
if (id >= cameras.length || id < 0) {
console.log('Warning : this camera does not exist');
return;
}
this.current_camera = id;
}
CameraContainer.prototype.forEach = function(callback) {
callback(this.pointerCamera);
2015-04-02 12:38:06 +02:00
this.cameras.forEach(callback);
}
CameraContainer.prototype.look = function() {
2015-04-22 10:17:54 +02:00
this.mainCamera().look();
}
CameraContainer.prototype.updateMainCamera = function() {
this.pointerCamera.update();
2015-04-02 12:38:06 +02:00
}
CameraContainer.prototype.update = function(position) {
this.cameras.map(function (elt) { elt.update(position); });
2015-04-02 12:38:06 +02:00
}
CameraContainer.prototype.push = function(camera) {
2015-04-22 10:17:54 +02:00
this.pointerCamera = camera;
this.push = function(camera) {
this.cameras.push(camera);
};
2015-04-02 12:38:06 +02:00
}
CameraContainer.prototype.get = function(i) {
return this.cameras[i];
}
CameraContainer.prototype.getById = function(id) {
for (var i in this.cameras) {
if (this.cameras[i] instanceof FixedCamera) {
if (this.cameras[i].object3D !== undefined) {
if (this.cameras[i].object3D.id == id) {
return this.get(i);
}
}
} else if (this.cameras[i] instanceof OldFixedCamera) {
if (this.cameras[i].mesh !== undefined) {
if (this.cameras[i].mesh.id == id) {
return this.get(i);
}
2015-04-02 12:38:06 +02:00
}
}
}
}
CameraContainer.prototype.setById = function(id) {
var i = this.getById(id);
if (i !== -1)
this.current_camera = i;
}
CameraContainer.prototype.nextCamera = function() {
if (this.cameras.length != 0) {
this.current_camera++;
this.current_camera%=this.cameras.length;
}
}
2015-04-13 09:48:50 +02:00
CameraContainer.prototype.map = function(callback) {
this.cameras.map(callback);
}