2018-01-29 12:42:46 +01:00
|
|
|
/**
|
|
|
|
* GameLib.D3.Camera.Perspective
|
|
|
|
* @param graphics GameLib.GraphicsRuntime
|
2018-02-22 16:12:20 +01:00
|
|
|
* @param apiD3ObjectPerspectiveCamera
|
2018-01-29 12:42:46 +01:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Camera.Perspective = function(
|
|
|
|
graphics,
|
2018-02-22 16:12:20 +01:00
|
|
|
apiD3ObjectPerspectiveCamera
|
2018-01-29 12:42:46 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
|
2018-02-22 16:12:20 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectPerspectiveCamera)) {
|
|
|
|
apiD3ObjectPerspectiveCamera = {
|
|
|
|
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
|
2018-01-29 12:42:46 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.D3.API.Camera.Perspective.call(
|
|
|
|
this,
|
2018-02-22 16:12:20 +01:00
|
|
|
apiD3ObjectPerspectiveCamera,
|
|
|
|
apiD3ObjectPerspectiveCamera.near,
|
|
|
|
apiD3ObjectPerspectiveCamera.far,
|
|
|
|
apiD3ObjectPerspectiveCamera.fov,
|
|
|
|
apiD3ObjectPerspectiveCamera.filmGauge,
|
|
|
|
apiD3ObjectPerspectiveCamera.filmOffset,
|
|
|
|
apiD3ObjectPerspectiveCamera.focus,
|
|
|
|
apiD3ObjectPerspectiveCamera.zoom
|
2018-01-29 12:42:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
GameLib.D3.Camera.call(
|
|
|
|
this,
|
|
|
|
this.graphics,
|
2018-01-30 15:02:47 +01:00
|
|
|
this
|
2018-01-29 12:42:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Camera.Perspective.prototype = Object.create(GameLib.D3.Camera.prototype);
|
|
|
|
GameLib.D3.Camera.Perspective.prototype.constructor = GameLib.D3.Camera.Perspective;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a camera instance
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Camera.Perspective.prototype.createInstance = function() {
|
|
|
|
|
|
|
|
this.instance = new THREE.PerspectiveCamera(
|
|
|
|
this.fov,
|
|
|
|
this.aspect,
|
|
|
|
this.near,
|
|
|
|
this.far
|
|
|
|
);
|
|
|
|
|
|
|
|
this.instance.filmGauge = this.filmGauge;
|
|
|
|
this.instance.filmOffset = this.filmOffset;
|
|
|
|
this.instance.focus = this.focus;
|
|
|
|
this.instance.zoom = this.zoom;
|
|
|
|
|
|
|
|
GameLib.D3.Camera.prototype.createInstance.call(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the instance with the current state
|
|
|
|
*/
|
|
|
|
GameLib.D3.Camera.Perspective.prototype.updateInstance = function(property) {
|
|
|
|
|
|
|
|
if (property === 'near') {
|
|
|
|
this.instance.near = this.near;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'far') {
|
|
|
|
this.instance.far = this.far;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'fov') {
|
|
|
|
this.instance.fov = this.fov;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'filmGauge') {
|
|
|
|
this.instance.filmGauge = this.filmGauge;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'filmOffset') {
|
|
|
|
this.instance.filmOffset = this.filmOffset;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'focus') {
|
|
|
|
this.instance.focus = this.focus;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property === 'zoom') {
|
|
|
|
this.instance.zoom = this.zoom;
|
2018-03-09 03:38:45 +01:00
|
|
|
this.instance.updateProjectionMatrix();
|
2018-01-29 12:42:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a GameLib.D3.Camera to a GameLib.D3.API.Camera
|
|
|
|
* @returns {GameLib.D3.API.Camera}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Camera.Perspective.prototype.toApiObject = function() {
|
|
|
|
|
|
|
|
var apiCamera = GameLib.D3.Camera.prototype.toApiObject.call(this);
|
|
|
|
|
|
|
|
var apiPerspectiveCamera = new GameLib.D3.API.Camera.Perspective(
|
|
|
|
apiCamera,
|
|
|
|
this.near,
|
|
|
|
this.far,
|
|
|
|
this.fov,
|
|
|
|
this.filmGauge,
|
|
|
|
this.filmOffset,
|
|
|
|
this.focus,
|
|
|
|
this.zoom
|
|
|
|
);
|
|
|
|
|
|
|
|
return apiPerspectiveCamera;
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Camera.Perspective.prototype.updateFromInstance = function() {
|
|
|
|
this.near = this.instance.near;
|
|
|
|
this.far = this.instance.far;
|
|
|
|
this.fov = this.instance.fov;
|
|
|
|
this.filmGauge = this.instance.filmGauge;
|
|
|
|
this.filmOffset = this.instance.filmOffset;
|
|
|
|
this.focus = this.instance.focus;
|
|
|
|
this.zoom = this.instance.zoom;
|
|
|
|
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
|
|
|
|
};
|