So I’ve always wondered if there was a simpler way to rotate a vector by Euler angles (for example to make moveWithCollisions behave like Space.LOCAL) than the Rube Goldberg contraption I like to use:
const vec = new Vector3(0, 0, velocity);
const quat = Quaternion.FromEulerAngles(0, mesh.rotation.y, 0);
let mat = Matrix.Zero();
quat.toRotationMatrix(mat);
const newVec = Vector3.TransformCoordinates(vec, mat);
mesh.moveWithCollisions(newVec);
I do this because neither Vector3.rotateByEulerAngles nor Matrix.FromEulerAngles are a thing.
It works and is still pretty fast, but is there any simpler way I’ve simply overlooked? Of course you can tuck it in a function, but it still bothers me somehow. There must be a better way to go about it, right?
edit: and of course you can build the rotation matrix yourself, with sines and cosines (IIRC), but that’s not really simpler!
Thank you! I was so focused on matrices I didn’t realize the ~Quaternion did have the coveted FromEulerAngles method ;)~ edit: of course I meant the
rotateByQuaternionToRef of course.
They really want us to use quaternions, huh? Time to stop procrastinating and finally learn the math behind them then.
Thank you! But I meant working with quaternions directly, like this. Maybe for a space game where you can move in all three dimensions that could be very useful.