Elegant engine - ProkopHapala/SimpleSimulationEngine GitHub Wiki

Goal is to make simple physical and rendering engine which is simple and fast, still enough general. Main focus is on physics. The main motivation is that I see that ad hoc approach to this topic with lot of specialized functions leads to unmanageable mess.

Basic ideas

  • Core is physical scene graph traversed in physics_update, which evaluate all physical links and interactions between objects
  • rendering is done independently by taking global transform gpos,grot resulting from physics update. Rendering is usually just calling some mesh. Specialized render may be for terrain, clouds and other particle systems.
  • we use 3D objects for everything, 2D and 2.5D are emulated by 3D objects with custom controller.
  • we do not have to assign mesh, texture and shader to each object, instead we use int kind which is than resolved by renderer (therefore each 3D object is an instance);

Parformance attempts

  • if possible, we want to use static functions (not virtual) for basic operations such as update and draw. There is many more physics update calls, therefore we should keep this overhead low.
  • for graphics it

class structure

        class Point{ public: Vec3d pos; int id; int kind; } // just to prevent diamond problem (?)
	class PointBody : public Point {
	   public:
	   Vec3d vel,force;
           inline  clean_temp_(){force=0;};
           inline  void update_(dt){ vel+=force; pos+=mass*vel*(dt/mass);   };  // can be called as obj->PointBody::update_(dt);
           virtual void update     (dt){update_(dt)};
           virtual void clean_temp (dt){clean_temp_()};
	}
        class KinematicBody : public Point{
            Mat3d rot;
        }
	class Object3D : public KinematicBody {
	   public:
	   Vec3d span;
	}
	class RigidBody : public Object3D, KinematicBody {
	   public:
	   Quat4d qrot;
	   Mat3d  momentOfInertia;
	   Vec3d  torque;
	   Vec3d  angular_velocity;
	   // pos, vel, force, mass, rot, span,  id, kind  ... should be inheriate
	}
        class GameObject : public RigidBody {
        } 

see problem here http://www.cprogramming.com/tutorial/multiple_inheritance.html

To stack overflow

For some physical simulation engine I would like class structure like

// class Point{ Vec3d pos; } // I consider use this as common parent if that helps
class PointBody{
   public:
   Vec3d pos,vel,force;
   double mass;
}
class Object3D{
   public:
   Vec3d pos;
   Mat3d rot;
   Vec3d span;
}
class RigidBody : public Object3D, public PointBody {
   public:
   Quat4d qrot;
   Mat3d  momentOfInertia;
   Vec3d  torque;
   Vec3d  angular_velocity;
   // pos, vel, force, mass, rot, span  should be inheriate
}

The obvious problem is pos but perhaps in this particular situation it can be resolved by making common parent for all containing pos. But I can imagine more complex situations where that is not feasible;

When I was searching this problem I found it mostly in relation to functions (mostly virutal) but not much about data.