Click to See Complete Forum and Search --> : portal scene management


staticVoid
May 26th, 2009, 10:44 AM
hi there,

I have a base class (IRenderable) that represents some form of renderable object, which has a virtual function called render().

My application needs to hold references to the derived classes of this IRenderable interface so that it can change specific variables of how the object looks, color, material etc. that wouldn't be kept in the IRenderable interface.

The problem is that I want to add a new form of managing these objects: I want to assign each renderable object to a sector (i.e. an area of the map) and have a pointer in the renderable object that points to the sector it belongs to.

each sector will contain an array of renderable objects and those objects should contain pointers to their sectors, the reason the objects need to have a reference to the sector they belong to is to speed up spatial querys of the scene (mainly collision). i.e. if an object moves I will only have to check the sector's geometry for a collision unless it crosses a portal.

If I just added the sector pointer into the IRenderable interface then when I implement a different scene management this will be unused.

I've tried a number of ways of doing this and the simplest so far would be to just map every renderable object to a sector in the manager class. i.e.



class PortalSceneManager
{
private:
std::map<IRenderable*, Sector*> map;
}




and then every time I need the sector the object belongs to just search for it in this map, but this means if I want to set the position of an object it would have to go through the manager class to see if the object crossed a portal when it was moved and therefore needs to be moved into another sector.

Another way I was thinking of would be to create a new class that wraps this renderable object and also holds a reference to the sector it belongs to.



class SectorObject
{
public:

void render()
{
renderable->render();
}

private:

IRenderable* renderable;
CSector* sector;
};




and then just hold references to this class in my application but this means I now don't know about what renderable objects I'm referencing therefore I can't for example change an objects material becuase I've only got a reference to the renderable interface.

any help would be appreciated.