diff --git a/src/cameras/OrthographicCamera.js b/src/cameras/OrthographicCamera.js index 00175cf29974211cc732181d37720edbb2878c56..a1879891da719d8383e68b5835931c034aa02dae 100644 --- a/src/cameras/OrthographicCamera.js +++ b/src/cameras/OrthographicCamera.js @@ -22,49 +22,52 @@ THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) { }; -THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype ); -THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera; +THREE.OrthographicCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), { -THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () { + constructor: THREE.OrthographicCamera, - var dx = ( this.right - this.left ) / ( 2 * this.zoom ); - var dy = ( this.top - this.bottom ) / ( 2 * this.zoom ); - var cx = ( this.right + this.left ) / 2; - var cy = ( this.top + this.bottom ) / 2; + copy: function ( source ) { - this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far ); + THREE.Camera.prototype.copy.call( this, source ); -}; + this.left = source.left; + this.right = source.right; + this.top = source.top; + this.bottom = source.bottom; + this.near = source.near; + this.far = source.far; -THREE.OrthographicCamera.prototype.copy = function ( source ) { + this.zoom = source.zoom; - THREE.Camera.prototype.copy.call( this, source ); + return this; - this.left = source.left; - this.right = source.right; - this.top = source.top; - this.bottom = source.bottom; - this.near = source.near; - this.far = source.far; + }, - this.zoom = source.zoom; + updateProjectionMatrix: function () { - return this; + var dx = ( this.right - this.left ) / ( 2 * this.zoom ); + var dy = ( this.top - this.bottom ) / ( 2 * this.zoom ); + var cx = ( this.right + this.left ) / 2; + var cy = ( this.top + this.bottom ) / 2; -}; + this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far ); -THREE.OrthographicCamera.prototype.toJSON = function ( meta ) { + }, - var data = THREE.Object3D.prototype.toJSON.call( this, meta ); + toJSON: function ( meta ) { - data.object.zoom = this.zoom; - data.object.left = this.left; - data.object.right = this.right; - data.object.top = this.top; - data.object.bottom = this.bottom; - data.object.near = this.near; - data.object.far = this.far; + var data = THREE.Object3D.prototype.toJSON.call( this, meta ); - return data; + data.object.zoom = this.zoom; + data.object.left = this.left; + data.object.right = this.right; + data.object.top = this.top; + data.object.bottom = this.bottom; + data.object.near = this.near; + data.object.far = this.far; -}; + return data; + + } + +} ); diff --git a/src/cameras/PerspectiveCamera.js b/src/cameras/PerspectiveCamera.js index 14080e485e370e9be8aae2a26335181e54ff38a6..fb61a9856b75b20fd82b4d06b0c9b9c5a847d4cf 100644 --- a/src/cameras/PerspectiveCamera.js +++ b/src/cameras/PerspectiveCamera.js @@ -28,199 +28,198 @@ THREE.PerspectiveCamera = function( fov, aspect, near, far ) { }; -THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype ); -THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera; +THREE.PerspectiveCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), { + constructor: THREE.PerspectiveCamera, -/** - * Sets the FOV by focal length (DEPRECATED). - * - * Optionally also sets .filmGauge, otherwise uses it. See .setFocalLength. - */ -THREE.PerspectiveCamera.prototype.setLens = function( focalLength, filmGauge ) { + copy: function ( source ) { - console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " + - "Use .setFocalLength and .filmGauge for a photographic setup." ); + THREE.Camera.prototype.copy.call( this, source ); - if ( filmGauge !== undefined ) this.filmGauge = filmGauge; - this.setFocalLength( focalLength ); + this.fov = source.fov; + this.zoom = source.zoom; -}; + this.near = source.near; + this.far = source.far; + this.focus = source.focus; -/** - * Sets the FOV by focal length in respect to the current .filmGauge. - * - * The default film gauge is 35, so that the focal length can be specified for - * a 35mm (full frame) camera. - * - * Values for focal length and film gauge must have the same unit. - */ -THREE.PerspectiveCamera.prototype.setFocalLength = function( focalLength ) { + this.aspect = source.aspect; + this.view = source.view === null ? null : Object.assign( {}, source.view ); - // see http://www.bobatkins.com/photography/technical/field_of_view.html - var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; + this.filmGauge = source.filmGauge; + this.filmOffset = source.filmOffset; - this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope ); - this.updateProjectionMatrix(); + return this; -}; + }, + /** + * Sets the FOV by focal length (DEPRECATED). + * + * Optionally also sets .filmGauge, otherwise uses it. See .setFocalLength. + */ + setLens: function ( focalLength, filmGauge ) { -/** - * Calculates the focal length from the current .fov and .filmGauge. - */ -THREE.PerspectiveCamera.prototype.getFocalLength = function() { + console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " + + "Use .setFocalLength and .filmGauge for a photographic setup." ); - var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ); + if ( filmGauge !== undefined ) this.filmGauge = filmGauge; + this.setFocalLength( focalLength ); - return 0.5 * this.getFilmHeight() / vExtentSlope; + }, -}; + /** + * Sets the FOV by focal length in respect to the current .filmGauge. + * + * The default film gauge is 35, so that the focal length can be specified for + * a 35mm (full frame) camera. + * + * Values for focal length and film gauge must have the same unit. + */ + setFocalLength: function ( focalLength ) { -THREE.PerspectiveCamera.prototype.getEffectiveFOV = function() { + // see http://www.bobatkins.com/photography/technical/field_of_view.html + var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; - return THREE.Math.RAD2DEG * 2 * Math.atan( - Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom ); + this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope ); + this.updateProjectionMatrix(); -}; + }, -THREE.PerspectiveCamera.prototype.getFilmWidth = function() { + /** + * Calculates the focal length from the current .fov and .filmGauge. + */ + getFocalLength: function () { - // film not completely covered in portrait format (aspect < 1) - return this.filmGauge * Math.min( this.aspect, 1 ); + var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ); -}; + return 0.5 * this.getFilmHeight() / vExtentSlope; -THREE.PerspectiveCamera.prototype.getFilmHeight = function() { + }, - // film not completely covered in landscape format (aspect > 1) - return this.filmGauge / Math.max( this.aspect, 1 ); + getEffectiveFOV: function () { -}; + return THREE.Math.RAD2DEG * 2 * Math.atan( + Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom ); + }, + getFilmWidth: function () { -/** - * Sets an offset in a larger frustum. This is useful for multi-window or - * multi-monitor/multi-machine setups. - * - * For example, if you have 3x2 monitors and each monitor is 1920x1080 and - * the monitors are in grid like this - * - * +---+---+---+ - * | A | B | C | - * +---+---+---+ - * | D | E | F | - * +---+---+---+ - * - * then for each monitor you would call it like this - * - * var w = 1920; - * var h = 1080; - * var fullWidth = w * 3; - * var fullHeight = h * 2; - * - * --A-- - * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); - * --B-- - * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); - * --C-- - * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); - * --D-- - * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); - * --E-- - * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); - * --F-- - * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); - * - * Note there is no reason monitors have to be the same size or in a grid. - */ -THREE.PerspectiveCamera.prototype.setViewOffset = function( fullWidth, fullHeight, x, y, width, height ) { + // film not completely covered in portrait format (aspect < 1) + return this.filmGauge * Math.min( this.aspect, 1 ); - this.aspect = fullWidth / fullHeight; + }, - this.view = { - fullWidth: fullWidth, - fullHeight: fullHeight, - offsetX: x, - offsetY: y, - width: width, - height: height - }; + getFilmHeight: function () { - this.updateProjectionMatrix(); - -}; - -THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function() { - - var near = this.near, - top = near * Math.tan( - THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom, - height = 2 * top, - width = this.aspect * height, - left = - 0.5 * width, - view = this.view; - - if ( view !== null ) { - - var fullWidth = view.fullWidth, - fullHeight = view.fullHeight; + // film not completely covered in landscape format (aspect > 1) + return this.filmGauge / Math.max( this.aspect, 1 ); - left += view.offsetX * width / fullWidth; - top -= view.offsetY * height / fullHeight; - width *= view.width / fullWidth; - height *= view.height / fullHeight; + }, - } - - var skew = this.filmOffset; - if ( skew !== 0 ) left += near * skew / this.getFilmWidth(); + /** + * Sets an offset in a larger frustum. This is useful for multi-window or + * multi-monitor/multi-machine setups. + * + * For example, if you have 3x2 monitors and each monitor is 1920x1080 and + * the monitors are in grid like this + * + * +---+---+---+ + * | A | B | C | + * +---+---+---+ + * | D | E | F | + * +---+---+---+ + * + * then for each monitor you would call it like this + * + * var w = 1920; + * var h = 1080; + * var fullWidth = w * 3; + * var fullHeight = h * 2; + * + * --A-- + * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); + * --B-- + * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); + * --C-- + * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); + * --D-- + * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); + * --E-- + * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); + * --F-- + * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); + * + * Note there is no reason monitors have to be the same size or in a grid. + */ + setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) { - this.projectionMatrix.makeFrustum( - left, left + width, top - height, top, near, this.far ); + this.aspect = fullWidth / fullHeight; -}; + this.view = { + fullWidth: fullWidth, + fullHeight: fullHeight, + offsetX: x, + offsetY: y, + width: width, + height: height + }; -THREE.PerspectiveCamera.prototype.copy = function( source ) { + this.updateProjectionMatrix(); - THREE.Camera.prototype.copy.call( this, source ); + }, - this.fov = source.fov; - this.zoom = source.zoom; + updateProjectionMatrix: function () { - this.near = source.near; - this.far = source.far; - this.focus = source.focus; + var near = this.near, + top = near * Math.tan( + THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom, + height = 2 * top, + width = this.aspect * height, + left = - 0.5 * width, + view = this.view; - this.aspect = source.aspect; - this.view = source.view === null ? null : Object.assign( {}, source.view ); + if ( view !== null ) { - this.filmGauge = source.filmGauge; - this.filmOffset = source.filmOffset; + var fullWidth = view.fullWidth, + fullHeight = view.fullHeight; - return this; + left += view.offsetX * width / fullWidth; + top -= view.offsetY * height / fullHeight; + width *= view.width / fullWidth; + height *= view.height / fullHeight; -}; + } -THREE.PerspectiveCamera.prototype.toJSON = function( meta ) { + var skew = this.filmOffset; + if ( skew !== 0 ) left += near * skew / this.getFilmWidth(); - var data = THREE.Object3D.prototype.toJSON.call( this, meta ); + this.projectionMatrix.makeFrustum( + left, left + width, top - height, top, near, this.far ); - data.object.fov = this.fov; - data.object.zoom = this.zoom; + }, - data.object.near = this.near; - data.object.far = this.far; - data.object.focus = this.focus; + toJSON: function ( meta ) { - data.object.aspect = this.aspect; + var data = THREE.Object3D.prototype.toJSON.call( this, meta ); - if ( this.view !== null ) data.object.view = Object.assign( {}, this.view ); + data.object.fov = this.fov; + data.object.zoom = this.zoom; + + data.object.near = this.near; + data.object.far = this.far; + data.object.focus = this.focus; + + data.object.aspect = this.aspect; + + if ( this.view !== null ) data.object.view = Object.assign( {}, this.view ); + + data.object.filmGauge = this.filmGauge; + data.object.filmOffset = this.filmOffset; + + return data; - data.object.filmGauge = this.filmGauge; - data.object.filmOffset = this.filmOffset; - - return data; + } -}; +} ); diff --git a/src/cameras/StereoCamera.js b/src/cameras/StereoCamera.js index 57a795d1f4ab9a67e7a033de8db409f056ced584..95262287bcd78ded789693d79bf2a46e9a8a2b0a 100644 --- a/src/cameras/StereoCamera.js +++ b/src/cameras/StereoCamera.js @@ -18,9 +18,7 @@ THREE.StereoCamera = function () { }; -THREE.StereoCamera.prototype = { - - constructor: THREE.StereoCamera, +Object.assign( THREE.StereoCamera.prototype, { update: ( function () { @@ -86,4 +84,4 @@ THREE.StereoCamera.prototype = { } )() -}; +} );