magallanes Posted May 4, 2015 Share Posted May 4, 2015 Hi there: I did the next code to multiply a Quaternion per a Vector3 (Typescript) but im not sure if this function (or some similar) is already defined.function QuaxVector3 (quat:BABYLON.Quaternion,vec:BABYLON.Vector3):BABYLON.Vector3 { var num = quat.x * 2; var num2 = quat.y * 2; var num3 = quat.z * 2; var num4 = quat.x * num; var num5 = quat.y * num2; var num6 = quat.z * num3; var num7 = quat.x * num2; var num8 = quat.x * num3; var num9 = quat.y * num3; var num10 = quat.w * num; var num11 = quat.w * num2; var num12 = quat.w * num3; var result:BABYLON.Vector3=new BABYLON.Vector3(0,0,0); result.x = (1 - (num5 + num6)) * vec.x + (num7 - num12) * vec.y + (num8 + num11) * vec.z; result.y = (num7 + num12) * vec.x + (1 - (num4 + num6)) * vec.y + (num9 - num10) * vec.z; result.z = (num8 - num11) * vec.x + (num9 + num10) * vec.y + (1 - (num4 + num5)) * vec.z; return result;} Quote Link to comment Share on other sites More sharing options...
jerome Posted May 5, 2015 Share Posted May 5, 2015 What is it for ?A quaternion is AFAIK a way to figure a rotation angle around a rotation axis, isn't it ? I think we can already do the job with :var matrix = BABYLON.Matrix.RotationAxis(axis, angle); // creates the rotation matrix around the given axis for the given anglevar result = BABYLON.Vector3.TransformCoordinates(vec, matrix); // rotates vec according to this matrixMaybe I'm wrong, I'm not expert... Your function could be more straight forward indeed. Quote Link to comment Share on other sites More sharing options...
Klaas Posted November 25, 2016 Share Posted November 25, 2016 ... old but gold! This is a nice one and should definitly go into Vector3 or Queternion Class. 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.