Jump to content

Quaternion x Vector 3


magallanes
 Share

Recommended Posts

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;}
Link to comment
Share on other sites

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 matrix

Maybe I'm wrong, I'm not expert...

 

Your function could be more straight forward indeed.

Link to comment
Share on other sites

  • 1 year later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...