PDA

View Full Version : Independent transformations



dmantamp
02-24-2004, 08:04 PM
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

mikael_aronsson
02-24-2004, 11:17 PM
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).]

dmantamp
02-24-2004, 11:48 PM
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()..... ?

chowe6685
02-25-2004, 06:21 AM
you need to do some thing like this
Rotate();
PushMatrix();
rotate_1();
DrawLine1();
PopMatrix();
PushMatrix();
rotate_2();
DrawLine2();
PopMatrix();

dmantamp
02-26-2004, 08:39 PM
Yes. It worked now. Thanks