# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Posted: Fri Jun 22, 2012 11:26 pm

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
Hi,

Is it possible to convert the yaw Euler angle got from

trans.getBasis().getEulerYPR(rx, ry, rz);

into the range [0 , 360]. Otherwise for a 360 deg rotation I get the Euler angle varying from 0->90->0-> -90 -> 0

but I want from 0->90->180->270->0

This is the code I use now for getting the angle :

trans.getBasis().getEulerYPR(yaw, pitch, roll);
pitch = (pitch >= 0) ? pitch : (PI2 + pitch);

Here are some angle values :

Code:
Previous Angle(used to undo) | Modified Pitch | Bullet(Yaw, pitch, roll) | Angle applied to rotate body manually
0.00000 | 5.00000 | (0.00000, 5.00000, 0.00000) | 5.00000
-5.00000 | 10.00000 | (0.00000, 10.00000, 0.00000) | 10.00000
-10.00000 | 15.00000 | (0.00000, 15.00000, 0.00000) | 15.00000
-15.00000 | 20.00000 | (0.00000, 20.00000, 0.00000) | 20.00000
-20.00000 | 25.00000 | (0.00000, 25.00000, 0.00000) | 25.00000
-25.00000 | 30.00000 | (0.00000, 30.00000, 0.00000) | 30.00000
-30.00000 | 35.00000 | (0.00000, 35.00000, 0.00000) | 35.00000
-35.00000 | 40.00000 | (0.00000, 40.00000, 0.00000) | 40.00000
-40.00000 | 45.00000 | (0.00000, 45.00000, 0.00000) | 45.00000
-45.00000 | 50.00000 | (0.00000, 50.00000, 0.00000) | 50.00000
-50.00000 | 55.00000 | (0.00000, 55.00000, 0.00000) | 55.00000
-55.00000 | 59.99999 | (0.00000, 59.99999, 0.00000) | 59.99999
-59.99999 | 64.99999 | (0.00000, 64.99999, 0.00000) | 64.99999
-64.99999 | 70.00001 | (0.00000, 70.00001, 0.00000) | 69.99999
-70.00001 | 74.99999 | (0.00000, 74.99999, 0.00000) | 74.99999
-74.99999 | 80.00001 | (0.00000, 80.00001, 0.00000) | 79.99999
-80.00001 | 85.00002 | (0.00000, 85.00002, 0.00000) | 84.99999                          <------------------ increasing
-85.00002 | 89.98022 | (0.00000, 89.98022, 0.00000) | 89.99999                          <------------------ decreasing
-89.98022 | 85.00002 | (180.00001, 85.00002, 180.00001) | 94.99999               <------------------ decreasing
-85.00002 | 80.00001 | (180.00001, 80.00001, 180.00001) | 99.99999
-80.00001 | 75.00003 | (180.00001, 75.00003, 180.00001) | 104.99999
-75.00003 | 70.00001 | (180.00001, 70.00001, 180.00001) | 109.99998
-70.00001 | 65.00001 | (180.00001, 65.00001, 180.00001) | 114.99999
-65.00001 | 59.99999 | (180.00001, 59.99999, 180.00001) | 119.99999
-59.99999 | 55.00001 | (180.00001, 55.00001, 180.00001) | 124.99999
-55.00001 | 50.00001 | (180.00001, 50.00001, 180.00001) | 129.99999
-50.00001 | 45.00001 | (180.00001, 45.00001, 180.00001) | 134.99999
-45.00001 | 40.00002 | (180.00001, 40.00002, 180.00001) | 139.99999
-40.00002 | 35.00001 | (180.00001, 35.00001, 180.00001) | 144.99998
-35.00001 | 30.00002 | (180.00001, 30.00002, 180.00001) | 149.99998
-30.00002 | 25.00002 | (180.00001, 25.00002, 180.00001) | 154.99998
-25.00002 | 20.00002 | (180.00001, 20.00002, 180.00001) | 159.99998
-20.00002 | 15.00002 | (180.00001, 15.00002, 180.00001) | 164.99998
-15.00002 | 10.00002 | (180.00001, 10.00002, 180.00001) | 169.99998
-10.00002 | 5.00002 | (180.00001, 5.00002, 180.00001) | 174.99998
-5.00002 | 0.00002 | (180.00001, 0.00002, 180.00001) | 179.99998
-0.00002 | 355.00001 | (180.00001, -4.99998, 180.00001) | 184.99998
-355.00001 | 350.00001 | (180.00001, -9.99998, 180.00001) | 189.99998
-350.00001 | 345.00001 | (180.00001, -14.99997, 180.00001) | 194.99997
-345.00001 | 340.00001 | (180.00001, -19.99997, 180.00001) | 199.99997
-340.00001 | 335.00002 | (180.00001, -24.99997, 180.00001) | 204.99997
-335.00002 | 330.00002 | (180.00001, -29.99997, 180.00001) | 209.99997
-330.00002 | 325.00004 | (180.00001, -34.99997, 180.00001) | 214.99997
-325.00004 | 320.00002 | (180.00001, -39.99997, 180.00001) | 219.99997
-320.00002 | 315.00002 | (180.00001, -44.99997, 180.00001) | 224.99997
-315.00002 | 310.00002 | (180.00001, -49.99998, 180.00001) | 229.99998
-310.00002 | 305.00002 | (180.00001, -54.99998, 180.00001) | 234.99998
-305.00002 | 300.00002 | (180.00001, -59.99998, 180.00001) | 239.99998
-300.00002 | 295.00002 | (180.00001, -64.99998, 180.00001) | 244.99998
-295.00002 | 290.00002 | (180.00001, -69.99998, 180.00001) | 249.99998
-290.00002 | 285.00000 | (180.00001, -75.00000, 180.00001) | 254.99998
-285.00000 | 280.00000 | (180.00001, -80.00001, 180.00001) | 259.99998
-280.00000 | 275.00003 | (180.00001, -84.99998, 180.00001) | 264.99997
-275.00003 | 270.00000 | (0.00000, -90.00000, 0.00000) | 269.99997
-270.00000 | 274.99997 | (0.00000, -85.00002, 0.00000) | 274.99997
-274.99997 | 279.99997 | (0.00000, -80.00003, 0.00000) | 279.99997
-279.99997 | 284.99997 | (0.00000, -75.00003, 0.00000) | 284.99997
-284.99997 | 289.99997 | (0.00000, -70.00004, 0.00000) | 289.99997
-289.99997 | 294.99997 | (0.00000, -65.00003, 0.00000) | 294.99997
-294.99997 | 299.99997 | (0.00000, -60.00003, 0.00000) | 299.99997
-299.99997 | 304.99997 | (0.00000, -55.00003, 0.00000) | 304.99997
-304.99997 | 309.99997 | (0.00000, -50.00004, 0.00000) | 309.99997
-309.99997 | 314.99996 | (0.00000, -45.00004, 0.00000) | 314.99996
-314.99996 | 319.99996 | (0.00000, -40.00004, 0.00000) | 319.99996
-319.99996 | 324.99996 | (0.00000, -35.00004, 0.00000) | 324.99996
-324.99996 | 329.99996 | (0.00000, -30.00004, 0.00000) | 329.99996
-329.99996 | 334.99996 | (0.00000, -25.00004, 0.00000) | 334.99996
-334.99996 | 339.99996 | (0.00000, -20.00004, 0.00000) | 339.99996
-339.99996 | 344.99996 | (0.00000, -15.00004, 0.00000) | 344.99996
-344.99996 | 349.99996 | (0.00000, -10.00004, 0.00000) | 349.99996
-349.99996 | 354.99996 | (0.00000, -5.00004, 0.00000) | 354.99996
-354.99996 | 359.99996 | (0.00000, -0.00004, 0.00000) | 359.99996
-359.99996 | -0.00000 | (0.00000, -0.00000, 0.00000) | 0.00000
0.00000 | 5.00000 | (0.00000, 5.00000, 0.00000) | 5.00000

The Bullet values are in the fat middle column. The problem lies in the sudden decrease in the angle values as we cross 90 degrees. This causes my mesh to rotate backwards after 1/4th turn.

Top

 Posted: Sun Jun 24, 2012 7:19 am

Joined: Tue Dec 25, 2007 1:06 pm
Posts: 348
Don't know if it's helpful, but if you can avoid using the methods provided by btMatrix3x3 in your project, you can try something like:
Code:
// The return value is in RADIANS: to get it in degrees use btDegrees(GetYawFromBasis(T.getBasis()));
static btScalar GetYawFromBasis(const btMatrix3x3& m)   {
// Extremely cut down version from the Ogre Source Code (OgreMatrix3.cpp) [ToEulerYXZ(...)]
btScalar value;
const btScalar rfPAngle = btAsin(-m[1][2]);
if ( rfPAngle < SIMD_HALF_PI )   {
if ( rfPAngle > -SIMD_HALF_PI ) value = btAtan2(m[0][2],m[2][2]);
else value = -btAtan2(-m[0][1],m[0][0]);
}
else value = btAtan2(-m[0][1],m[0][0]);
return value;
}

I'm not sure this method will work in your case, because it depends on the order of rotations you're using (the code I've posted refers to the YXZ order).
Should it work, you can find further info/methods in this old post http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=3940&hilit=Ogre.

Top

 Posted: Mon Jun 25, 2012 9:34 pm

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
Thanks Flix. Will try that out

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Google [Bot] and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities