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 | |
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
-rw-r--r-- | application/main.cpp | 4 | ||||
-rw-r--r-- | game/vehicles/railloco.cpp | 30 | ||||
-rw-r--r-- | game/vehicles/railloco.h | 14 | ||||
-rw-r--r-- | game/vehicles/vehicle.cpp | 6 | ||||
-rw-r--r-- | game/vehicles/vehicle.h | 19 | ||||
-rw-r--r-- | res/brush47.mtl | 13 | ||||
-rw-r--r-- | res/brush47.obj | 203 | ||||
-rw-r--r-- | res/brush47.png | bin | 0 -> 98156 bytes | |||
-rw-r--r-- | test/Jamfile.jam | 1 | ||||
-rw-r--r-- | test/test-obj.cpp | 21 |
10 files changed, 310 insertions, 1 deletions
diff --git a/application/main.cpp b/application/main.cpp index 30b4a44..8b2488f 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -3,6 +3,7 @@ #include <collection.hpp> #include <game/network/rail.h> #include <game/terrain.h> +#include <game/vehicles/railloco.h> #include <game/world.h> #include <game/worldobject.h> #include <gfx/camera_controller.h> @@ -70,8 +71,9 @@ public: const glm::vec3 j {-1100, 5, -1100}, k {-1100, 15, -1000}, l {-1150, 30, -1050}, m {-1050, 10, -1050}; rl->addLink<RailLinkStraight>(j, k); rl->addLink<RailLinkCurve>(l, k, glm::vec2 {l.x, k.z}); - rl->addLink<RailLinkStraight>(l, m); + auto l3 = rl->addLink<RailLinkStraight>(l, m); rl->addLink<RailLinkCurve>(m, j, glm::vec2 {m.x, j.z}); + world.create<Brush47>(l3); } Shader shader; 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") { } diff --git a/game/vehicles/railloco.h b/game/vehicles/railloco.h new file mode 100644 index 0000000..05e3e48 --- /dev/null +++ b/game/vehicles/railloco.h @@ -0,0 +1,14 @@ +#include "game/worldobject.h" +#include "vehicle.h" +#include <string> + +class RailLoco : public Vehicle { +public: + using Vehicle::Vehicle; + void tick(TickDuration elapsed) override; +}; + +class Brush47 : public RailLoco { +public: + Brush47(LinkPtr p); +}; diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp new file mode 100644 index 0000000..4c4ac71 --- /dev/null +++ b/game/vehicles/vehicle.cpp @@ -0,0 +1,6 @@ +#include "vehicle.h" + +Vehicle::Vehicle(LinkPtr l, const std::string & obj, const std::string & tex) : + Physical(l->ends.front().first->pos, obj, tex), link(l) +{ +} diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h new file mode 100644 index 0000000..01be6a6 --- /dev/null +++ b/game/vehicles/vehicle.h @@ -0,0 +1,19 @@ +#ifndef VEHICLE_H +#define VEHICLE_H + +#include "game/physical.h" +#include <game/network/link.h> +#include <game/worldobject.h> +#include <glm/glm.hpp> +#include <string> + +class Vehicle : public WorldObject, public Physical { +public: + Vehicle(LinkPtr link, const std::string & obj, const std::string & tex); + LinkPtr link; // Which link are we travelling along + unsigned char linkDir {0}; // Starting end e0->e1 or e1->e0 + float linkDist {0}; // distance long current link + float speed {50}; // speed in m/s (~75 km/h) +}; + +#endif diff --git a/res/brush47.mtl b/res/brush47.mtl new file mode 100644 index 0000000..0e3563b --- /dev/null +++ b/res/brush47.mtl @@ -0,0 +1,13 @@ +# Blender MTL File: 'brush47.blend' +# Material Count: 1 + +newmtl Material.004 +Ns 225.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 +map_Kd /home/randomdan/dev/ilt-raw/brush47/brush47.png diff --git a/res/brush47.obj b/res/brush47.obj new file mode 100644 index 0000000..d60409a --- /dev/null +++ b/res/brush47.obj @@ -0,0 +1,203 @@ +# Blender v2.91.0 OBJ File: 'brush47.blend' +# www.blender.org +mtllib brush47.mtl +o Brush_47_Brush47 +v 1.326000 0.100000 2.700000 +v 1.326000 1.100000 2.700000 +v 1.326000 0.100000 9.300000 +v 1.326000 1.100000 9.300000 +v -1.326000 0.100000 2.700000 +v -1.326000 1.100000 2.700000 +v -1.326000 0.100000 9.300000 +v -1.326000 1.100000 9.300000 +v -1.326000 0.100000 -2.700000 +v -1.326000 0.100000 -9.300000 +v -1.326000 1.100000 -9.300000 +v -1.326000 1.100000 -2.700000 +v 1.326000 0.100000 -2.700000 +v 1.326000 1.100000 -2.700000 +v 1.326000 0.100000 -9.300000 +v 1.326000 1.100000 -9.300000 +v -1.345000 1.200000 -9.690000 +v -1.345000 1.200000 9.690000 +v 1.345000 1.200000 -9.690000 +v 1.345000 1.200000 9.690000 +v -0.991447 3.900000 -8.536446 +v -1.345000 3.546447 -9.440000 +v -0.991447 3.900000 8.536446 +v -1.345000 3.546447 9.440000 +v 0.991447 3.900000 -8.536446 +v 1.345000 3.546447 -9.440000 +v 0.991447 3.900000 8.536446 +v 1.345000 3.546447 9.440000 +v -1.345000 2.723224 9.690000 +v 1.345000 2.723224 9.690000 +v 1.345000 2.723224 -9.690000 +v -1.345000 2.723224 -9.690000 +v 1.340000 0.200000 9.600000 +v -1.340000 0.200000 9.600000 +v 1.340000 1.200000 9.600000 +v -1.340000 1.200000 9.600000 +v -1.340000 0.200000 -9.600000 +v 1.340000 0.200000 -9.600000 +v -1.340000 1.200000 -9.600000 +v 1.340000 1.200000 -9.600000 +v -1.300000 0.200000 -2.250000 +v -1.300000 1.200000 -2.250000 +v -1.300000 0.200000 2.250000 +v -1.300000 1.200000 2.250000 +v 1.300000 0.200000 -2.250000 +v 1.300000 1.200000 -2.250000 +v 1.300000 0.200000 2.250000 +v 1.300000 1.200000 2.250000 +vt 0.342014 0.435417 +vt 0.006076 0.435417 +vt 0.006076 0.591667 +vt 0.342014 0.591667 +vt 0.987847 0.602083 +vt 0.987847 0.464583 +vt 0.931424 0.464583 +vt 0.931424 0.602083 +vt 0.006076 0.435417 +vt 0.342014 0.435417 +vt 0.342014 0.591667 +vt 0.006076 0.591667 +vt 0.987847 0.602083 +vt 0.987847 0.464583 +vt 0.931424 0.464583 +vt 0.931424 0.602083 +vt 0.043403 0.081250 +vt 0.043403 0.014583 +vt 0.002604 0.014583 +vt 0.002604 0.081250 +vt 0.342014 0.435417 +vt 0.342014 0.591667 +vt 0.006076 0.591667 +vt 0.006076 0.435417 +vt 0.043403 0.014583 +vt 0.002604 0.014583 +vt 0.002604 0.081250 +vt 0.043403 0.081250 +vt 0.342014 0.435417 +vt 0.342014 0.591667 +vt 0.006076 0.591667 +vt 0.006076 0.435417 +vt 0.043403 0.014583 +vt 0.002604 0.014583 +vt 0.002604 0.081250 +vt 0.043403 0.081250 +vt 0.043403 0.081250 +vt 0.043403 0.014583 +vt 0.025174 0.662500 +vt 0.025174 0.831250 +vt 0.037326 0.925000 +vt 0.957465 0.927083 +vt 0.971354 0.833333 +vt 0.971354 0.662500 +vt 0.025174 0.662500 +vt 0.025174 0.831250 +vt 0.037326 0.925000 +vt 0.957465 0.927083 +vt 0.971354 0.833333 +vt 0.971354 0.662500 +vt 0.002604 0.014583 +vt 0.002604 0.081250 +vt 0.043403 0.081250 +vt 0.043403 0.014583 +vt 0.926215 0.527083 +vt 0.926215 0.612500 +vt 0.834201 0.612500 +vt 0.834201 0.527083 +vt 0.834201 0.527083 +vt 0.834201 0.612500 +vt 0.927083 0.612500 +vt 0.927083 0.527083 +vt 0.114583 0.293750 +vt 0.114583 0.414583 +vt 0.010417 0.414583 +vt 0.010417 0.293750 +vt 0.010417 0.293750 +vt 0.010417 0.414583 +vt 0.114583 0.414583 +vt 0.114583 0.293750 +vt 0.043403 0.081250 +vt 0.043403 0.014583 +vt 0.002604 0.014583 +vt 0.002604 0.081250 +vt 0.043403 0.081250 +vt 0.043403 0.014583 +vt 0.002604 0.014583 +vt 0.002604 0.081250 +vt 0.605035 0.456250 +vt 0.605035 0.581250 +vt 0.359375 0.581250 +vt 0.359375 0.456250 +vt 0.605035 0.581250 +vt 0.605035 0.456250 +vt 0.359375 0.581250 +vt 0.359375 0.456250 +vt 0.088542 0.089583 +vt 0.088542 0.206250 +vt 0.918403 0.206250 +vt 0.918403 0.089583 +vt 0.083333 0.989583 +vt 0.913194 0.989583 +vt 0.037326 0.927083 +vt 0.152778 0.364583 +vt 0.197049 0.364583 +vt 0.204861 0.310417 +vt 0.144965 0.310417 +vt 0.083333 0.989583 +vt 0.913194 0.989583 +vt 0.037326 0.927083 +vt 0.152778 0.364583 +vt 0.197049 0.364583 +vt 0.204861 0.310417 +vt 0.144965 0.310417 +vn -1.0000 0.0000 -0.0000 +vn 0.0000 0.0000 -1.0000 +vn 1.0000 0.0000 0.0000 +vn 0.0000 0.0000 1.0000 +vn 0.0000 -1.0000 0.0000 +vn 0.0000 1.0000 0.0000 +vn -0.0000 -0.2906 -0.9569 +vn 0.0000 -0.2906 0.9569 +vn -0.3335 -0.9344 -0.1252 +vn 0.3335 -0.9344 -0.1252 +vn 0.3335 -0.9344 0.1252 +vn -0.3335 -0.9344 0.1252 +vn 0.6276 -0.5509 -0.5500 +vn 0.6276 -0.5509 0.5500 +vn -0.6276 -0.5509 -0.5500 +vn -0.6276 -0.5509 0.5500 +usemtl Material.004 +s off +f 1/1/1 3/2/1 4/3/1 2/4/1 +f 3/5/2 7/6/2 8/7/2 4/8/2 +f 7/9/3 5/10/3 6/11/3 8/12/3 +f 5/13/4 1/14/4 2/15/4 6/16/4 +f 8/17/5 6/18/5 2/19/5 4/20/5 +f 10/21/3 11/22/3 12/23/3 9/24/3 +f 9/25/2 12/26/2 14/27/2 13/28/2 +f 13/29/1 14/30/1 16/31/1 15/32/1 +f 15/33/4 16/34/4 11/35/4 10/36/4 +f 14/27/5 12/37/5 11/38/5 16/34/5 +f 20/39/1 30/40/1 28/41/1 26/42/1 31/43/1 19/44/1 +f 17/45/3 32/46/3 22/47/3 24/48/3 29/49/3 18/50/3 +f 18/51/6 20/52/6 19/53/6 17/54/6 +f 29/55/7 24/56/7 28/57/7 30/58/7 +f 31/59/8 26/60/8 22/61/8 32/62/8 +f 18/63/2 29/64/2 30/65/2 20/66/2 +f 19/67/4 31/68/4 32/69/4 17/70/4 +f 33/71/2 34/72/2 36/73/2 35/74/2 +f 37/75/4 38/76/4 40/77/4 39/78/4 +f 41/79/3 42/80/3 44/81/3 43/82/3 +f 43/82/2 44/81/2 48/83/2 47/84/2 +f 47/84/1 48/83/1 46/85/1 45/86/1 +f 45/86/4 46/85/4 42/80/4 41/79/4 +s 1 +f 27/87/9 23/88/10 21/89/11 25/90/12 +f 21/91/11 23/92/10 24/48/13 22/93/14 +f 23/94/10 27/95/9 28/96/15 24/97/13 +f 27/98/9 25/99/12 26/42/16 28/100/15 +f 25/101/12 21/102/11 22/103/14 26/104/16 diff --git a/res/brush47.png b/res/brush47.png Binary files differnew file mode 100644 index 0000000..97fd77d --- /dev/null +++ b/res/brush47.png diff --git a/test/Jamfile.jam b/test/Jamfile.jam index c6e6d5e..ffc1a19 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -15,4 +15,5 @@ project : requirements ; run test-collection.cpp ; +run test-obj.cpp ; run test-maths.cpp ; diff --git a/test/test-obj.cpp b/test/test-obj.cpp new file mode 100644 index 0000000..337df99 --- /dev/null +++ b/test/test-obj.cpp @@ -0,0 +1,21 @@ +#define BOOST_TEST_MODULE test_obj + +#include <boost/test/unit_test.hpp> + +#include <gfx/models/obj.h> +#include <memory> +#include <vector> + +BOOST_AUTO_TEST_CASE(objparse) +{ + ObjParser op {"/home/randomdan/dev/game/res/brush47.obj"}; + BOOST_REQUIRE_EQUAL(0, op.yylex()); + BOOST_CHECK_EQUAL(48, op.vertices.size()); + BOOST_CHECK_EQUAL(104, op.texCoords.size()); + BOOST_CHECK_EQUAL(16, op.normals.size()); + BOOST_CHECK_EQUAL(28, op.faces.size()); + BOOST_CHECK_EQUAL(4, op.faces[0].size()); + BOOST_CHECK_EQUAL(6, op.faces[10].size()); + BOOST_CHECK_EQUAL(6, op.faces[11].size()); + BOOST_CHECK_EQUAL(4, op.faces[12].size()); +} |