Skip to content

Commit 6f6c056

Browse files
committed
optimized getWorldDirection
1 parent e8443b2 commit 6f6c056

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/cameras/Camera.js

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

3838
},
3939

40-
getWorldDirection: function () {
40+
getWorldDirection: function ( target ) {
4141

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

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

46-
if ( target === undefined ) {
47+
}
4748

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

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

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

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

6157
updateMatrixWorld: function ( force ) {
6258

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)