Thread: Independent transformations

1. 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.

0) Initial position.
1) Draw line along Y-axis.
2) Rotate it anticlickwise 45.0
3) Come to initial position. Such that transformation done in the step (2) does not
apply next.
4) Now draw one more line along Y-axis.
5) Rotate it clockwise 45.0. Now we should have a shape 'V'
6) 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

2. Re: Independent transformations

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).]

3. Re: Independent transformations

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()..... ?

4. Re: Independent transformations

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

5. Re: Independent transformations

Yes. It worked now. Thanks

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•