Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: hierachies

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    9

    hierachies

    I'm trying to implement an object hierachy. I have no problem in creating it but then I need to draw it.

    So i have my parent node that will point to its children and them children will point to their own children and so and so forth.

    So I draw the parent and then the children, i thought of then going through the children making them the parent and then draw their children so the algorithm is recursive. But im having such a brain block and cant think of how to do that second stage, can anyone possible help??

    I'm not the greatest programmer and so the answer is probably very simple. eugh head pain.

    Cheers,

  2. #2
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    King George, Virginia
    Posts
    138

    Re: hierachies

    let's say you have an object that is (loosely) defined like this:
    Code :
    class Object
    {
      Object *parent;
      list<Object *> children;
    };
    now you can recursively render (or do anything else) to every Object in the tree like this:
    Code :
    void recurse(Object *obj)
    {
      obj->render();
      if (obj->children.size())
      {
        for (list<Object *>::itereator i = children.begin(); i != children.end(); i++)
        {
          recurse(*i);
        }
      }
    }

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    9

    Re: hierachies

    could this be translated into c by any chance??

  4. #4
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    King George, Virginia
    Posts
    138

    Re: hierachies

    to make this work in C, just change the class to a struct, and implement your own linked list data structure.

Posting Permissions

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