PDA

View Full Version : rotation origin



11-04-2003, 11:25 AM
Is there a way to set the origin point for a rotation.

I have an object I am rotating and it is only on the screen for angles between 300 and 320 degree rotations.

I have tried transforming the object after the rotation but the numbers I am inputting are just guessed so I still dont have any control over where the object will appear.

Ideally I would like to set the origin point as the bottomleft of my graphic and have it revolve around that.

the code I have tried out is

glPushMatrix();
glRotated(90, 0, 0, 1);
object();
glPopMatrix();

I have also inserted the line glTranslated(); with values for the x and y.

My results so far have been either off screen
On a part of the screen that I dont want them to be on. Or the rest of my scene has rotated and the object I am trying to rotate has remained in the same place.

I have looked through other posts and tried various things but am still having no luck.

Can anybody help me with this?

Thanks

nexusone
11-04-2003, 11:41 AM
You can translate the object before rotating it, note openGL work's backwards, last transform first.

glTranslate(.....) // Move object
glRotate(....) // Rotate on axis
glTranslate(....); // With this translate we can move the rotation axis.
draw_Object();

11-04-2003, 12:10 PM
Still not having any luck I tired

void rot(void)
{
glPushMatrix();
glTranslatef(200,-200,0);
glRotatef(90,0,0,1);
glTranslatef(320,240,0);
redcar();
glPopMatrix();

glEnd();
}

My object is not appearing on the screen.

Can anyone point out where I am going wrong?

Object start point on screen is
void redcar(void)
{
//set colour red
glColor3f(1.0f, 0.0f, 0.0f);

//car body
glRecti(111.25, 395, 141.25, 455);


//set colour black
glColor3f(0.0f, 0.0f, 0.0f);

//rectangle back of car
glRecti(121.25,435, 131.25,445);

//wheels
glRecti(141.25,395, 156.25,410); //bottom right
glRecti(141.25,440, 156.25,455); //top right
glRecti(96.25,395, 111.25,410); //bottom left
glRecti(96.25,440, 111.25,455); //top left

//lines back of car
glLineWidth(1.0);
glBegin(GL_LINES);

glVertex2i(123.25, 400);
glVertex2i(123.25, 415);
glVertex2i(126.25, 400);
glVertex2i(126.25, 415);
glVertex2i(129.25, 400);
glVertex2i(129.25, 415);

glEnd();
}