PDA

View Full Version : glRotatef (a pivot?)

gemini
02-26-2003, 09:34 AM
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?
regards for your help.

delic
02-26-2003, 10:40 AM
You are rotating about the y-axis instead of the origin of the object.

gemini
02-26-2003, 10:48 AM
Could you help me with solving the problem?

HalcyonBlaze
02-26-2003, 11:45 AM
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

gemini
02-27-2003, 01:18 AM
Now the object dissapeared ;(

gemini
02-27-2003, 01:19 AM
Maybe i'll throw the code:
--[cut here]---
render(){
glLoadIdentity();
glPushMatrix();
glRotatef(-90,0,0,1);//obracamy kamere.
gluLookAt( XP-5, CAMUP, ZP,XP, 0.5f, ZP,XP, 1, ZP);
podloga(); //draw the floor.

glPushMatrix();
glRotatef(g_RotationSpeed, 0.0f, 1.0f, 0.0f);
g_RotateX += g_RotationSpeed; // Increase the speed of rotation
renderobject(0,XP,-9, ZP,0);
glPopMatrix();

...

gemini
02-27-2003, 01:48 AM
Ok i have made it, - modyfing the render function for 3ds files.
Big thanks for help to all of you.