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

139 lines
3.4 KiB
JavaScript

/**
* GameLib.D3.Camera.Perspective
* @param graphics GameLib.GraphicsRuntime
* @param apiD3ObjectPerspectiveCamera
* @constructor
*/
GameLib.D3.Camera.Perspective = function(
graphics,
apiD3ObjectPerspectiveCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectPerspectiveCamera)) {
apiD3ObjectPerspectiveCamera = {
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
};
}
GameLib.D3.API.Camera.Perspective.call(
this,
apiD3ObjectPerspectiveCamera,
apiD3ObjectPerspectiveCamera.near,
apiD3ObjectPerspectiveCamera.far,
apiD3ObjectPerspectiveCamera.fov,
apiD3ObjectPerspectiveCamera.filmGauge,
apiD3ObjectPerspectiveCamera.filmOffset,
apiD3ObjectPerspectiveCamera.focus,
apiD3ObjectPerspectiveCamera.zoom
);
GameLib.D3.Camera.call(
this,
this.graphics,
this
);
};
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);
};