1 #include "Composition.hpp"
2 #include "Creature.hpp"
5 #include "NameGenerator.hpp"
6 #include "Situation.hpp"
7 #include "Steering.hpp"
9 #include "BlobBackgroundTask.hpp"
11 #include "IdleGoal.hpp"
12 #include "../app/Assets.hpp"
13 #include "../math/const.hpp"
14 #include "../world/Body.hpp"
15 #include "../world/Planet.hpp"
16 #include "../world/Simulation.hpp"
17 #include "../world/TileType.hpp"
21 #include <glm/gtx/transform.hpp>
22 #include <glm/gtx/vector_angle.hpp>
25 #include <glm/gtx/io.hpp>
31 Composition::Composition()
35 Composition::~Composition() {
39 bool CompositionCompare(const Composition::Component &a, const Composition::Component &b) {
40 return b.value < a.value;
44 void Composition::Add(int res, double amount) {
46 for (auto &c : components) {
47 if (c.resource == res) {
54 components.emplace_back(res, amount);
56 std::sort(components.begin(), components.end(), CompositionCompare);
59 bool Composition::Has(int res) const noexcept {
60 for (auto &c : components) {
61 if (c.resource == res) {
68 double Composition::Get(int res) const noexcept {
69 for (auto &c : components) {
70 if (c.resource == res) {
78 Creature::Creature(world::Simulation &sim)
85 , highlight_color(0.0, 0.0, 0.0, 1.0)
98 // all creatures avoid each other for now
99 steering.Separate(0.1, 1.5);
102 Creature::~Creature() {
105 void Creature::AddMass(int res, double amount) {
106 composition.Add(res, amount);
108 double nonsolid = 0.0;
110 for (const auto &c : composition) {
112 volume += c.value / sim.Assets().data.resources[c.resource].density;
113 if (sim.Assets().data.resources[c.resource].state != world::Resource::SOLID) {
118 Size(std::cbrt(volume));
119 highlight_color.a = nonsolid / mass;
122 void Creature::HighlightColor(const glm::dvec3 &c) noexcept {
123 highlight_color = glm::dvec4(c, highlight_color.a);
126 void Creature::Ingest(int res, double amount) noexcept {
127 // TODO: check foreign materials
129 AddMass(res, amount * 0.1);
132 void Creature::Hurt(double amount) noexcept {
133 stats.Damage().Add(amount);
134 if (stats.Damage().Full()) {
135 std::cout << "[" << int(sim.Time()) << "s] " << name << " ";
136 if (stats.Exhaustion().Full()) {
137 std::cout << "died of exhaustion";
138 } else if (stats.Breath().Full()) {
139 std::cout << "suffocated";
140 } else if (stats.Thirst().Full()) {
141 std::cout << "died of thirst";
142 } else if (stats.Hunger().Full()) {
143 std::cout << "starved to death";
145 std::cout << "succumed to wounds";
147 std::cout << " at an age of ";
149 int age = int(Age());
151 std::cout << (age / 3600) << "h ";
155 std::cout << (age / 60) << "m ";
158 std::cout << age << 's';
160 std::cout << " (" << int(Age() / properties.Lifetime() * 100)
161 << "% of life expectancy of ";
163 int lt = int(properties.Lifetime());
165 std::cout << (lt / 3600) << "h ";
169 std::cout << (lt / 60) << "m ";
172 std::cout << lt << 's';
174 std::cout << ")" << std::endl;
179 void Creature::Die() noexcept {
188 double Creature::Age() const noexcept {
189 return sim.Time() - birth;
192 double Creature::AgeFactor(double peak) const noexcept {
193 // shifted inverse hermite, y = 1 - (3t² - 2t³) with t = normalized age - peak
194 // goes negative below -0.5 and starts to rise again above 1.0
195 double t = glm::clamp((Age() / properties.Lifetime()) - peak, -0.5, 1.0);
196 return 1.0 - (3.0 * t * t) + (2.0 * t * t * t);
199 double Creature::ExhaustionFactor() const noexcept {
200 return 1.0 - (glm::smoothstep(0.5, 1.0, stats.Exhaustion().value) * 0.5);
203 double Creature::FatigueFactor() const noexcept {
204 return 1.0 - (glm::smoothstep(0.5, 1.0, stats.Fatigue().value) * 0.5);
207 double Creature::Strength() const noexcept {
208 // TODO: replace all age factors with actual growth and decay
209 return properties.Strength() * ExhaustionFactor() * AgeFactor(0.25);
212 double Creature::Stamina() const noexcept {
213 return properties.Stamina() * ExhaustionFactor() * AgeFactor(0.25);
216 double Creature::Dexerty() const noexcept {
217 return properties.Dexerty() * ExhaustionFactor() * AgeFactor(0.25);
220 double Creature::Intelligence() const noexcept {
221 return properties.Intelligence() * FatigueFactor() * AgeFactor(0.25);
224 double Creature::Lifetime() const noexcept {
225 return properties.Lifetime();
228 double Creature::Fertility() const noexcept {
229 return properties.Fertility() * AgeFactor(0.25);
232 double Creature::Mutability() const noexcept {
233 return properties.Mutability();
236 double Creature::OffspringMass() const noexcept {
237 return properties.OffspringMass();
240 double Creature::OffspringChance() const noexcept {
241 return AgeFactor(0.25) * properties.Fertility() * (1.0 / 3600.0);
244 double Creature::MutateChance() const noexcept {
245 return GetProperties().Mutability() * (1.0 / 3600.0);
248 void Creature::AddGoal(std::unique_ptr<Goal> &&g) {
250 goals.emplace_back(std::move(g));
255 bool GoalCompare(const std::unique_ptr<Goal> &a, const std::unique_ptr<Goal> &b) {
256 return b->Urgency() < a->Urgency();
261 void Creature::Tick(double dt) {
267 void Creature::TickState(double dt) {
268 steering.MaxSpeed(Dexerty());
269 steering.MaxForce(Strength());
270 Situation::State state(situation.GetState());
271 Situation::Derivative a(Step(Situation::Derivative(), 0.0));
272 Situation::Derivative b(Step(a, dt * 0.5));
273 Situation::Derivative c(Step(b, dt * 0.5));
274 Situation::Derivative d(Step(c, dt));
275 Situation::Derivative f(
276 (1.0 / 6.0) * (a.vel + 2.0 * (b.vel + c.vel) + d.vel),
277 (1.0 / 6.0) * (a.acc + 2.0 * (b.acc + c.acc) + d.acc)
279 state.pos += f.vel * dt;
280 state.vel += f.acc * dt;
281 if (length2(state.vel) > 0.000001) {
282 glm::dvec3 nvel(normalize(state.vel));
283 double ang = angle(nvel, state.dir);
284 double turn_rate = PI * 0.5 * dt;
285 if (ang < turn_rate) {
286 state.dir = normalize(state.vel);
287 } else if (std::abs(ang - PI) < 0.001) {
288 state.dir = rotate(state.dir, turn_rate, world::Planet::SurfaceNormal(situation.Surface()));
290 state.dir = rotate(state.dir, turn_rate, normalize(cross(state.dir, nvel)));
293 situation.SetState(state);
294 stats.Exhaustion().Add(length(f.acc) * Mass() / Stamina() * dt);
297 Situation::Derivative Creature::Step(const Situation::Derivative &ds, double dt) const noexcept {
298 Situation::State s = situation.GetState();
299 s.pos += ds.vel * dt;
300 s.vel += ds.acc * dt;
303 steering.Force(s) / Mass()
307 void Creature::TickStats(double dt) {
308 for (auto &s : stats.stat) {
311 stats.Breath().Add(stats.Breath().gain * stats.Exhaustion().value * dt);
312 // TODO: damage values depending on properties
313 if (stats.Breath().Full()) {
314 constexpr double dps = 1.0 / 4.0;
317 if (stats.Thirst().Full()) {
318 constexpr double dps = 1.0 / 32.0;
321 if (stats.Hunger().Full()) {
322 constexpr double dps = 1.0 / 128.0;
325 if (!situation.Moving()) {
326 // double exhaustion recovery when standing still
327 stats.Exhaustion().Add(stats.Exhaustion().gain * dt);
331 void Creature::TickBrain(double dt) {
335 // do background stuff
339 for (auto &goal : goals) {
342 // if active goal can be interrupted, check priorities
343 if (goals.size() > 1 && goals[0]->Interruptible()) {
344 std::sort(goals.begin(), goals.end(), GoalCompare);
347 for (auto goal = goals.begin(); goal != goals.end();) {
348 if ((*goal)->Complete()) {
356 math::AABB Creature::CollisionBox() const noexcept {
357 return { glm::dvec3(size * -0.5), glm::dvec3(size * 0.5) };
360 glm::dmat4 Creature::CollisionTransform() const noexcept {
361 const double half_size = size * 0.5;
362 const glm::dvec3 &pos = situation.Position();
363 const glm::dmat3 srf(world::Planet::SurfaceOrientation(situation.Surface()));
364 return glm::translate(glm::dvec3(pos.x, pos.y, pos.z + half_size))
365 * glm::rotate(glm::orientedAngle(-srf[2], situation.Heading(), srf[1]), srf[1])
369 glm::dmat4 Creature::LocalTransform() noexcept {
370 const double half_size = size * 0.5;
371 return CollisionTransform()
372 * glm::scale(glm::dvec3(half_size, half_size, half_size));
375 void Creature::BuildVAO() {
377 vao.BindAttributes();
378 vao.EnableAttribute(0);
379 vao.EnableAttribute(1);
380 vao.EnableAttribute(2);
381 vao.AttributePointer<glm::vec3>(0, false, offsetof(Attributes, position));
382 vao.AttributePointer<glm::vec3>(1, false, offsetof(Attributes, normal));
383 vao.AttributePointer<glm::vec3>(2, false, offsetof(Attributes, texture));
384 vao.ReserveAttributes(6 * 4, GL_STATIC_DRAW);
386 auto attrib = vao.MapAttributes(GL_WRITE_ONLY);
387 const float offset = 1.0f;
388 for (int surface = 0; surface < 6; ++surface) {
389 const float tex_u_begin = surface < 3 ? 1.0f : 0.0f;
390 const float tex_u_end = surface < 3 ? 0.0f : 1.0f;
392 attrib[4 * surface + 0].position[(surface + 0) % 3] = -offset;
393 attrib[4 * surface + 0].position[(surface + 1) % 3] = -offset;
394 attrib[4 * surface + 0].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
395 attrib[4 * surface + 0].normal[(surface + 0) % 3] = 0.0f;
396 attrib[4 * surface + 0].normal[(surface + 1) % 3] = 0.0f;
397 attrib[4 * surface + 0].normal[(surface + 2) % 3] = surface < 3 ? 1.0f : -1.0f;
398 attrib[4 * surface + 0].texture.x = tex_u_begin;
399 attrib[4 * surface + 0].texture.y = 1.0f;
400 attrib[4 * surface + 0].texture.z = surface;
402 attrib[4 * surface + 1].position[(surface + 0) % 3] = -offset;
403 attrib[4 * surface + 1].position[(surface + 1) % 3] = offset;
404 attrib[4 * surface + 1].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
405 attrib[4 * surface + 1].normal[(surface + 0) % 3] = 0.0f;
406 attrib[4 * surface + 1].normal[(surface + 1) % 3] = 0.0f;
407 attrib[4 * surface + 1].normal[(surface + 2) % 3] = surface < 3 ? 1.0f : -1.0f;
408 attrib[4 * surface + 1].texture.x = tex_u_end;
409 attrib[4 * surface + 1].texture.y = 1.0f;
410 attrib[4 * surface + 1].texture.z = surface;
412 attrib[4 * surface + 2].position[(surface + 0) % 3] = offset;
413 attrib[4 * surface + 2].position[(surface + 1) % 3] = -offset;
414 attrib[4 * surface + 2].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
415 attrib[4 * surface + 2].normal[(surface + 0) % 3] = 0.0f;
416 attrib[4 * surface + 2].normal[(surface + 1) % 3] = 0.0f;
417 attrib[4 * surface + 2].normal[(surface + 2) % 3] = surface < 3 ? 1.0f : -1.0f;
418 attrib[4 * surface + 2].texture.x = tex_u_begin;
419 attrib[4 * surface + 2].texture.y = 0.0f;
420 attrib[4 * surface + 2].texture.z = surface;
422 attrib[4 * surface + 3].position[(surface + 0) % 3] = offset;
423 attrib[4 * surface + 3].position[(surface + 1) % 3] = offset;
424 attrib[4 * surface + 3].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
425 attrib[4 * surface + 3].normal[(surface + 0) % 3] = 0.0f;
426 attrib[4 * surface + 3].normal[(surface + 1) % 3] = 0.0f;
427 attrib[4 * surface + 3].normal[(surface + 2) % 3] = surface < 3 ? 1.0f : -1.0f;
428 attrib[4 * surface + 3].texture.x = tex_u_end;
429 attrib[4 * surface + 3].texture.y = 0.0f;
430 attrib[4 * surface + 3].texture.z = surface;
434 vao.ReserveElements(6 * 6, GL_STATIC_DRAW);
436 auto element = vao.MapElements(GL_WRITE_ONLY);
437 for (int surface = 0; surface < 3; ++surface) {
438 element[6 * surface + 0] = 4 * surface + 0;
439 element[6 * surface + 1] = 4 * surface + 2;
440 element[6 * surface + 2] = 4 * surface + 1;
441 element[6 * surface + 3] = 4 * surface + 1;
442 element[6 * surface + 4] = 4 * surface + 2;
443 element[6 * surface + 5] = 4 * surface + 3;
445 for (int surface = 3; surface < 6; ++surface) {
446 element[6 * surface + 0] = 4 * surface + 0;
447 element[6 * surface + 1] = 4 * surface + 1;
448 element[6 * surface + 2] = 4 * surface + 2;
449 element[6 * surface + 3] = 4 * surface + 2;
450 element[6 * surface + 4] = 4 * surface + 1;
451 element[6 * surface + 5] = 4 * surface + 3;
457 void Creature::Draw(graphics::Viewport &viewport) {
459 vao.DrawTriangles(6 * 6);
463 void Spawn(Creature &c, world::Planet &p) {
465 c.GetSituation().SetPlanetSurface(p, 0, p.TileCenter(0, p.SideLength() / 2, p.SideLength() / 2));
466 c.GetSituation().Heading(-world::Planet::SurfaceOrientation(0)[2]);
468 // probe surrounding area for common resources
469 int start = p.SideLength() / 2 - 2;
471 std::map<int, double> yields;
472 for (int y = start; y < end; ++y) {
473 for (int x = start; x < end; ++x) {
474 const world::TileType &t = p.TypeAt(0, x, y);
475 for (auto yield : t.resources) {
476 yields[yield.resource] += yield.ubiquity;
482 for (auto e : yields) {
483 if (c.GetSimulation().Resources()[e.first].state == world::Resource::LIQUID) {
484 if (liquid < 0 || e.second > yields[liquid]) {
487 } else if (c.GetSimulation().Resources()[e.first].state == world::Resource::SOLID) {
488 if (solid < 0 || e.second > yields[solid]) {
495 genome.properties.Strength() = { 2.0, 0.1 };
496 genome.properties.Stamina() = { 2.0, 0.1 };
497 genome.properties.Dexerty() = { 2.0, 0.1 };
498 genome.properties.Intelligence() = { 1.0, 0.1 };
499 genome.properties.Lifetime() = { 480.0, 60.0 };
500 genome.properties.Fertility() = { 0.5, 0.03 };
501 genome.properties.Mutability() = { 1.0, 0.1 };
502 genome.properties.OffspringMass() = { 0.3, 0.02 };
504 glm::dvec3 color_avg(0.0);
505 double color_divisor = 0.0;
507 if (p.HasAtmosphere()) {
508 c.AddMass(p.Atmosphere(), 0.01);
509 color_avg += c.GetSimulation().Resources()[p.Atmosphere()].base_color * 0.1;
510 color_divisor += 0.1;
513 c.AddMass(liquid, 0.3);
514 color_avg += c.GetSimulation().Resources()[liquid].base_color * 0.5;
515 color_divisor += 0.5;
518 c.AddMass(solid, 0.1);
519 color_avg += c.GetSimulation().Resources()[solid].base_color;
520 color_divisor += 1.0;
523 if (color_divisor > 0.001) {
524 color_avg /= color_divisor;
526 glm::dvec3 hsl = rgb2hsl(color_avg);
527 genome.base_hue = { hsl.x, 0.01 };
528 genome.base_saturation = { hsl.y, 0.01 };
529 genome.base_lightness = { hsl.z, 0.01 };
534 void Genome::Configure(Creature &c) const {
535 c.GetGenome() = *this;
537 math::GaloisLFSR &random = c.GetSimulation().Assets().random;
539 c.GetProperties() = Instantiate(properties, random);
541 // TODO: derive stats from properties
542 c.GetStats().Damage().gain = (-1.0 / 100.0);
543 c.GetStats().Breath().gain = (1.0 / 5.0);
544 c.GetStats().Thirst().gain = (1.0 / 60.0);
545 c.GetStats().Hunger().gain = (1.0 / 200.0);
546 c.GetStats().Exhaustion().gain = (-1.0 / 100.0);
547 c.GetStats().Fatigue().gain = (-1.0 / 100.0);
548 c.GetStats().Boredom().gain = (1.0 / 300.0);
550 glm::dvec3 base_color(
551 std::fmod(base_hue.FakeNormal(random.SNorm()) + 1.0, 1.0),
552 glm::clamp(base_saturation.FakeNormal(random.SNorm()), 0.0, 1.0),
553 glm::clamp(base_lightness.FakeNormal(random.SNorm()), 0.0, 1.0)
555 glm::dvec3 highlight_color(
556 std::fmod(base_color.x + 0.5, 1.0),
560 c.BaseColor(hsl2rgb(base_color));
561 c.HighlightColor(hsl2rgb(highlight_color));
562 c.SetBackgroundTask(std::unique_ptr<Goal>(new BlobBackgroundTask(c)));
563 c.AddGoal(std::unique_ptr<Goal>(new IdleGoal(c)));
567 void Split(Creature &c) {
568 Creature *a = new Creature(c.GetSimulation());
569 const Situation &s = c.GetSituation();
570 a->Name(c.GetSimulation().Assets().name.Sequential());
571 c.GetGenome().Configure(*a);
572 for (const auto &cmp : c.GetComposition()) {
573 a->AddMass(cmp.resource, cmp.value * 0.5);
575 s.GetPlanet().AddCreature(a);
576 // TODO: duplicate situation somehow
577 a->GetSituation().SetPlanetSurface(
578 s.GetPlanet(), s.Surface(),
579 s.Position() + glm::dvec3(0.0, a->Size() + 0.1, 0.0));
581 std::cout << "[" << int(c.GetSimulation().Time()) << "s] "
582 << a->Name() << " was born" << std::endl;
584 Creature *b = new Creature(c.GetSimulation());
585 b->Name(c.GetSimulation().Assets().name.Sequential());
586 c.GetGenome().Configure(*b);
587 for (const auto &cmp : c.GetComposition()) {
588 b->AddMass(cmp.resource, cmp.value * 0.5);
590 s.GetPlanet().AddCreature(b);
591 b->GetSituation().SetPlanetSurface(
592 s.GetPlanet(), s.Surface(),
593 s.Position() + glm::dvec3(0.0, b->Size() - 0.1, 0.0));
595 std::cout << "[" << int(c.GetSimulation().Time()) << "s] "
596 << b->Name() << " was born" << std::endl;
602 Memory::Memory(Creature &c)
609 void Memory::Tick(double dt) {
610 Situation &s = c.GetSituation();
612 TrackStay({ &s.GetPlanet(), s.Surface(), s.SurfacePosition() }, dt);
616 void Memory::TrackStay(const Location &l, double t) {
617 const world::TileType &type = l.planet->TypeAt(l.surface, l.coords.x, l.coords.y);
618 auto entry = known_types.find(type.id);
619 if (entry != known_types.end()) {
620 if (c.GetSimulation().Time() - entry->second.last_been > c.GetProperties().Lifetime() * 0.1) {
622 if (entry->second.time_spent > c.Age() * 0.25) {
623 // the place is very familiar
624 c.GetStats().Boredom().Add(-0.2);
627 c.GetStats().Boredom().Add(-0.1);
630 entry->second.last_been = c.GetSimulation().Time();
631 entry->second.last_loc = l;
632 entry->second.time_spent += t;
634 known_types.emplace(type.id, Stay{
635 c.GetSimulation().Time(),
637 c.GetSimulation().Time(),
641 // completely new place, interesting
642 // TODO: scale by personality trait
643 c.GetStats().Boredom().Add(-0.25);
648 NameGenerator::NameGenerator()
652 NameGenerator::~NameGenerator() {
655 std::string NameGenerator::Sequential() {
656 std::stringstream ss;
657 ss << "Blob " << ++counter;
662 Situation::Situation()
664 , state(glm::dvec3(0.0), glm::dvec3(0.0))
669 Situation::~Situation() {
672 bool Situation::OnPlanet() const noexcept {
673 return type == PLANET_SURFACE;
676 bool Situation::OnSurface() const noexcept {
677 return type == PLANET_SURFACE;
680 bool Situation::OnTile() const noexcept {
681 glm::ivec2 t(planet->SurfacePosition(surface, state.pos));
682 return type == PLANET_SURFACE
683 && t.x >= 0 && t.x < planet->SideLength()
684 && t.y >= 0 && t.y < planet->SideLength();
687 glm::ivec2 Situation::SurfacePosition() const noexcept {
688 return planet->SurfacePosition(surface, state.pos);
691 world::Tile &Situation::GetTile() const noexcept {
692 glm::ivec2 t(planet->SurfacePosition(surface, state.pos));
693 return planet->TileAt(surface, t.x, t.y);
696 const world::TileType &Situation::GetTileType() const noexcept {
697 glm::ivec2 t(planet->SurfacePosition(surface, state.pos));
698 return planet->TypeAt(surface, t.x, t.y);
701 void Situation::Move(const glm::dvec3 &dp) noexcept {
704 // enforce ground constraint
706 state.pos[(Surface() + 2) % 3] = std::max(0.0, state.pos[(Surface() + 2) % 3]);
708 state.pos[(Surface() + 2) % 3] = std::min(0.0, state.pos[(Surface() + 2) % 3]);
713 void Situation::SetPlanetSurface(world::Planet &p, int srf, const glm::dvec3 &pos) noexcept {
714 type = PLANET_SURFACE;
721 Steering::Steering(const Creature &c)
735 Steering::~Steering() {
738 void Steering::Separate(double min_distance, double max_lookaround) noexcept {
740 min_dist = min_distance;
741 max_look = max_lookaround;
744 void Steering::DontSeparate() noexcept {
748 void Steering::ResumeSeparate() noexcept {
752 void Steering::Halt() noexcept {
758 void Steering::Pass(const glm::dvec3 &t) noexcept {
765 void Steering::GoTo(const glm::dvec3 &t) noexcept {
772 glm::dvec3 Steering::Force(const Situation::State &s) const noexcept {
773 double speed = max_speed * glm::clamp(max_speed * haste * haste, 0.25, 1.0);
774 double force = max_speed * glm::clamp(max_force * haste * haste, 0.5, 1.0);
775 glm::dvec3 result(0.0);
777 // TODO: off surface situation
778 glm::dvec3 repulse(0.0);
779 const Situation &s = c.GetSituation();
780 for (auto &other : s.GetPlanet().Creatures()) {
781 if (&*other == &c) continue;
782 glm::dvec3 diff = s.Position() - other->GetSituation().Position();
783 if (length2(diff) > max_look * max_look) continue;
784 double sep = length(diff) - other->Size() * 0.707 - c.Size() * 0.707;
785 if (sep < min_dist) {
786 repulse += normalize(diff) * (1.0 - sep / min_dist);
789 SumForce(result, repulse, force);
792 SumForce(result, s.vel * -force, force);
795 glm::dvec3 diff = target - s.pos;
796 if (!allzero(diff)) {
797 SumForce(result, TargetVelocity(s, (normalize(diff) * speed), force), force);
801 glm::dvec3 diff = target - s.pos;
802 double dist = length(diff);
803 if (!allzero(diff) && dist > std::numeric_limits<double>::epsilon()) {
804 SumForce(result, TargetVelocity(s, diff * std::min(dist * force, speed) / dist, force), force);
810 bool Steering::SumForce(glm::dvec3 &out, const glm::dvec3 &in, double max) const noexcept {
811 if (allzero(in) || anynan(in)) {
814 double cur = allzero(out) ? 0.0 : length(out);
815 double rem = max - cur;
819 double add = length(in);
821 // this method is off if in and out are in different
822 // directions, but gives okayish results
823 out += in * (1.0 / add);
831 glm::dvec3 Steering::TargetVelocity(const Situation::State &s, const glm::dvec3 &vel, double acc) const noexcept {
832 return (vel - s.vel) * acc;