-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to determine vector of Object3D (where it is facing) #1606
Comments
I think this is what you're after: var matrix = new THREE.Matrix4();
matrix.extractRotation( mesh.matrix );
var direction = new THREE.Vector3( 0, 0, 1 );
matrix.multiplyVector3( direction ); |
wow..thanks for the quick response... Stupid question 1: Stupid question 2: |
Ray expects a |
duh....I didn't realize that the multipleVector3 function returned results...I assumed it modified the original matrix. |
Indeed. It wasn't too clear. Perhaps this makes it more obvious: var matrix = new THREE.Matrix4();
matrix.extractRotation( mesh.matrix );
var direction = new THREE.Vector3( 0, 0, 1 );
direction = matrix.multiplyVector3( direction ); |
no worries..thanks again for a FANTASTIC library. I haven't had this much fun coding in years.... |
:D |
Related question... how can I set the direction an object is facing based on a Vector3? I am using cylinder primitives, making them into cones, translating them outward. I want them all to point to (0,0,0). Is there something like... geometry.applyMatrix( new THREE.Matrix4().makeRotationFromVector3(Vector3) ); ? |
Also remember an example of this in the docs that seems to have disappeared. A sphere would drift through a field of cones. |
As stated in the guidelines, help requests should be directed to stackoverflow. This board is for bugs and feature requests. |
This is a super old and also closed issue, but as a relative 3D newcomer this was the only real answer to this same problem I found after quite a while of searching and trying. Maybe it would make sense to have a helper function on |
This is an old thread but I thought I'd still give a little input for everyone finding this now. A clean solution based on quaternions would be this: var direction = new Vector3( 0, 0, -1 ).applyQuaternion( mesh.quaternion ); Comes in very handy if you want the direction the camera is looking for instance. 📷 |
@MathiasPaumgarten var vector = new THREE.Vector3(); // create once and reuse it!
...
camera.getWorldDirection( vector ); See this post. |
My goal is to create a ray with my object's position x,y.z as the origin and pointing ...well...out the 'front' of my object......
I know each Object3D has a "rotation vector" (x y and z are in radians I thnk) . How can I convert that to a 'directional' vector to use as the 'direction' in my ray? Or is there some other gem hidden in the Object3D that I can pull out that already has this vector?
The text was updated successfully, but these errors were encountered: