Body2D.hpp

This file defines classes to represent bodies that exist on a 2D surface.

Each class should be able to:

  • Maintain a pointer to information about the full organism associated with this body.

  • provide a circular perimeter of the body (for phase1 of collision detection)

  • Provide body an anchor point and center point of the body (typically the same)

Currently, the only type of body we have is:

CircleBody2D - One individual circular object in the 2D world.

Development notes:

  • If we are going to have a lot of links, we may want a better data structure than vector.

class Body2D_Base
#include <Body2D.hpp>

Subclassed by CircleBody2D

Public Functions

inline Body2D_Base()
inline virtual ~Body2D_Base()
inline double GetBirthTime() const
inline const Angle &GetOrientation() const
inline const Point &GetVelocity() const
inline double GetMass() const
inline uint32_t GetColorID() const
inline bool IsReproducing() const
inline int GetReproCount() const
inline Point GetShift() const
inline double GetPressure() const
inline bool GetDetachOnDivide() const
inline void SetBirthTime(double _in)
inline void SetOrientation(Angle _in)
inline void SetVelocity(Point _in)
inline void SetMass(double _in)
inline void SetColorID(uint32_t _in)
inline void TurnLeft(int steps = 1)
inline void TurnRight(int steps = 1)
inline void RotateDegrees(double degrees)
inline void IncSpeed(const Point &offset)
inline void IncSpeed()
inline void DecSpeed()
inline void SetVelocity(double x, double y)
inline void AddShift(const Point &s)
inline void SetDetachOnDivide(bool in = true)

Protected Types

Values:

Protected Attributes

double birth_time
Angle orientation
Point velocity
double mass
uint32_t color_id
int repro_count
Point shift
Point cum_shift
Point total_abs_shift
double pressure
bool detach_on_divide
template<typename BODY_TYPE>
struct BodyLink
#include <Body2D.hpp>

Public Functions

inline BodyLink()
inline ~BodyLink()

Public Members

LINK_TYPE type
Ptr<BODY_TYPE> from
Ptr<BODY_TYPE> to
double cur_dist
double target_dist
class CircleBody2D : public Body2D_Base
#include <Body2D.hpp>

Public Functions

CircleBody2D() = delete
inline CircleBody2D(const Circle2D<double> &_p)
inline ~CircleBody2D()
inline const Circle2D<double> &GetPerimeter() const
inline const Point &GetPosition() const
inline const Point &GetCenter() const
inline double GetRadius() const
inline double GetTargetRadius() const
inline void SetPosition(const Point &p)
inline void SetRadius(double r)
inline void SetTargetRadius(double t)
inline void Translate(const Point &t)
inline bool IsLinkedFrom(const CircleBody2D &link_org) const
inline bool IsLinkedTo(const CircleBody2D &link_org) const
inline bool IsLinked(const CircleBody2D &link_org) const
inline size_t GetLinkCount() const
inline void RemoveLink(Ptr<BodyLink<CircleBody2D>> link)
inline const BodyLink<CircleBody2D> &FindLink(const CircleBody2D &link_org) const
inline BodyLink<CircleBody2D> &FindLink(CircleBody2D &link_org)
inline double GetLinkDist(const CircleBody2D &link_org) const
inline double GetTargetLinkDist(const CircleBody2D &link_org) const
inline void ShiftLinkDist(CircleBody2D &link_org, double change)
inline Ptr<CircleBody2D> BuildOffspring(Point offset)
inline void BodyUpdate(double change_factor = 1)
inline void ProcessStep(double friction = 0)
inline void FinalizePosition(const Point &max_coords)
inline bool OK()

Protected Attributes

Circle2D<double> perimeter
double target_radius
vector<Ptr<BodyLink<CircleBody2D>>> from_links
vector<Ptr<BodyLink<CircleBody2D>>> to_links