Advertisement

Rolling Sphere - Please help with my Rotation

Started by February 09, 2002 04:04 PM
2 comments, last by fallingbrickwork 23 years ago
Hi all, Could anyone help me solve a problem I''m having with Rotating a Sphere?? I''m trying to get a Sphere to Rotate using the Keyboard. The problem I''m having is....When you press the `Right` Rotate key the sphere rotates correctly (to the RIGHT). If you press the `Up` rotate key so the Sphere has rotated through 180 degress and then you press the `Right` rotate key, the Sphere rotates to the Left. This is due to the axis being flipped over. I''m trying to write a very simple `Move the ball through a maze type game (Marble Madness)`. I need the ball to always move / rotate in the direction of the pressed key. Cheers in advance for any help, P.S. I hope you could understand what I''m trying to ask!!!!
It could be I''m seeing something over the head here, but what about keeping track of the current rotation-degree, and rotate the other way if that degree is >180 ?
Newbie programmers think programming is hard.Amature programmers think programming is easy.Professional programmers know programming is hard.
Advertisement
ok.. this may help, or it may not

ok, first, I assume your using a vector to represent the axis rotation you want to do. thats good.

what you should do, is either grab the matrix of the object you are drawing, or you should keep a local copy and rotate it yourself... (how you do this is up to you) and before you apply the rotation, put the rotation vector through the matrix, to rotate it (be careful to aviod translation though) and then rotate using that new vector. your problem hopfully should be solved.
i believe the problem you are seeing is called ''gimble lock'', after 180deg. things get weird and your axis flip. i had a similar problem while trying to recreate devil dice. this is supposedly solvable by using quaternions for your rotations, but I''m not 100% on that ''cause i never actually finished the project - got sidetracked

there were a few good quaternion examples in the gamedev archives if I recall correctly.

hope that helps...
Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com

This topic is closed to new replies.

Advertisement