Scene Graph

Started by
1 comment, last by GameDev.net 17 years, 2 months ago
Hi all my meshes, sounds, sprites and stuff derive from a common Entity class which contains the methods to postion something in 3d space. In my Node class, i want to store a list of these things to show that they are attaced to the node. As they all derive from entity it is possible to store them as an array or linked list of Entities but this "chopps" them to the entity level which only gives me access to the positional methods. When i come to access things from nodes, I have to re-cast them every time into what they originally were. Is there a better way of doing this? thanks
Advertisement
Hello,

The first question you should consider is: why do you need to cast back? Once your objects are in the scene graph, they should just be Entities!

If you need to change the properties of a particular object, your best bet is probably to keep a reference to the object (for example, Car) outside your graph (where it is upcasted as an entity). When moving your car, you call the method "move" on your Car reference. Note that you could use some messaging system to arrive to the same result. Using the Visitor pattern is another solution.

Have a try with these different techniques, and get an idea of which one is the most maintainable in regards to the rest of your design.

Happy Coding!

Depending upon which information you want access too, making your functions virtual would allow specific information too be looked up at runtime. This of course is a limited approach as you obviously don't want to make all of the functionality virtual. Other suggestions?

This topic is closed to new replies.

Advertisement