Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quaternions instability #211

Open
CoWayger opened this issue Jul 9, 2015 · 2 comments
Open

Quaternions instability #211

CoWayger opened this issue Jul 9, 2015 · 2 comments

Comments

@CoWayger
Copy link

CoWayger commented Jul 9, 2015

Hello I'm trying to connect my game engine in WebGL to cannon.js, but I have a trouble to convert your quaternions to euler angles. (I'm using euler angles, I never had the problem until I faced quaternions)

Function on Quaternion.js toEuler provides very unstable angles. They are ok in x axis. But y and z are behaving weird. I captured it on video. It is very noticeable on the end of video. http://youtu.be/ljd4avOFPs4 If you know where the problem could be please let me know. Thank you :)

@schteppe
Copy link
Owner

Maybe the euler order is wrong? What order do you use in your rendering engine?

In any case, it is often more convenient to not use euler. Use the quaternion directly or convert it to a rotation matrix.

@CoWayger
Copy link
Author

I tried all 6 permutations of xyz order, none of them works stable.
I woke up today and try different aproach... searched for formulas on internet:
These works perfectly:

function quatToVec3(x,y,z,w){
var ax = Math.atan2(-2_y_z+2_x_w,1-2_x_x-2_y_y);
var ay = Math.asin(2_x_z+2_y_w);
var az = Math.atan2(-2_x_y+2_z_w,1-2_y_y-2_z_z);
return [ax,ay,az];
}

It's for XYZ order. Someone will be happy if you add this order to cannon.js. Anyway thank you for awesome physics library! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants