diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-14 14:19:21 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-14 14:19:21 +0000 |
commit | c08e33649931b679b17488ba6f7dab1d628213fd (patch) | |
tree | 76382c1740e4605667dce2fc74f03034f0b34960 /game/vehicles/railloco.cpp | |
parent | Apply pitch to vehicles on a link (diff) | |
download | ilt-c08e33649931b679b17488ba6f7dab1d628213fd.tar.bz2 ilt-c08e33649931b679b17488ba6f7dab1d628213fd.tar.xz ilt-c08e33649931b679b17488ba6f7dab1d628213fd.zip |
Add our first vehicle
Diffstat (limited to 'game/vehicles/railloco.cpp')
-rw-r--r-- | game/vehicles/railloco.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/game/vehicles/railloco.cpp b/game/vehicles/railloco.cpp new file mode 100644 index 0000000..baa9b81 --- /dev/null +++ b/game/vehicles/railloco.cpp @@ -0,0 +1,30 @@ +#include "railloco.h" +#include "game/vehicles/vehicle.h" +#include "gfx/gl/transform.h" +#include <glm/glm.hpp> +#include <maths.h> + +void +RailLoco::tick(TickDuration dur) +{ + linkDist += dur.count() * speed; + while (linkDist > link->length) { + location = link->positionAt(link->length, linkDir); + const auto & nexts {link->nexts[1 - linkDir]}; + const auto next = std::find_if(nexts.begin(), nexts.end(), [ang = location.GetRot().y](const Link::Next & n) { + return std::abs(normalize(n.first->ends[n.second].second - ang)) < 0.1F; + }); + if (next != nexts.end()) { + linkDist -= link->length; + link = next->first; + linkDir = next->second; + } + else { + linkDist = link->length; + speed = 0; + } + } + location = link->positionAt(linkDist, linkDir); +} + +Brush47::Brush47(LinkPtr l) : RailLoco(l, "brush47.obj", "brush47.png") { } |