Advertisement

Still need help with my Rotating Sphere!!

Started by February 13, 2002 01:53 PM
8 comments, last by fallingbrickwork 23 years ago
Hi again, I''m still 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.
I think your answer lies
in the simple addition of
another set of
pushMatrix();
popMatrix();

this is NOT a tough problem to solve.
Advertisement
ie

glPushMatrix();		// Push Matrix Onto Stack 		glRotated(yrot,0,1,0);		glPushMatrix();	                    DRAWSPEHERE;                glPopMatrix();			glPopMatrix();	// Pop Matrix Off The Stack 
Thanks for the reply Anon.

I''ve tried what you said but the results weem the same....see below for what I''m doing......

void DrawBall(void)
{
// These two entries are required for creating and texturing spheres
GLUquadricObj *obj;
obj = gluNewQuadric();

// Create and texture the sphere
glPushMatrix();
glTranslatef(0.0f,0.0f,-2.0f);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glColor3f(0.8f, 0.8f, 0.8f);
glEnable(GL_TEXTURE_2D);
Tex1.SetActive();
gluQuadricTexture( obj, GL_TRUE );
gluSphere( obj, 0.2f, 20, 20);
glPopMatrix();
}

I''ve tried adding a second & third set of glPushMatrix(); & glPopMatrix(); commands in as many places as I can think, but get the same results.....where do you think??

Cheers again.


Well my suggestion would be to check to value of the rot variables and when they reach 180 set them back to 0 and so on...

hope that helps
Hi glnefugio,

I''ve just tried resetting the rot variable to 0 when it reaches 180, but it makes the object seem to jump/spin around about 180 degrees....do you have any other ideas?????


Cheers again.


Advertisement
hey fallingbrickwork (hereinafter known as fbw), I''m the guy that suggested the quaternions. I''ve been through the exact same thing you are going through. As far as I can figure it, quaternions are the EASIEST way to tackle this problem.

there are other ways to fudge it (creating a big list of possible rotations to cross reference for example, based on the current state of your object) but i would go with the quaternion rotations.

i still have to look into this myself, so if you want, i''ll start looking into it and send you anything i find out...

hope that helps...

Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com
I suppose your problems actually lie in the texture, since you wouldn''t see an effect like that when you just had a plain texture, would you? I haven''t yet studied texturing very much yet, but can''t you just position the texture over the sphere so that it looks like it''s fully rotating? I can imagine that you would rotate the sphere only up to 180 degrees, and then go back to 0 degrees. The only difference would have to be the position of the texture then, in order not to make it visibly go back to 0 degrees. You''d only have to put the texture on the other side of the sphere.
Newbie programmers think programming is hard.Amature programmers think programming is easy.Professional programmers know programming is hard.
Hi Jasonf,

Thanks for your reply.

Any help with regards to this type of rotation would be gratefully received. (email me).

I''ve been racking my brains over this axis problem for a couple of weeks now, trying different things.

Do you know of any very, very, simple examples/source code showing rotations acheived using matrices instead of the simple....

glPushMatrix();
glRotatef(......)
DrawYourObject();
glPopMatrix();

Thanks again,
fbw.
Here is an excellent faq on matrix mathmatics and interestingly enough, there is a section that explains the problems you get when using euler angles for your rotations.

http://skal.planet-d.net/demo/matrixfaq.htm

From what I just read, quaternions are the only way to do what we want. As I said, we can make it work other ways, but it won''t be simple rotation, as it should be. For instance, take the pips on a single die. You could store the top value and the value of the face facing the viewer - eg. The top value would be 1 and the front facing value would be 3. By making a table of rotations from the origin amount, and cross referencing the values you get, you would be able to achieve what you want (at least in terms of dice, but it applies to your sphere as well).

Straight from the faq...


rotation in the Z-axis is performed first and therefore
correctly. The Y-axis is also rotated correctly. However, after
rotation in the Y axis, the X-axis is rotated onto the Z-axis.

Thus, any rotation in the X-axis actually rotates the object in the Z-axis. Even worse, it becomes to rotate the object in the X-axis.

The only solution to this problem is to make use of Qaternions.

:j
Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com

This topic is closed to new replies.

Advertisement