Simple RotateF problem [now with program link]
I am trying to use this code:
glPushMatrix();
glEnable(GL_LIGHTING);
glTranslatef(sphere_x,sphere_y,sphere_z);
glRotatef(xspin,1.0f,0.0f,0.0);
glRotatef(zspin,0.0f,0.0f,1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TextureArray[1]);
glColor3f(1.0f, 1.0f, 1.0f);
gluSphere(q, 0.35f, 32, 16);
glPopMatrix();
the problem is that I am trying to rotate the ball when it moves in a certain direction. For example when it moves along the X the ball will rotate on its X axis to make it look like the ball was rolling.
Now this is all fine for when the ball rolls along the X axis but when I move along the Z axis it rotates on the balls modified z. Not the Z of the scene.
(Believe me its as hard to explain as it is to understand) Its like I need to load identity or something between the rotatefs but obviously this does not work.
I am pretty much out of ideas at this point, can anyone help?
[Edited by - Groberts on November 30, 2005 5:55:58 AM]
ok, I'll take a stab. it seems to me what you want to do is first figure out the direction the ball needs to roll in the X/Z plane. direction = atan2(z,x), something like that. Then, rotate the ball around the Y axis (yes I mean Y axis) by this amount so that Z is pointing along the direction of travel. Then, rotate around the X axis an amount based on how far it should move, which you can figure out based on the ratio of the distance of travel in X/Z over the circumference of the sphere * 360.0. There would be no rotation around the Z axis. Be sure to convert radians and degrees properly.
Nice one for the reply its a nice way of looking at it, but does anyone know of a easier way?
Unfortunately, relative transformations in 3D can be a real brute unless you know good and well what you are doing. Using some "find the angle to a point" math and some simple rotation values, you can do it fairly easily.
In order to know how polar coordinates are expressed in 3D space, do a search on Google for the word "Azimuth"
Using an "Out Vector" and an "Up Vector," you can express any direction in 3D. Finding the rotation values needed to put the out straight ahead and the up straight up (Azimuth, Elevation and Roll), you'll be able to apply a third vector using the transformations of your choosing. Tracing your steps backwards by using your previously-found rotation values, you can supply coordinates and a direction that will be relative to the original values.
This is what you need to do in order to make your ball roll forwards, bounce, etc.
It's a simple concept if you get to understanding it, but I appologize for being unable to express it any more clearly in such a small post. I should write a detailed tutorial of how to do this.
Any takers? I'll be doing this shortly for a project I'm working on, so I may as well document how I do it.
In order to know how polar coordinates are expressed in 3D space, do a search on Google for the word "Azimuth"
Using an "Out Vector" and an "Up Vector," you can express any direction in 3D. Finding the rotation values needed to put the out straight ahead and the up straight up (Azimuth, Elevation and Roll), you'll be able to apply a third vector using the transformations of your choosing. Tracing your steps backwards by using your previously-found rotation values, you can supply coordinates and a direction that will be relative to the original values.
This is what you need to do in order to make your ball roll forwards, bounce, etc.
It's a simple concept if you get to understanding it, but I appologize for being unable to express it any more clearly in such a small post. I should write a detailed tutorial of how to do this.
Any takers? I'll be doing this shortly for a project I'm working on, so I may as well document how I do it.
yeh mate new tutorials are allways good.
If anyone is interested in my actual program. Here it is. All started from nehe lesson 5 and using no fancy vector maths. Which is why I am keen to avoid using them now for something so simple.
Click here to download my little prog!
If anyone is interested in my actual program. Here it is. All started from nehe lesson 5 and using no fancy vector maths. Which is why I am keen to avoid using them now for something so simple.
Click here to download my little prog!
December 03, 2005 11:53 PM
Maybe you should distribute the Glut.dll with it, or indicate its use in the application
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement