romainguy/kotlin-math

Include Quaternions?

Closed this issue · 5 comments

Hi,

I struggle with animations between 2 transform Matrix rotations.
I tried moving every Quaternions I was using to Float3 Euler Angles but, as expected, rotations animation between 2 Float3 sometimes generates wrong revolutions and that why Quaternions exists.

My question is:
Do you have any plan to introduce Mat4.quaternionRotation : Float4 and quaternionRotation(Float4) : Mat4 ?
And maybe some related functions like slerp or other Quaternion ones?

I understand that it could make things confusing by introducing another rotation system but I can't find a way to smooth multiple axis rotation changes with Euler Angles.

I think I already have those quaternion functions written somewhere and can PR them if you want.

Thanks

screen-20220113-002616.2.mp4

Given the right APIs, I would be happy to have quaternions in this library.

Ok. I'll make it.

Can you just tell me which wording you think would be the best at the Mat4 level?

  • rotation4
  • rotationQuaternion
  • quaternion
  • other

In one hand quaternion only describes rotation so we could remove the rotations world and in the other hand it's clearer to tell that it corresponds to the rotation.

We shouldn't need to override Float4 (even more cause we can't override data class) but putting a slerp function at the Float4 level may introduce a specific Quaternion function inside the multiple usage Float4.
Scalar should be the right place for specific functions?

Thanks for the amazing contribution!