Skip to content

Commit 621da77

Browse files
committed
optimized getWorldDirection
1 parent e8443b2 commit 621da77

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

src/cameras/Camera.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { Matrix4 } from '../math/Matrix4.js';
8-
import { Quaternion } from '../math/Quaternion.js';
98
import { Object3D } from '../core/Object3D.js';
109
import { Vector3 } from '../math/Vector3.js';
1110

@@ -37,26 +36,22 @@ Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
3736

3837
},
3938

40-
getWorldDirection: function () {
39+
getWorldDirection: function ( target ) {
4140

42-
var quaternion = new Quaternion();
41+
if ( target === undefined ) {
4342

44-
return function getWorldDirection( target ) {
43+
console.warn( 'THREE.Camera: .getWorldPosition() target is now required' );
44+
target = new Vector3();
4545

46-
if ( target === undefined ) {
46+
}
4747

48-
console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
49-
target = new Vector3();
48+
this.updateMatrixWorld( true );
5049

51-
}
50+
var e = this.matrixWorld.elements;
5251

53-
this.getWorldQuaternion( quaternion );
52+
return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
5453

55-
return target.set( 0, 0, - 1 ).applyQuaternion( quaternion );
56-
57-
};
58-
59-
}(),
54+
},
6055

6156
updateMatrixWorld: function ( force ) {
6257

src/core/Object3D.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -506,26 +506,22 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
506506

507507
}(),
508508

509-
getWorldDirection: function () {
509+
getWorldDirection: function ( target ) {
510510

511-
var quaternion = new Quaternion();
512-
513-
return function getWorldDirection( target ) {
514-
515-
if ( target === undefined ) {
511+
if ( target === undefined ) {
516512

517-
console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
518-
target = new Vector3();
513+
console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
514+
target = new Vector3();
519515

520-
}
516+
}
521517

522-
this.getWorldQuaternion( quaternion );
518+
this.updateMatrixWorld( true );
523519

524-
return target.set( 0, 0, 1 ).applyQuaternion( quaternion );
520+
var e = this.matrixWorld.elements;
525521

526-
};
522+
return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
527523

528-
}(),
524+
},
529525

530526
raycast: function () {},
531527

0 commit comments

Comments
 (0)