So I'm still working on this...
I recently started on a sizable bit of refactoring. I've changed things so that rays (or point particles, whatever you want to call them) are no longer just
RigidBody objects with a specific type of
CollisionShape. Now instead there are two classes,
RigidBody and
RayCollider, which both extend a new class called
DynamicsObject, which in turn extends
CollisionObject.
Now I've moved on to the second half of the task, creating another subclass of
CollisionObject called
CollisionGroup class, which represents a bunch of rigid bodies that are confined within a small volume... the goal is to have a single item in the spatial partitioning system which stores all of the bones of a dood... since the doods are small compared to the cells of the grid, it should work out to be more efficient this way.
I'm just about done coding up the
CollisionGroup class, and then it'll be time to make the game actually use it... and debug why it doesn't actually work. (Edit: I got it integrated and working

)
In other news, I discovered something annoying about the
protected keyword in C++ (which IIRC was different in C# and/or Java)...
If I have this:
class CollisionObject
{
protected:
virtual void DoStuff() { Debug("default behavior"); }
};
class RigidBody : public CollisionObject
{
protected:
void DoStuff() { Debug("overridden behavior"); }
};
class CollisionGroup : public CollisionObject
{
protected:
vector<RigidBody*> children;
void DoStuff(); // various attempted implementations below
};
Note, this is altered a bit from my actual code; I removed the intermediate DynamicsObject class for simplicity.The following code doesn't compile; the compiler complains that
CollisionObject::DoStuff is inaccessible, even though
CollisionGroup is derived from
CollisionObject!
void CollisionGroup::DoStuff()
{
for(vector<RigidBody*>::iterator iter = children.begin(); iter != children.end(); ++iter)
(*iter)->DoStuff();
}
This doesn't work either:
void CollisionGroup::DoStuff()
{
for(vector<RigidBody*>::iterator iter = children.begin(); iter != children.end(); ++iter)
((CollisionObject*)*iter)->DoStuff();
}
There are two ways to make it work, and they both suck. One is to declare
CollisionGroup as a friend class in
CollisionObject... which is not a good solution, because it means I can't have additional classes that derive from
CollisionObject and want to use their peer's
DoStuff method, without modifying the declaration of
CollisionObject.
The second way (which is what I'm doing now) is equally horrible:
void CollisionGroup::DoStuff()
{
for(vector<RigidBody*>::iterator iter = children.begin(); iter != children.end(); ++iter)
((CollisionGroup*)*iter)->DoStuff();
}
I
literally shuddered when that compiled successfully.