schteppe / cannon.js

A lightweight 3D physics engine written in JavaScript.
http://schteppe.github.com/cannon.js
MIT License
4.63k stars 700 forks source link

Quaternion to Euler conversion #447

Open TheSonOfThomp opened 4 years ago

TheSonOfThomp commented 4 years ago

I've noticed that the order the Euler angles are applied does not match between quaternion.toEuler and quaternion.setFromEuler. For example, this code should do nothing, however it ends up rotating the body. When I pass the optional order param to setFromEuler as 'YZX' I achieve the desired result (i.e. no rotation in this case).

const euler = new CANNON.Vec3(0,0,0)
body.quaternion.toEuler(euler)
body.quaternion.setFromEuler(euler.x, euler.y, euler.z) // does not work
body.quaternion.setFromEuler(euler.x, euler.y, euler.z, 'YZX') // works

It seems like the default order does not match between toEuler and setFromEuler

Also, small request: can we have toEuler return the vector instead of passing a variable in by reference?

d3x0r commented 3 years ago

toEuler only supports one decode mode... and it's hard coded to only use that one order...

TheSonOfThomp commented 3 years ago

@d3x0r I understand that toEuler only supports the one order. My concern is that the order isn't consistent with the default order in setFromEuler. It's simple to work around sure, but I feel like the API design should be internally consistent