2015-05-06 14:54:02 +02:00
|
|
|
var CameraContainer = function (pointerCamera, cameras) {
|
|
|
|
if (cameras !== undefined) {
|
|
|
|
this.cameras = cameras;
|
|
|
|
} else {
|
|
|
|
this.cameras = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pointerCamera !== undefined) {
|
|
|
|
this.push(pointerCamera);
|
|
|
|
}
|
2015-04-02 12:38:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CameraContainer.prototype.mainCamera = function(id) {
|
2015-04-07 12:04:59 +02:00
|
|
|
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) {
|
2015-04-27 14:54:40 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-05-13 09:11:54 +02:00
|
|
|
CameraContainer.prototype.updateMainCamera = function(time) {
|
|
|
|
this.pointerCamera.update(time);
|
2015-04-02 12:38:06 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 10:11:42 +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];
|
|
|
|
}
|
|
|
|
|
2015-05-11 09:31:10 +02:00
|
|
|
CameraContainer.prototype.getByObject = function(object) {
|
2015-04-02 12:38:06 +02:00
|
|
|
for (var i in this.cameras) {
|
2015-05-11 09:31:10 +02:00
|
|
|
if (this.cameras[i].containsObject(object)) {
|
|
|
|
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);
|
|
|
|
}
|