Independent transformations

Hi All,

I am a beginner to OpenGL programming. I am stuck with a problem. I will

explain it with a simple example.
I wanted to draw a tilted V using two lines and some rotations. I wanted
to do in the following way.

  1. Initial position.
  2. Draw line along Y-axis.
  3. Rotate it anticlickwise 45.0
  4. Come to initial position. Such that transformation done in the step (2) does not
    apply next.
  5. Now draw one more line along Y-axis.
  6. Rotate it clockwise 45.0. Now we should have a shape ‘V’
  7. Now rotate thsi whole model(, I mean the V shape), 90.0

That is I wanted to apply independent transformations to each object and one more transformation for the entire scene.

I tried to use pusmatrix and popmatrix. But it didn’t help. May be I am not
using it in proper way. Can you please let me know how to acheive this.
A pseudo code will be really help ful.

Expecting your help.

Thanks in advance
Deek**** M

Maybe you could post the code that you have problems with ?

You could do it soemmthing like this:

glPushMatrix();
glRotatef( -45, 0, 0, 1);
draw line
glPopMatrix();
glPushMatrix();
glRotatef( 45, 0, 0, 1);
draw line again
glPopMatrix();

You save the current matrix, do the rotation and then draw the shape you want, then pop the matrix to restore it as it was before.

You have to do any rotation before you draw the object not after.

Mikael

[This message has been edited by mikael_aronsson (edited 02-25-2004).]

Hi Mikael,
The code is bit complex. and conatisn 4 files, If it can be posted I can send that. Here is what I did.

Rotate();
PushMatrix();
/* loadIdenity() /
rotate_1();
DrawLine1();
/
loadIdenity() */
rotate_2();
DrawLine2();
pop();

But I found that drawLine2 is affected by both rorate_1() and rotate_2(). Do I need co uncomment the loadIdentity()… ?

you need to do some thing like this
Rotate();
PushMatrix();
rotate_1();
DrawLine1();
PopMatrix();
PushMatrix();
rotate_2();
DrawLine2();
PopMatrix();

Yes. It worked now. Thanks