Skip to content

Commit ccc554c

Browse files
committed
FirstPersonControls: Added lookAt()
1 parent 77adaa3 commit ccc554c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/js/controls/FirstPersonControls.js

Lines changed: 28 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,31 @@ THREE.FirstPersonControls = function ( object, domElement ) {
181182

182183
};
183184

185+
this.lookAt = function ( targetPosition ) {
186+
187+
this.object.lookAt( targetPosition );
188+
189+
setOrientation( this );
190+
191+
return this;
192+
193+
};
194+
195+
var lookDirection = new THREE.Vector3();
196+
var spherical = new THREE.Spherical();
197+
198+
function setOrientation( controls ) {
199+
200+
var quaternion = controls.object.quaternion;
201+
202+
lookDirection.copy( controls.forward ).applyQuaternion( quaternion );
203+
spherical.setFromVector3( lookDirection );
204+
205+
controls.lat = 90 - THREE.Math.radToDeg( spherical.phi );
206+
controls.lon = THREE.Math.radToDeg( spherical.theta );
207+
208+
}
209+
184210
this.update = function () {
185211

186212
var targetPosition = new THREE.Vector3();
@@ -297,4 +323,6 @@ THREE.FirstPersonControls = function ( object, domElement ) {
297323

298324
this.handleResize();
299325

326+
setOrientation( this );
327+
300328
};

0 commit comments

Comments
 (0)