|
@@ -1,39 +1,34 @@
|
|
|
import { Camera } from './Camera.js';
|
|
|
-import { Object3D } from '../core/Object3D.js';
|
|
|
import { MathUtils } from '../math/MathUtils.js';
|
|
|
|
|
|
-function PerspectiveCamera( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
|
|
|
+class PerspectiveCamera extends Camera {
|
|
|
|
|
|
- Camera.call( this );
|
|
|
+ constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
|
|
|
|
|
|
- this.type = 'PerspectiveCamera';
|
|
|
+ super();
|
|
|
|
|
|
- this.fov = fov;
|
|
|
- this.zoom = 1;
|
|
|
+ this.type = 'PerspectiveCamera';
|
|
|
|
|
|
- this.near = near;
|
|
|
- this.far = far;
|
|
|
- this.focus = 10;
|
|
|
+ this.fov = fov;
|
|
|
+ this.zoom = 1;
|
|
|
|
|
|
- this.aspect = aspect;
|
|
|
- this.view = null;
|
|
|
+ this.near = near;
|
|
|
+ this.far = far;
|
|
|
+ this.focus = 10;
|
|
|
|
|
|
- this.filmGauge = 35; // width of the film (default in millimeters)
|
|
|
- this.filmOffset = 0; // horizontal film offset (same unit as gauge)
|
|
|
+ this.aspect = aspect;
|
|
|
+ this.view = null;
|
|
|
|
|
|
- this.updateProjectionMatrix();
|
|
|
+ this.filmGauge = 35; // width of the film (default in millimeters)
|
|
|
+ this.filmOffset = 0; // horizontal film offset (same unit as gauge)
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
|
|
|
-
|
|
|
- constructor: PerspectiveCamera,
|
|
|
+ this.updateProjectionMatrix();
|
|
|
|
|
|
- isPerspectiveCamera: true,
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( source, recursive ) {
|
|
|
+ copy( source, recursive ) {
|
|
|
|
|
|
- Camera.prototype.copy.call( this, source, recursive );
|
|
|
+ super.copy( source, recursive );
|
|
|
|
|
|
this.fov = source.fov;
|
|
|
this.zoom = source.zoom;
|
|
@@ -50,7 +45,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Sets the FOV by focal length in respect to the current .filmGauge.
|
|
@@ -60,7 +55,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
*
|
|
|
* Values for focal length and film gauge must have the same unit.
|
|
|
*/
|
|
|
- setFocalLength: function ( focalLength ) {
|
|
|
+ setFocalLength( focalLength ) {
|
|
|
|
|
|
/** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
|
|
|
const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
|
|
@@ -68,39 +63,39 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
|
|
|
this.updateProjectionMatrix();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Calculates the focal length from the current .fov and .filmGauge.
|
|
|
*/
|
|
|
- getFocalLength: function () {
|
|
|
+ getFocalLength() {
|
|
|
|
|
|
const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
|
|
|
|
|
|
return 0.5 * this.getFilmHeight() / vExtentSlope;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getEffectiveFOV: function () {
|
|
|
+ getEffectiveFOV() {
|
|
|
|
|
|
return MathUtils.RAD2DEG * 2 * Math.atan(
|
|
|
Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getFilmWidth: function () {
|
|
|
+ getFilmWidth() {
|
|
|
|
|
|
// film not completely covered in portrait format (aspect < 1)
|
|
|
return this.filmGauge * Math.min( this.aspect, 1 );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getFilmHeight: function () {
|
|
|
+ getFilmHeight() {
|
|
|
|
|
|
// film not completely covered in landscape format (aspect > 1)
|
|
|
return this.filmGauge / Math.max( this.aspect, 1 );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Sets an offset in a larger frustum. This is useful for multi-window or
|
|
@@ -137,7 +132,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
*
|
|
|
* Note there is no reason monitors have to be the same size or in a grid.
|
|
|
*/
|
|
|
- setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
|
|
|
+ setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
|
|
|
|
|
|
this.aspect = fullWidth / fullHeight;
|
|
|
|
|
@@ -165,9 +160,9 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
|
|
|
this.updateProjectionMatrix();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- clearViewOffset: function () {
|
|
|
+ clearViewOffset() {
|
|
|
|
|
|
if ( this.view !== null ) {
|
|
|
|
|
@@ -177,9 +172,9 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
|
|
|
this.updateProjectionMatrix();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- updateProjectionMatrix: function () {
|
|
|
+ updateProjectionMatrix() {
|
|
|
|
|
|
const near = this.near;
|
|
|
let top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom;
|
|
@@ -207,11 +202,11 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
|
|
|
this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toJSON: function ( meta ) {
|
|
|
+ toJSON( meta ) {
|
|
|
|
|
|
- const data = Object3D.prototype.toJSON.call( this, meta );
|
|
|
+ const data = super.toJSON( meta );
|
|
|
|
|
|
data.object.fov = this.fov;
|
|
|
data.object.zoom = this.zoom;
|
|
@@ -231,7 +226,8 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
|
|
|
+PerspectiveCamera.prototype.isPerspectiveCamera = true;
|
|
|
|
|
|
export { PerspectiveCamera };
|