PDA

View Full Version : Need help with Rotating my Sphere??



fallingbrickwork
02-13-2002, 10:33 AM
Hi all,

I'm having trouble rotating a sphere using the keys!!!
My problem is this:

When you press the `Rotate Right` Key the sphere rotate right (Y-Axis) which is correct.

When you press the `Rotate Up` Key the sphere rotate upwards (X-Axis) which is correct.

But,

If the sphere has rotate through 180 degrees upwards or downwards, the `Rotate Right` Key rotates Left. This is due to the Axis being flipped. How can I get around this?? I'm writing a very basic `Top View (Looking down)` move the ball through the maze type game.

I want the ball to always rotate in the direction of the key press.

I've heared something about `quaternion` <-spelling???? and 'gimble lock',is this the answer!? I fear these are abit over my head!!!! Is it possible to fix my problem cleverly using glRotate ?? Do you know of any example source showing something similar???

Many thanks in advance.

Mr_Smith
02-13-2002, 02:30 PM
just add limiters so once it has rotated 180 deg it goes back to -180 deg (add this on all axis and it should work)

mmcoder
02-16-2002, 09:20 PM
Easy - don't use glrotate for this. if glrotate had the form glrotate(x angle, y angle, z angle) it would work fine, however it does not. This is not "gimbal lock" although it could get that way quickly. (quaternions do solve that) This is a problem of glrotate taking a point in 3D as input, which itself is rotated by a previous glrotate. Trust me, try concatting your own rotation matrices and tell me it doesn't work. This should really be a kind of FAQ hall of fame question, it comes up in some form every time I visit this message board, and oddly I'm the only one giving this answer (in my experience.)

davepermen
02-17-2002, 01:32 AM
glrotate is an axis-angle rotation, not a yet rotated point in 3d or what ever.
it rotates around the in current space defined axis (x,y,z) around the defined angle.

knackered
02-17-2002, 02:45 AM
fallingbrickwork,
I'm not trying to be funny, but why did you post this in the advanced forum?
Do you own the OpenGL Programming Guide?
Have you read any books on 3d graphics?
Have you noticed the "search" link at the top of this page?
I'm genuinely interested in the effort you made to solve this problem on your own before posting this question in the advanced opengl forum.
You'll get a proper answer to your question if you read up on the subject of 3d graphics - it's not an opengl problem or question.
I'm sorry if this sounds harsh, but the value of having two seperate forums, beginners and advanced, is being deminished with every question posted here like this.
I've noticed that some 'frequent contributors', people who know a hell of a lot about opengl, have stopped contributing to this forum, which is a shame, but not surprising.
This is the last time I will criticise someone elses post. Forgive me.

fallingbrickwork
02-17-2002, 03:28 AM
Thank you for all your replies (except knackered!)

What is the point of posting a reply like that?? Are you trying to help or hinder someone with a genuine problem?? Surely encouragement towards someone who knows less than you is always nicer!!! So, I posted the question on the incorrect forum (in your opinion!?), I should of used the `beginners` one. The other people who replied to my post didn't seem to mind - or they managed to keep it to themselves!. Sorry if my posted question seemed a bit to trivial for the `advanced` board!!

Thanks again for the answers posted.

davepermen
02-17-2002, 04:32 AM
don't take knackered too personal. he's just a bit annoyed to see the same questions over and over again. but that is how a forum works http://www.opengl.org/discussion_boards/ubb/smile.gif

knackered: if you're bored by the post, don't reply.

and don't forget knacky, starting into rotations in 3d is a difficult part, really difficult. thats why all move into the advanced forum for it. because they got the basics, means they know how to get stuff correct on screen. don't say quaternions or matrices for rotations are an easy topic http://www.opengl.org/discussion_boards/ubb/wink.gif

knackered
02-17-2002, 06:40 AM
Look brick, I don't want to get into some kind of flame war with you, that's why I thought carefully about what I said - as dave says, I've read many post like yours.
This is why I said:-
"I'm genuinely interested in the effort you made to solve this problem on your own before posting this question in the advanced opengl forum."

Because I want to get *something* out of the time it took me to read your post. You haven't answered my question.

BTW, dave: "he's just a bit annoyed to see the same questions over and over again. but that is how a forum works"
It's not the way a forum *should* work. That's the purpose of a search engine.
Brick, even if you don't want to take advantage of the opengl.org search facility, you can go to "google groups" which is superb at finding answers to questions that have been asked over and over again.
I understand that you want the personal touch in the answers to your questions, and maybe some people like to answer questions that have been asked many times before, but it's wise to assume that most people will be annoyed that you patently haven't put any effort into finding the answer yourself.
In an effort to actually answer your question in (what I believe) is the best way, I must refer you to somewhere like http://www.drmath.com

[This message has been edited by knackered (edited 02-17-2002).]

satan
02-17-2002, 02:40 PM
i nearly don't dare to ask (since i am a newbie, too)
when i got it right the answer to the rotation question was this link to a math page
i think this means forget glrotate and do it on your own (which is not the problem since i know the math for such stuff)
but what the hell is glrotate good for then?
i thought i have to calculate this rotation stuff just for my camera (which works really fine: 6dof no gimbal lock, no quaternions) but now it looks like i have to do it for all objects i want to rotate about local axis (which are in fact all objects!!!)
did i get this right? (and i know this is the wrong forum but the topic was started here)

and please don't flame me to heaven http://www.opengl.org/discussion_boards/ubb/wink.gif

[This message has been edited by satan (edited 02-17-2002).]