SpaceToast Posted June 9, 2015 Share Posted June 9, 2015 What would be the most straightforward way to rotate a Vector3, by either an euler angle or a quaternion? I feel like there must be a simpler way than my ludicrous hack: Two invisible cubes, with the vector assigned to the child, the rotation assigned to the parent, and the difference taken between their positions in world space using .getAbsolutePosition(). Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 9, 2015 Share Posted June 9, 2015 Hello, Like this: http://www.babylonjs-playground.com/#FY4Q8 Here is the key code/** ROTATION */var m = new BABYLON.Matrix();q.toRotationMatrix(m); var v2 = BABYLON.Vector3.TransformCoordinates(sphere.position, m); Quote Link to comment Share on other sites More sharing options...
jerome Posted June 9, 2015 Share Posted June 9, 2015 even shorter, say we want to turn around Y axis for 90° var matrix = BABYLON.Matrix.RotationAxis(BABYLON.Axis.Y, Math.PI / 2);var v2 = BABYLON.Vector3.TransformCoordinates(sphere.position, matrix); Quote Link to comment Share on other sites More sharing options...
SpaceToast Posted June 10, 2015 Author Share Posted June 10, 2015 Thank you both. So to broaden Temechon's suggestion for the next newbie like myself, a simple function taking a vector and a quaternion and returning the vector rotated would be as follows:function rotateVector(vect, quat) { var matr = new BABYLON.Matrix(); quat.toRotationMatrix(matr); var rotatedvect = BABYLON.Vector3.TransformCoordinates(vect, matr); return rotatedvect;} 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.