marco leon
marco leon

Reputation: 41

how do i know the direction (unit vector) from an axis of THREE.AxisHelper?

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

Answers (2)

marco leon
marco leon

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

WestLangley
WestLangley

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

Related Questions