Surface2D.hpp

This file defines a templated class to represent a 2D suface capable of maintaining data about which 2D bodies are currently on that surface and rapidly identifying if they are overlapping.

BODY_TYPE is the class that represents the body geometry. BODY_INFO represents the internal infomation about the body, including the controller.

Member functions include: Surface2D(double _width, double _height); const Point & GetMaxPosition() const; vector<BODY_TYPE *> & GetBodySet(); const vector<BODY_TYPE *> & GetConstBodySet() const; Surface2D<BODY_TYPE, BODY_INFO> & AddBody(BODY_TYPE * new_body); void TestCollisions(std::function<bool(BODY_TYPE &, BODY_TYPE &)> collide_fun);

Development notes:

  • Need a good function to remove a body; now we have to use GetBodySet() and modify it.

template<typename BODY_TYPE>
class Surface2D
#include <Surface2D.hpp>

Public Functions

inline Surface2D(double _width, double _height)
inline ~Surface2D()
inline double GetWidth() const
inline double GetHeight() const
inline const Point &GetMaxPosition() const
inline vector<Ptr<BODY_TYPE>> &GetBodySet()
inline const vector<Ptr<BODY_TYPE>> &GetConstBodySet() const
inline Surface2D &AddBody(Ptr<BODY_TYPE> new_body)
inline Surface2D &Clear()
inline void TestCollisions(std::function<bool(BODY_TYPE&, BODY_TYPE&)> collide_fun)

Private Members

const Point max_pos
vector<Ptr<BODY_TYPE>> body_set