Skip to content

Commit 4febda5

Browse files
committed
FirstPersonControls: Added .setOrientation()
1 parent 77adaa3 commit 4febda5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

examples/js/controls/FirstPersonControls.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
3030
this.verticalMax = Math.PI;
3131

3232
this.autoSpeedFactor = 0.0;
33+
this.forward = new THREE.Vector3( 0, 0, - 1 );
3334

3435
this.mouseX = 0;
3536
this.mouseY = 0;
@@ -181,6 +182,25 @@ THREE.FirstPersonControls = function ( object, domElement ) {
181182

182183
};
183184

185+
this.setOrientation = function () {
186+
187+
var lookDirection = new THREE.Vector3();
188+
var spherical = new THREE.Spherical();
189+
190+
return function setOrientation( quaternion ) {
191+
192+
lookDirection.copy( this.forward ).applyQuaternion( quaternion );
193+
spherical.setFromVector3( lookDirection );
194+
195+
this.lat = 90 - THREE.Math.radToDeg( spherical.phi );
196+
this.lon = THREE.Math.radToDeg( spherical.theta );
197+
198+
return this;
199+
200+
};
201+
202+
}();
203+
184204
this.update = function () {
185205

186206
var targetPosition = new THREE.Vector3();

0 commit comments

Comments
 (0)