Browse Source

Merge pull request #14685 from WestLangley/dev-camera_pmi

Camera: added projectionMatrixInverse property
Mr.doob 7 years ago
parent
commit
67a4893527

+ 3 - 0
docs/api/cameras/Camera.html

@@ -55,6 +55,9 @@
 		<h3>[property:Matrix4 projectionMatrix]</h3>
 		<p>This is the matrix which contains the projection.</p>
 
+		<h3>[property:Matrix4 projectionMatrixInverse]</h3>
+		<p>The inverse of projectionMatrix.</p>
+
 
 		<h2>Methods</h2>
 		<p>See the base [page:Object3D] class for common methods.</p>

+ 4 - 0
src/cameras/Camera.js

@@ -15,7 +15,9 @@ function Camera() {
 	this.type = 'Camera';
 
 	this.matrixWorldInverse = new Matrix4();
+
 	this.projectionMatrix = new Matrix4();
+	this.projectionMatrixInverse = new Matrix4();
 
 }
 
@@ -30,7 +32,9 @@ Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
 		Object3D.prototype.copy.call( this, source, recursive );
 
 		this.matrixWorldInverse.copy( source.matrixWorldInverse );
+
 		this.projectionMatrix.copy( source.projectionMatrix );
+		this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
 
 		return this;
 

+ 2 - 0
src/cameras/OrthographicCamera.js

@@ -119,6 +119,8 @@ OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 		this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
 
+		this.projectionMatrixInverse.getInverse( this.projectionMatrix );
+
 	},
 
 	toJSON: function ( meta ) {

+ 3 - 2
src/cameras/PerspectiveCamera.js

@@ -189,8 +189,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 	updateProjectionMatrix: function () {
 
 		var near = this.near,
-			top = near * Math.tan(
-				_Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
+			top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
 			height = 2 * top,
 			width = this.aspect * height,
 			left = - 0.5 * width,
@@ -213,6 +212,8 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 		this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
 
+		this.projectionMatrixInverse.getInverse( this.projectionMatrix );
+
 	},
 
 	toJSON: function ( meta ) {