Rotation question

Started by
5 comments, last by Supernova 22 years, 10 months ago
How can I rotate a quad around a custom axis? Is there any way to stack glTranslatef() and glRotatef()? Without having to make a custom matrix. Basically what I want to do is Translate to a certain point, then Rotate so that it rotates around the origin (0,0), then Translate again to put it where it should be. I'm interested in how to do this in both regular perspective and orthographic. Thanks. Edited by - Supernova on June 25, 2001 12:09:31 AM
Advertisement
lol
Well I am running on fumes right now so I''m not sure I''m comprehending your question right so I will stick to one thing that rings a bell... lol

When you ask if you can stack glTranslate and glRotate, if you are asking if there is a way to push them onto the stack, perform another operation and release them from the stack, you can do this:

glPushMatrix();

// do your transformation

glPopMatrix();

If I am totally off the mark here, please have pity... lol it has been one of those days...

Seeya
Krippy
That''s not what I''m trying to do. If it helps, here''s the code I used in D3D:

  //first move the center of rotation 15 pixels UPD3DXMatrixTranslation(&turrettrans2, 0, 15, 0);	//then rotate the turret to the given angleD3DXMatrixRotationZ(&turretrot, turret.rot_angle*3.1415927f/180);	//then combine the two matrices and put them into hold_tempD3DXMatrixMultiply(&hold_temp,&turrettrans2,&turretrot);	//make a matrix that holds where it''s supposed to be on the screenD3DXMatrixTranslation(&turrettrans, turret.x, turret.y, 0);//then combine the screen coordinates matrix with the correctly rotated matrix//and put it into the world matrix which is used to renderD3DXMatrixMultiply(&matworld, &hold_temp,&turrettrans);  

I do not know if I understand the question but here is a try with some pseudo code:

glRotate(rot);
glTranslate(trans);

// Now is the next output rotated rot around (0,0) with radius trans
glTranslate(finalPosition);
// Now is it also translated to the finalPosition
drawTheQuad();

You will probably also want to have a push at top and a pop at bottom.

You are asking if it is possible to stack rotates and translates but yo do not seems to mean the matrix stack. All rotates and translates is accumulated in the current matrix.

About your question about perspective. This has nothing to do with it. You are placing the polygons and can then use any perspective you want to.

I think that I got the order in the pseudo code wrong. The natural order should be to go to smaller details. New pseudo code:

glTranslate(finalPos);

glRotate(rot);
glTranslate(trans);

draw();

I apparently misused the term "stack". What I meant was multiply (stack, multiply.. eh..), like you do in D3D. But either way, your code seems to do what I want. Thanks!!
this should do:

float Current_rotation = 0.0f;


glPushMatrix();
glRotatef(Current_Rotation,1.0f,0.0f,0.0f);
Current_Rotatation += 1.0f;

// draw the object

glPopMatrix();

This topic is closed to new replies.

Advertisement