r3-legacy/src/game-lib-d3-camera-perspect...

139 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-01-29 12:42:46 +01:00
/**
* GameLib.D3.Camera.Perspective
* @param graphics GameLib.GraphicsRuntime
* @param apiPerspectiveCamera
* @constructor
*/
GameLib.D3.Camera.Perspective = function(
graphics,
apiPerspectiveCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiPerspectiveCamera)) {
apiPerspectiveCamera = {
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
};
}
GameLib.D3.API.Camera.Perspective.call(
this,
apiPerspectiveCamera,
apiPerspectiveCamera.near,
apiPerspectiveCamera.far,
apiPerspectiveCamera.fov,
apiPerspectiveCamera.filmGauge,
apiPerspectiveCamera.filmOffset,
apiPerspectiveCamera.focus,
apiPerspectiveCamera.zoom
);
GameLib.D3.Camera.call(
this,
this.graphics,
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;
return;
}
if (property === 'far') {
this.instance.far = this.far;
return;
}
if (property === 'fov') {
this.instance.fov = this.fov;
return;
}
if (property === 'filmGauge') {
this.instance.filmGauge = this.filmGauge;
return;
}
if (property === 'filmOffset') {
this.instance.filmOffset = this.filmOffset;
return;
}
if (property === 'focus') {
this.instance.focus = this.focus;
return;
}
if (property === 'zoom') {
this.instance.zoom = this.zoom;
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);
};