}
Body::~Body() {
- for (creature::Creature *c : creatures) {
- delete c;
- }
}
void Body::SetSimulation(Simulation &s) noexcept {
// first remove creatures so they don't collide
for (auto c = Creatures().begin(); c != Creatures().end();) {
if ((*c)->Removable()) {
- delete *c;
+ (*c)->Removed();
c = Creatures().erase(c);
} else {
++c;
for (auto &c : collisions) {
c.A().GetSituation().Move(c.Normal() * (c.Depth() * -0.5));
c.B().GetSituation().Move(c.Normal() * (c.Depth() * 0.5));
- // TODO: adjust velocities as well
+ c.A().GetSituation().Accelerate(c.Normal() * -dot(c.Normal(), c.AVel()));
+ c.B().GetSituation().Accelerate(c.Normal() * -dot(c.Normal(), c.BVel()));
// TODO: notify participants so they can be annoyed
}
}
return a->GetSituation().Position();
}
+const glm::dvec3 &CreatureCreatureCollision::AVel() const noexcept {
+ return a->GetSituation().Velocity();
+}
+
const glm::dvec3 &CreatureCreatureCollision::BPos() const noexcept {
return b->GetSituation().Position();
}
+const glm::dvec3 &CreatureCreatureCollision::BVel() const noexcept {
+ return b->GetSituation().Velocity();
+}
+
Orbit::Orbit()
: sma(1.0)