11import { Camera } from './Camera.js' ;
2- import { Object3D } from '../core/Object3D.js' ;
32import { MathUtils } from '../math/MathUtils.js' ;
43
5- function PerspectiveCamera ( fov = 50 , aspect = 1 , near = 0.1 , far = 2000 ) {
4+ class PerspectiveCamera extends Camera {
65
7- Camera . call ( this ) ;
6+ constructor ( fov = 50 , aspect = 1 , near = 0.1 , far = 2000 ) {
87
9- this . type = 'PerspectiveCamera' ;
8+ super ( ) ;
109
11- this . fov = fov ;
12- this . zoom = 1 ;
10+ this . type = 'PerspectiveCamera' ;
1311
14- this . near = near ;
15- this . far = far ;
16- this . focus = 10 ;
12+ this . fov = fov ;
13+ this . zoom = 1 ;
1714
18- this . aspect = aspect ;
19- this . view = null ;
15+ this . near = near ;
16+ this . far = far ;
17+ this . focus = 10 ;
2018
21- this . filmGauge = 35 ; // width of the film (default in millimeters)
22- this . filmOffset = 0 ; // horizontal film offset (same unit as gauge)
19+ this . aspect = aspect ;
20+ this . view = null ;
2321
24- this . updateProjectionMatrix ( ) ;
22+ this . filmGauge = 35 ; // width of the film (default in millimeters)
23+ this . filmOffset = 0 ; // horizontal film offset (same unit as gauge)
2524
26- }
27-
28- PerspectiveCamera . prototype = Object . assign ( Object . create ( Camera . prototype ) , {
29-
30- constructor : PerspectiveCamera ,
25+ this . updateProjectionMatrix ( ) ;
3126
32- isPerspectiveCamera : true ,
27+ }
3328
34- copy : function ( source , recursive ) {
29+ copy ( source , recursive ) {
3530
36- Camera . prototype . copy . call ( this , source , recursive ) ;
31+ super . copy ( source , recursive ) ;
3732
3833 this . fov = source . fov ;
3934 this . zoom = source . zoom ;
@@ -50,7 +45,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
5045
5146 return this ;
5247
53- } ,
48+ }
5449
5550 /**
5651 * Sets the FOV by focal length in respect to the current .filmGauge.
@@ -60,47 +55,47 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
6055 *
6156 * Values for focal length and film gauge must have the same unit.
6257 */
63- setFocalLength : function ( focalLength ) {
58+ setFocalLength ( focalLength ) {
6459
6560 /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
6661 const vExtentSlope = 0.5 * this . getFilmHeight ( ) / focalLength ;
6762
6863 this . fov = MathUtils . RAD2DEG * 2 * Math . atan ( vExtentSlope ) ;
6964 this . updateProjectionMatrix ( ) ;
7065
71- } ,
66+ }
7267
7368 /**
7469 * Calculates the focal length from the current .fov and .filmGauge.
7570 */
76- getFocalLength : function ( ) {
71+ getFocalLength ( ) {
7772
7873 const vExtentSlope = Math . tan ( MathUtils . DEG2RAD * 0.5 * this . fov ) ;
7974
8075 return 0.5 * this . getFilmHeight ( ) / vExtentSlope ;
8176
82- } ,
77+ }
8378
84- getEffectiveFOV : function ( ) {
79+ getEffectiveFOV ( ) {
8580
8681 return MathUtils . RAD2DEG * 2 * Math . atan (
8782 Math . tan ( MathUtils . DEG2RAD * 0.5 * this . fov ) / this . zoom ) ;
8883
89- } ,
84+ }
9085
91- getFilmWidth : function ( ) {
86+ getFilmWidth ( ) {
9287
9388 // film not completely covered in portrait format (aspect < 1)
9489 return this . filmGauge * Math . min ( this . aspect , 1 ) ;
9590
96- } ,
91+ }
9792
98- getFilmHeight : function ( ) {
93+ getFilmHeight ( ) {
9994
10095 // film not completely covered in landscape format (aspect > 1)
10196 return this . filmGauge / Math . max ( this . aspect , 1 ) ;
10297
103- } ,
98+ }
10499
105100 /**
106101 * 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 ),
137132 *
138133 * Note there is no reason monitors have to be the same size or in a grid.
139134 */
140- setViewOffset : function ( fullWidth , fullHeight , x , y , width , height ) {
135+ setViewOffset ( fullWidth , fullHeight , x , y , width , height ) {
141136
142137 this . aspect = fullWidth / fullHeight ;
143138
@@ -165,9 +160,9 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
165160
166161 this . updateProjectionMatrix ( ) ;
167162
168- } ,
163+ }
169164
170- clearViewOffset : function ( ) {
165+ clearViewOffset ( ) {
171166
172167 if ( this . view !== null ) {
173168
@@ -177,9 +172,9 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
177172
178173 this . updateProjectionMatrix ( ) ;
179174
180- } ,
175+ }
181176
182- updateProjectionMatrix : function ( ) {
177+ updateProjectionMatrix ( ) {
183178
184179 const near = this . near ;
185180 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 ),
207202
208203 this . projectionMatrixInverse . copy ( this . projectionMatrix ) . invert ( ) ;
209204
210- } ,
205+ }
211206
212- toJSON : function ( meta ) {
207+ toJSON ( meta ) {
213208
214- const data = Object3D . prototype . toJSON . call ( this , meta ) ;
209+ const data = super . toJSON ( meta ) ;
215210
216211 data . object . fov = this . fov ;
217212 data . object . zoom = this . zoom ;
@@ -231,7 +226,8 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
231226
232227 }
233228
234- } ) ;
229+ }
235230
231+ PerspectiveCamera . prototype . isPerspectiveCamera = true ;
236232
237233export { PerspectiveCamera } ;
0 commit comments