38 static std::array<std::vector<collider*>,
39 std::numeric_limits<uint8_t>::max()>
57 void push(
float force) {
58 std::vector<collider*> contacts;
60 contacts = collider::contacts();
61 if (contacts.empty()) {
65 force -= contacts_mass(contacts);
68 contacts.begin(), contacts.end(),
71 if ((this->*dynamic_resolver)(*contact,
72 contact->mass() + force)) {
73 contact->push<static_resolver, dynamic_resolver>(force);
74 (this->*static_resolver)(*contact);
78 std::for_each(contacts.begin(), contacts.end(),
79 [=](
collider const* contact) ->
void {
80 (this->*static_resolver)(*contact);
91 [[nodiscard]] std::vector<collider*> contacts()
const;
100 [[nodiscard]]
static float
101 contacts_mass(std::vector<collider*>
const& contacts);
113 template <float (
polygon::*position)()
const,
114 void (
polygon::*set_position)(float)>
115 void solo_static_resolver(
collider const& other) {
118 collision = body().overlap<
float>(other.body());
119 if (!(
bool)collision) {
124 (_body.*set_position)((body().*position)() +
125 ((body().*position)() < (other.body().*position)()
142 template <float (polygon::*position)()
const,
143 void (polygon::*set_position)(float)>
144 [[nodiscard]]
bool solo_dynamic_resolver(collider& other,
float force) {
146 std::pair<float, float> movement;
148 collision = body().overlap<
float>(other.body());
149 if (!(
bool)collision) {
153 movement = dynamic_movement(collision, force, other.mass());
154 if ((body().*position)() < (other.body().*position)()) {
155 (_body.*set_position)((body().*position)() - movement.first);
156 (other._body.*set_position)((other.body().*position)() +
159 (_body.*set_position)((body().*position)() + movement.first);
160 (other._body.*set_position)((other.body().*position)() -
174 void dual_static_resolver(collider
const& other);
185 [[nodiscard]]
bool dual_dynamic_resolver(collider& other,
float force);
196 static std::pair<float, float> dynamic_movement(
float collision,
197 float force,
float mass);
204 void align_entities()
const;
213 [[nodiscard]] polygon
const& body()
const;
221 void set_body(polygon
const& body);
229 [[nodiscard]]
float force()
const;
237 void set_force(
float force);
245 [[nodiscard]]
float mass()
const;
253 void set_mass(
float mass);
262 [[nodiscard]] uint8_t world()
const;
271 void set_world(uint8_t world);
279 [[nodiscard]]
float x() const final;
287 void set_x(
float x) final;
295 [[nodiscard]]
float y() const final;
303 void set_y(
float y) final;
311 [[nodiscard]]
float angle() const final;
319 void set_angle(
float angle) final;
327 [[nodiscard]]
float scale() const;
335 void set_scale(
float scale);
343 [[nodiscard]]
float x_offset() const final;
351 void set_x_offset(
float x_offset) final;
359 [[nodiscard]]
float y_offset() const final;
367 void set_y_offset(
float y_offset) final;
375 [[nodiscard]]
float angle_offset() const final;
383 void set_angle_offset(
float angle_offset) final;
391 [[nodiscard]]
bool attach_x() const final;
399 void set_attach_x(
bool attach_x) final;
407 [[nodiscard]]
bool attach_y() const final;
415 void set_attach_y(
bool attach_y) final;
423 [[nodiscard]]
bool attach_angle() const final;
431 void set_attach_angle(
bool attach_angle) final;
439 [[nodiscard]]
bool x_angle_lock() const final;
447 void set_x_angle_lock(
bool x_angle_lock) final;
455 [[nodiscard]]
bool y_angle_lock() const final;
463 void set_y_angle_lock(
bool y_angle_lock) final;
477 polygon const& body = polygon(),
float force = 0,
float mass = 0,
478 uint8_t world = std::numeric_limits<uint8_t>::max(),
479 std::vector<std::weak_ptr<component>> const& components = {});
487 collider(collider
const& other);
494 ~collider()
override;
503 collider& operator=(collider
const& other);