PDA

View Full Version : How To Circumvent Matrix Stack Limits?



MaxH
11-02-2010, 09:36 AM
I have a subroutine that calls itself recursively to generate something that looks like a segmented worm. The routine is called with the number of segments I want to generate. Nested pushes and pops are involved. It works well until I get up to about 30 segments. Then things go haywire. I'm pretty sure this is because I'm overflowing the ModelView matrix stack. Has anyone found a workaround for this problem? Thanks.

ZbuffeR
11-02-2010, 10:22 AM
Use your own stack, and glLoadMatrix the result, without any glPush/glPop.

overlay
11-02-2010, 01:58 PM
If the worm is just a sequence of segments where each segment has just one parent/one child but no sibling, you don't even need push and pop. Just on push before the first segment, one pop after the last segment to isolate the worm from the other objects/transform of your scene. You have a degenerated tree/hierarchy which turns to be just a flat list.

MaxH
11-02-2010, 04:50 PM
Use your own stack, and glLoadMatrix the result, without any glPush/glPop. I thought of that but was hoping for something easier.

MaxH
11-02-2010, 04:55 PM
If the worm is just a sequence of segments where each segment has just one parent/one child but no sibling, you don't even need push and pop. Just on push before the first segment, one pop after the last segment to isolate the worm from the other objects/transform of your scene. You have a degenerated tree/hierarchy which turns to be just a flat list.
Bingo. You are correct and I am embarrassed. Should have realized this myself. Each segment has only a parent and a child. There are no siblings. I commented out the pushes and pops, and the routine works fine. Thanks. A screen capture showing 3 tentacles with 49 segments each should be attached ...

http://www.mfwweb.com/OpenGL/Tentacles.jpg