altreality Posted January 31, 2015 Share Posted January 31, 2015 Hi, If I have 2 points in 3D space and I want to orient a mesh along the line joining them, how can I achieve this ? Say my points are (0,1,0) & (5, 0, 5). I see there are many ways to rotate a mesh around a particular axis but is there a way to orient it along a given direction vector by specifying just the vector ? Quote Link to comment Share on other sites More sharing options...
jerome Posted January 31, 2015 Share Posted January 31, 2015 var axis = point2.subtract(point1) ;gives you the vector defined by your 2 points then you could create a rotation matrixvar rotationMatrix = BABYLON.Matrix.RotationAxis(axis, 0);At last, you can apply this matrix to what you want ...BABYLON.Vector3.TransformCoordinates(meshVector, rotationMatrix); Wingnut and altreality 2 Quote Link to comment Share on other sites More sharing options...
altreality Posted January 31, 2015 Author Share Posted January 31, 2015 wow, thats neat !! Thanks Quote Link to comment Share on other sites More sharing options...
altreality Posted January 31, 2015 Author Share Posted January 31, 2015 Whats the meshVector exactly ? Is it the current orientation of the mesh ? How do I get it ? How do I apply this rotation matrix to a mesh ? Quote Link to comment Share on other sites More sharing options...
jerome Posted January 31, 2015 Share Posted January 31, 2015 meshVector is the vector you want then to rotateit was just an example if you want to rotate a full mesh, you should use mesh.rotation (// Euler) : https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translationsyour axis is the vector3 to be used with rotation in the documentation Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.