#### Archived

This topic is now archived and is closed to further replies.

# Rotation question

This topic is 6229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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();

glPopMatrix();

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

Seeya
Krippy

##### Share on other sites
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);

##### Share on other sites
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

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.

##### Share on other sites
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();

##### Share on other sites
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!!

##### Share on other sites
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();

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×