I reviewed this scenario: objects that look something like this:
class PhyisicalObject { private: virtual void Update() = 0; friend class PhysicsController; void DoUpdate() { this->Update(); } };
There is a controller class called PhysicsController
that controls the dynamics of a pool of physical objects by calling their DoUpdate()
method. This method, in terms, calls the overloaded version of the Update()
function, where a numerical integrator is used to calculate the position, speed and acceleration of objects in stages. I thought having an interface implying this functionality would be a good starting point:
class IIntegrator { virtual void opertor() (const vec3& pos, const vec3& vel, vec3& outPos, vec3& outVel); };
Now inheriting this IIntegrator
abstract class and providing an implementation for various methods is the next step (explicit Euler, RK4, Verlet, Midpoint, Symplectic Euler, and possibly some semi-implicit / IMEX or implicit, would be excellent). The problem is that I do not see clearly how to do the following two things:
Each physical object calculates its own acceleration in any of its vertices in different ways (given that the objects consist of mass points connected through springs or some kind of restraining objects). This function must be passed to the integrator, but it is specific to the object. You can get pointers to non-static methods, but how will this match the IIntegrator
interface?
When an object calls its Update()
method, what happens behind the scenes is that the integrator is used to provide functionality. Perhaps I would like to switch the integration method on the fly. Or at least create an instance of one object with different integrators. For me it sounds like a factory, and to switch the integrator on the fly .. maybe a strategy template? Which solution will be quite elegant and effective in this context?
source share