146 lines
3.7 KiB
JavaScript
146 lines
3.7 KiB
JavaScript
|
/**
|
||
|
* R3.D3.Camera.Perspective
|
||
|
* @param graphics R3.GraphicsRuntime
|
||
|
* @param apiD3ObjectPerspectiveCamera
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.D3.Camera.Perspective = function(
|
||
|
graphics,
|
||
|
apiD3ObjectPerspectiveCamera
|
||
|
) {
|
||
|
|
||
|
this.graphics = graphics;
|
||
|
this.graphics.isNotThreeThrow();
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiD3ObjectPerspectiveCamera)) {
|
||
|
apiD3ObjectPerspectiveCamera = {
|
||
|
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
|
||
|
};
|
||
|
}
|
||
|
|
||
|
R3.D3.API.Camera.Perspective.call(
|
||
|
this,
|
||
|
apiD3ObjectPerspectiveCamera,
|
||
|
apiD3ObjectPerspectiveCamera.near,
|
||
|
apiD3ObjectPerspectiveCamera.far,
|
||
|
apiD3ObjectPerspectiveCamera.fov,
|
||
|
apiD3ObjectPerspectiveCamera.filmGauge,
|
||
|
apiD3ObjectPerspectiveCamera.filmOffset,
|
||
|
apiD3ObjectPerspectiveCamera.focus,
|
||
|
apiD3ObjectPerspectiveCamera.zoom
|
||
|
);
|
||
|
|
||
|
R3.D3.Camera.call(
|
||
|
this,
|
||
|
this.graphics,
|
||
|
this
|
||
|
);
|
||
|
|
||
|
};
|
||
|
|
||
|
R3.D3.Camera.Perspective.prototype = Object.create(R3.D3.Camera.prototype);
|
||
|
R3.D3.Camera.Perspective.prototype.constructor = R3.D3.Camera.Perspective;
|
||
|
|
||
|
/**
|
||
|
* Creates a camera instance
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
R3.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;
|
||
|
|
||
|
R3.D3.Camera.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the instance with the current state
|
||
|
*/
|
||
|
R3.D3.Camera.Perspective.prototype.updateInstance = function(property) {
|
||
|
|
||
|
if (property === 'near') {
|
||
|
this.instance.near = this.near;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (property === 'far') {
|
||
|
this.instance.far = this.far;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (property === 'fov') {
|
||
|
this.instance.fov = this.fov;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (property === 'filmGauge') {
|
||
|
this.instance.filmGauge = this.filmGauge;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (property === 'filmOffset') {
|
||
|
this.instance.filmOffset = this.filmOffset;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (property === 'focus') {
|
||
|
this.instance.focus = this.focus;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (property === 'zoom') {
|
||
|
this.instance.zoom = this.zoom;
|
||
|
this.instance.updateProjectionMatrix();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
R3.D3.Camera.prototype.updateInstance.call(this, property);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a R3.D3.Camera to a R3.D3.API.Camera
|
||
|
* @returns {R3.D3.API.Camera}
|
||
|
*/
|
||
|
R3.D3.Camera.Perspective.prototype.toApiObject = function() {
|
||
|
|
||
|
var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this);
|
||
|
|
||
|
var apiPerspectiveCamera = new R3.D3.API.Camera.Perspective(
|
||
|
apiCamera,
|
||
|
this.near,
|
||
|
this.far,
|
||
|
this.fov,
|
||
|
this.filmGauge,
|
||
|
this.filmOffset,
|
||
|
this.focus,
|
||
|
this.zoom
|
||
|
);
|
||
|
|
||
|
return apiPerspectiveCamera;
|
||
|
};
|
||
|
|
||
|
R3.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;
|
||
|
R3.D3.Camera.prototype.updateFromInstance.call(this);
|
||
|
};
|