Browse Source

Merge remote-tracking branch 'jsermeno/ortho' into dev

Mr.doob 14 years ago
parent
commit
a52637b892
1 changed files with 25 additions and 1 deletions
  1. 25 1
      src/core/Projector.js

+ 25 - 1
src/core/Projector.js

@@ -40,7 +40,7 @@ THREE.Projector = function() {
 		_projScreenMatrix.multiplyVector3( vector );
 
 		return vector;
-
+		
 	};
 
 	this.unprojectVector = function ( vector, camera ) {
@@ -49,7 +49,31 @@ THREE.Projector = function() {
 		_projScreenMatrix.multiplyVector3( vector );
 
 		return vector;
+		
+	};
+
+	/**
+	 * Translates a 2D point from NDC to a THREE.Ray
+	 * that can be used for picking.
+	 * @vector - THREE.Vector3 that represents 2D point
+	 * @camera - THREE.Camera
+	 */
+	this.pickingRay = function ( vector, camera ) {
+
+		var end, ray, t;
+
+		// set two vectors with opposing z values
+		vector.z = -1.0;
+		end = new THREE.Vector3( vector.x, vector.y, 1.0 );
+
+		this.unprojectVector( vector, camera );
+		this.unprojectVector( end, camera );
+
+		// find direction from vector to end
+		end.subSelf( vector ).normalize();
 
+		return new THREE.Ray( vector, end );
+		
 	};
 
 	this.projectObjects = function ( scene, camera, sort ) {