Jump to content

  • Log In with Google      Sign In   
  • Create Account


Rotation question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Supernova   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 June 2001 - 04:15 PM

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

Sponsor:

#2 Krippy2k   Members   -  Reputation: 134

Like
Likes
Like

Posted 25 June 2001 - 05:09 PM

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

#3 Supernova   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 June 2001 - 05:40 PM

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 UP

D3DXMatrixTranslation(&turrettrans2, 0, 15, 0);

//then rotate the turret to the given angle

D3DXMatrixRotationZ(&turretrot, turret.rot_angle*3.1415927f/180);

//then combine the two matrices and put them into hold_temp

D3DXMatrixMultiply(&hold_temp,&turrettrans2,&turretrot);

//make a matrix that holds where it''s supposed to be on the screen

D3DXMatrixTranslation(&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 render

D3DXMatrixMultiply(&matworld, &hold_temp,&turrettrans);



#4 Obelix   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 June 2001 - 11:08 PM

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.



#5 Obelix   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 June 2001 - 12:15 AM

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();



#6 Supernova   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 June 2001 - 03:37 AM

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!!

#7 AIRmichael   Members   -  Reputation: 136

Like
Likes
Like

Posted 27 June 2001 - 12:24 AM

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();




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS