PDA

View Full Version : drawing trees recursively (and rotation)



rhmazza
05-13-2001, 06:53 PM
I'm trying to draw trees recursively, so you start at the trunk and then draw branches that draw branches etc...

I'm trying to use gluCylinder, but I'm having problems keeping track of multiple rotations when I have to draw a branch off of a previous branch. Things get confusing because after a few rotations, glRotate(x, 0, 0, 1) for example won't necessarily rotate around the Z axis since matrix operations have built up.

Any advice on how to go about this?

Thug
05-17-2001, 03:14 PM
You could try and using
glPushMatrix and glPopMatrix. It may help in simplifing the proglem but then again I did really think about the problem long enough to grasp the complexity of the problem.

Relic
05-18-2001, 12:43 AM
You have to get familiar with global and local coordinate systems.
For growing trees with L-systems the next branch in the hierarchy will have to inherit the whole transformation of it's predecessors and add it's own _local_ transformation on top of that.
Right, glPush- and glPopMatrix is one way. Don't exceed the GL_MAX_MODELVIEW_STACK_DEPTH!