[Plib-users] RE: Problem with rotations
Brought to you by:
sjbaker
From: McEvoy, N. <nic...@ds...> - 2002-09-11 00:23:06
|
Ben Woodhead wrote: >As you can see in pitch when it hits 90 on pitch, role also >goes to 90. The one thing that I just noticed is that non of >the other rotations get to exactly 90.0. >Any ideas, thanks for all your help steve. You really gotta take Steve's advice on this ... it is gymbal lock ... read and understand those links he mentioned. :-) I had the same trouble when I started with matrices ... it drove me crazy (and still does) ... my model flipped all over the place when I hit 90 pitch ... I even tried Quats (eg. sgHPRToQuat) ... which (I thought) should avoid the problem ... but unfortunately I couldn't get them to work either ... I'm still not sure why !? I now use ODE (a physics engine) and PLIB for the graphics. ODE does all the rotation work for me and avoids the 'gymbal lock' problem ... but before I found ODE I did fix the problem you are having by doing the following (notice I never let the pitch hit exactly 90) ... // If the eyepoint it pitched by 90 degrees - then roll and heading do the same // thing and the whole thing goes crazy ... so ensure we never point exactly 90. if (mPosition.hpr[1] == 90.0f) mPosition.hpr[1] -= 0.2f; if (mPosition.hpr[1] == -90.0f) mPosition.hpr[1] += 0.2f; // Update player hpr sgMat4 POS, ROT; sgMakeCoordMat4(POS, &mPosition); sgMakeRotMat4(ROT, mDirChange); sgPreMultMat4(POS, ROT); sgSetCoord(&mPosition, POS); I hope that helps. Good luck ! Nick http://members.ozemail.com.au/~ndmcevoy/ |