Jump to content

Rotating a Vector


SpaceToast
 Share

Recommended Posts

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().

Link to comment
Share on other sites

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

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

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...