Bläddra i källkod

Added PointerLockControls.getDirection()

WestLangley 12 år sedan
förälder
incheckning
4092b036f8
1 ändrade filer med 21 tillägg och 0 borttagningar
  1. 21 0
      examples/js/controls/PointerLockControls.js

+ 21 - 0
examples/js/controls/PointerLockControls.js

@@ -6,6 +6,8 @@ THREE.PointerLockControls = function ( camera ) {
 
 	var scope = this;
 
+	camera.rotation.set( 0, 0, 0 );
+
 	var pitchObject = new THREE.Object3D();
 	pitchObject.add( camera );
 
@@ -118,6 +120,25 @@ THREE.PointerLockControls = function ( camera ) {
 
 	};
 
+	this.getDirection = function() {
+
+		// assumes the camera itself is not rotated
+
+		var direction = new THREE.Vector3( 0, 0, -1 );
+		var rotation = new THREE.Euler( 0, 0, 0, "YXZ" );
+
+		return function( v ) {
+
+			rotation.set( pitchObject.rotation.x, yawObject.rotation.y, 0 );
+
+			v.copy( direction ).applyEuler( rotation );
+
+			return v;
+
+		}
+
+	}();
+
 	this.update = function ( delta ) {
 
 		if ( scope.enabled === false ) return;