View Full Version : How to connect objects

Hi all,

what is the best approach to "connect" objects??

Example:

PushMatrix

translated1..

rotated1...

Block1

Popmatrix

Pushmatrix

translated2..

rotated2...

Block2

Popmatrix

Now i got two Blocks that i can move independently in the space by changing values of translated and rotated....

Is that a good way??

How can i now connect them both that they atre both in one Coordinatesystem and behave like one objekt when rotating /translating??

Thanks in advance!

mikael_aronsson

05-04-2002, 12:25 AM

Hi !

Just put another push/pop around it:

push

transform

draw something here

push

transform

draw part of object

pop

push

transform

draw another part of object

pop

pop

Now you can transform each part of the object, and also the whole object any way you want.

Mikael

Thanks Mikael.

One more question:

Is that the best way since there is a limit for the Matrix Stack concerning Push and Pop(32)?

How can i make one Object being moved

by translation and rotation when it is selected and the others not without defining every object with its own PushMatrix and Popmatrix??

Like this:

Pushmatrix()

obj1

obj2

obj3

.

.

.

Popmatrix

Now i have selected Obj3

What to do to rotate just Obj3 now??

For each object you want to transform without affecting other objects, draw the object inside yet anoter glPush/PopMatirx pair, and make the object specific transformation inside that pair.

Sorry, didn't see you wanted to do it without push/pop. Well, is there a reason you DON'T want to use them?

You can of course keep on transforming each object, without pushing them, and when you want to go back one step in the transformation (i.e. pop the stack), you can load the identity matrix, and redo all matrix operations but the last one.

Yes, there is a limit on the modelview stack. The depth is implementation depdenent, but you are guaranteed to have at least 32 matrices deep stack. That means you can call glPushMatrix at least 32 times, with out popping the stack. That that should be more than enough for any not too advanced application.

nexusone

05-04-2002, 04:48 AM

I don't think the limit of 32 is a problem, since you would have to push 32 times in a row and not pop to go over the 32.

If you push then pop each object you are still back at zero.

example

glPushMartix() // Push matrix by 1

draw_object1()

glPopMatrix() // Pop matrix subtract matrix by 1

glPushMartix() // Push matrix by 1

draw_object2()

glPopMatrix() // Pop matrix subtract matrix by 1

If you do the math your matrix is back at zero.

A little more advanced:

glPushMartix() // Push matrix by 1

glTranslate(.....) Move robot

glRotate(....) Rotate robot

draw_robot_body()

glPushMartix() // Push matrix by 1

glRotate() // move robot arm

draw_robot_arm()

glPopMatrix() // Pop matrix subtract matrix by 1

glPushMartix() // Push matrix by 1

glRotate(....) // rotate robot legs

draw_robot_legs()

glPopMatrix() // Pop matrix subtract matrix by 1

glPopMatrix() // Pop matrix subtract matrix by 1

same results matrix is back at zero.

Originally posted by Stef:

Thanks Mikael.

One more question:

Is that the best way since there is a limit for the Matrix Stack concerning Push and Pop(32)?

How can i make one Object being moved

by translation and rotation when it is selected and the others not without defining every object with its own PushMatrix and Popmatrix??

Like this:

Pushmatrix()

obj1

obj2

obj3

.

.

.

Popmatrix

Now i have selected Obj3

What to do to rotate just Obj3 now??

Thanks all!

If the push/pop is not a problem then it's ok.

That would have been the only reason not to do it with Push/pop...

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.