I'm not gonna be too abstract, though the concept I refer to is an abstract one. I hope I'm not opening some can of worms here, but would love to get your opinions.
Suppose I have a object. This object represents a physical entity and also a renderable entity. Both a physical entity and a renderable entity can have some transformation.
So a physical entity might look like this:
class RigidBody
{
// Real meat is here
private:
Matrix4 transformation;
Vector3 position;
Vector3 veloctiy, acceleration;
Vector3 angularVelocity, angularAcceleration;
// etc.
};
Now, a renderable entity might look like so:
class RenderObject
{
// again, real meat
private:
Matrix4 transformation;
Mesh mesh;
std::vector<boost::shared_ptr<RenderObject> > subObjects;
};
Now, when you add a physical object, it will always want to be rendered. So we need some way of sharing the transformation between the two classes.
One way would to make the physics object contain the renderobject (or pointers to shared renderobjects) and then allow public access to this, and then the physical object can update the renderobject. This should be fairly fast, but doesn't seem conceptually correct. (I guess you could think of the renderobject being the physics object's slave, and it gives it behavior).
I think the reason this is unsatisfying is because there's a higher class that is both physical and renderable. Some static objects are only renderable though. So are there alternate solutions (maybe using inheritance? I couldn't think of anything good) to this problem?