The most successful publicly accessible physical engines are not very difficult for "templates" or "object-oriented design."
Here's a summary of my admittedly bold statement:
Chipmunk - written in C, enough is said.
Box2d - written in C ++, and there is some polymorphism here. there is a hierarchy of forms (b2Shape base class) with several virtual functions. However, this abstraction seeps in like a sieve, and you will find many castings to leaf through classes throughout the source code. There is also a hierarchy of “contacts”, which turns out to be more successful, although with a single virtual function it would be trivial to rewrite this without polymorphism (as I suppose, a pointer to a function is used for a tweet). b2Body is a class used to represent solids, and it is not virtual.
Bullet - Written in C ++, used in a ton of games. Tons of functions, tons of code (relative to the other two). Actually there is a base class that extends to bodies with a solid body and a soft body, but only a small part of the code can use it. Most of the virtual function of the base class relates to serialization (saving / loading the state of the kernel), of the two remaining virtual functions, the soft body cannot implement one with TODO, informing us that some hacks need to be cleared. Not quite the sound of approval for polymorphism in physical engines.
These are many words, and I did not even begin to answer your question. All I want to score is that polymorphism is not something that is effectively applied to existing physical engines. And this is probably not because the authors did not “receive” OO.
One way or another, my advice is: polina is watered for your entity class. You will not have 100 different types that you cannot reorganize later, your data on the physical engine will be quite uniform (convex policies, boxes, spheres, etc.), and the data of your entity will probably be even more uniform (maybe , only solids to get started).
Another mistake that I feel that you are doing only supports physics :: System. There is a utility in modeling bodies independently of each other (for example, for playing with two players), and the easiest way to do this is to support several physical :: systems.
With this in mind, the cleanest “pattern” to follow is the factory pattern. When users want to create a rigid body, they need to tell the :: System physics (acting like a factory) to do this for them, so in your physics :: System:
And in the client code:
circle_params_t circle(1.f ); body_params_t b( 1.f , &circle , xform ); rigid_body_t* body = physics_system.AddBody( b );
Anyhoo, a kind of rant. Hope this is helpful. At least I want to point you to box2d. It is written in a fairly simple C ++ dialect and the templates used in it will be relevant to your engine, whether 3D or 2D.