I’ve got SEVERE problems with sheres rolling around on planes.

My first thought was: This must be a piece of cake. But it turned out to be much more complex than I thought (or I’m just too stupid.)

I figured out now that I must somehow store the old angular position and for the next frame rotate it again aroung the new rotation axis.
So I get the rotation matrix with

glGet(GL_MODELVIEW_MATRIX, matrix)

and load it in the next frame with

glLoadMatrix.

But that doesn’t help because the new rotation is obviously done around the local axis of the sphere although the matrix that I get with glGet is obviously that from the perspective projection because the translate y-values change while I move around in a plane parallel to the x-y-plane and the Sphere even moves when I move my “camera” so that it stays in the center of the screen.

I think that I got my whole PopMatrix()/PushMatrix()-structure all messed up.

Please help:
How can I rotate an Object around any axis between x and z IN WORLD COORDINATES and “store” its rotation so that afterwards it behaves like it was never rotated and I can rotate it again around any axis between x and z IN WORLD COORDINATES ???

If that looks as confisung to you as it looks to me:

How the hell can I get a Sphere to look like it would roll on a plane when the plane is the x-z-plane and the camera looks down on it?
btw. the pure movement is no problem, that works.

OK, since your modelview matrix is going to reflect your camera’s position as well as that of your sphere, I suggest you store a seperate matrix for your sphere, and then push the MV matrix, mul in the sphere matrix then draw the sphere. Now, with the sphere’s coordinate transform seperate from the camera’s view, you can manipulate the sphere accordingly. If you wish to rotate the sphere WRT its own coordinates, create the appropriate rotation matrix, multiply it by your sphere’s matrix, store that as the new sphere’s matrix, and then multiply that in with the modelview matrix when you draw it.

If you don’t want to hand-calculate the matrix for the rotation, then you can push the MV matrix, set it to identity, perform the rotation, then glGet() the matrix, but since all the matrix math is very well documented, I suggest you not do this.

Thanks for the answer.
I already thought of that but I thought I could do it by pushing, loading the old matrix and then rotating.
But the problem is that i’ve already translated by then.
I’ll try your suggestion tomorrow.
(here in germany it’s quarter to 9 pm now and I definitely need some diversion now after sitting in front of the pc the whole day. =)

First Ignor the camera rotations, in relation of keeping track of your objects.

Setup a variable to track your object/plane movement.

Example:

// Camera rotations/translations
// When we do a camera rotation, we are really moving all things in the world the same amount. Since both the plane and ball have been rotated/translated the same amount.
// The relationship between the two stay’s the same.

// Draw world as if you had not done any rotations befor hand.

//Draw plane on Z axis
glPushMatrix()
.
.
.
glPopMatrix()

//Draw ball, in relationship to the plane it X/Z is the movement long the plane Z= forward/backware; X = right/left, where Y is the hight of the ball relative to the plane.
glPushMatrix()
glTranslate3f( ball_x, ball_y, ball_z);

.
gluSoldSphere( 5 ); // if ball is rolling on plane, then hight Y will be 5
glPopMatrix()

How this helps.

Originally posted by eisebs:
[b]Thanks for the answer.
I already thought of that but I thought I could do it by pushing, loading the old matrix and then rotating.
But the problem is that i’ve already translated by then.
I’ll try your suggestion tomorrow.
(here in germany it’s quarter to 9 pm now and I definitely need some diversion now after sitting in front of the pc the whole day. =)