# glRotatef (a pivot?)

Hello again,
is there somekind of setting up a pivot when rotating the object?
I want to rotate the cube but the object isn’t rotating “around himself”, but around some place on the scene.
I am using:
spin++;
glRotatef(spin,0.0f,1.0f,0.0f);

What is going on?

You are rotating about the y-axis instead of the origin of the object.

Could you help me with solving the problem?

This is what you kinda want to do:

void draw(){

// Put all your standard glClear(…) and what not functions here

// Transform the scene back a certain amount
glTransformf(x,y,z);

// Push an identity matrix on the matrix stack
glPushMatrix();

``````  // Rotate the object about it's center
glRotatef(angle, 0.0f,1.0f,0.0f);

// Draw the object
drawCube();
``````

// Pull that temporrary matrix out
glPopMatrix();

}

This code is under the assumption that you are defining the cube’s vertices so that it is centered about to the global space origin.

If it isn’t, just do this inside the glPushMatrix()/glPopMatrix() pair:

// let’s say the position of the cube in world/global space is (x, y, z).

// Translate the point to the center
glTranslatef(-x,-y,-z);
// Now rotate the object (this will be about the origin of world space AND the cube’s center
glRotatef(angle, 0.0f,1.0f,0.0f);
// Translate the object back
glTranslatef(x, y, z);

// then draw the object
drawCube();

And that should do it.

• Halcyon

Now the object dissapeared ;(

Maybe i’ll throw the code:
–[cut here]—
render(){