Reputation: 41
I have a mesh with an added THREE.AxisHelper. The mesh rotate and traslate into the world and i need to know the direction of the mesh x axis at a given time.
Upvotes: 1
Views: 906
Reputation: 41
based on WestLangley resp., I have written this function:
this.dirAirplane = new THREE.Vector3();
...
this.takeDir = function(){
var quaternion = new THREE.Quaternion();
this.mesh.getWorldQuaternion( quaternion );
this.dirAirplane.set(1,0,0).applyQuaternion(quaternion);
}
Thanks
Upvotes: 1
Reputation: 104833
Create a new method by copying the source code of Object3D.getWorldDirection()
.
getWorldDirection: function () {
var quaternion = new Quaternion();
return function getWorldDirection( optionalTarget ) {
var result = optionalTarget || new Vector3();
this.getWorldQuaternion( quaternion );
return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
};
}(),
and replace the z-axis ( 0, 0, 1 )
with the the x-axis ( 1, 0, 0 )
.
For efficiency, when you use the method, you can pass in the optionalTarget
so a new Vector3
is not allocated every time the method is called.
three.js r.80
Upvotes: 1