C Scene Graph

Started by
12 comments, last by GameDev.net 18 years, 8 months ago
Swordfish, if you're not so familiar with C++, this is an excellent opportunity to learn it along with good OOP practices! Pick up a design patterns book and look at existing scene graph implementations (in any language). Learn and plan as much as you can before actually implementing the system and you'll be much more productive when you start writing code. It's easy to get bogged down on details and go into a continual cycle of revising code without making a lot of progress, especially if you'd be spending time dealing with language issues.

I personally like the conventions of the Magic library (except for the Hungarian notation). It's very consistently written.
Advertisement
Quote:Original post by swordfish
Yeah, implementing a scene-graph in C is a definite challenge and at times it can be a nightmare. The reason I chose C is mainly because I find it more intuitive than C++. I have knowledge of C++ and object-oriented programming, it's just that my C++ skills aren't exactly as sharp as are my C skills. When I look at C++ source like that in the WildMagic engine, I am just dumbfounded by how complicated it all looks - one could really get lost trying to perfect/optimize things.

Evolutional, that is somewhat how I have my scene-graph setup. Did you just come up with that or is that based on something that has been used/tested? I've got my scene graph working, it's just that things are starting to get tight as I add more functionality to it. I'm interested in seeing the results of a more complete C scene-graph than mine.



typedef struct scene_node_s
{
int type;
void * p_data;

void (*update)(struct scene_node_s * p);
void (*draw)(struct scene_node_s * p );
}
scene_node_t;

void SN_Init( int type, scene_node_t * node )
{
switch(type)
{
case SN_TYPE_WHATEVER:
sn_type_whatever_init( node );
break;
}
}

scene_node_t * p_node;
p_node->draw(p_node);

Got it? That is what the C++ compiler does internally with virtual functions anyways. In C you have to manually do what the C++ compiler does for you, and there is alot of things you can't do because the language won't let you.
"It's such a useful tool for living in the city!"
the original SGI Performer scene graph was implemented in C. so it is definitely possible to implement it in C.

but yeah, the library ends up doing all sorts of things with function pointers, as a previous poster mentioned.
Eww, void*... the headaches caused by that alone is enough to make me glad I use C++ :)

This topic is closed to new replies.

Advertisement