diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-05 01:59:16 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-05 01:59:16 +0000 |
commit | d4c073a18adaed73973f34c6c39fc15664d9211d (patch) | |
tree | 44536af3af0284ab75eae79ef81a5e4452019269 /game | |
parent | Add helper operator to perform vec3*mat4 and perspective divide (diff) | |
parent | Remove old hard coded asset factory test, run entirely from XML load and rend... (diff) | |
download | ilt-d4c073a18adaed73973f34c6c39fc15664d9211d.tar.bz2 ilt-d4c073a18adaed73973f34c6c39fc15664d9211d.tar.xz ilt-d4c073a18adaed73973f34c6c39fc15664d9211d.zip |
Merge branch 'model-factory'
Diffstat (limited to 'game')
-rw-r--r-- | game/vehicles/railVehicle.cpp | 8 | ||||
-rw-r--r-- | game/vehicles/railVehicle.h | 2 | ||||
-rw-r--r-- | game/vehicles/railVehicleClass.cpp | 21 | ||||
-rw-r--r-- | game/vehicles/railVehicleClass.h | 10 |
4 files changed, 35 insertions, 6 deletions
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index bcde68f..77907be 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -11,6 +11,12 @@ #include <memory> #include <ray.hpp> +RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)} +{ + bogies.front().pos.y = rvClass->wheelBase / 2.F; + bogies.back().pos.y = -bogies.front().pos.y; +} + void RailVehicle::render(const SceneShader & shader) const { @@ -20,7 +26,7 @@ RailVehicle::render(const SceneShader & shader) const void RailVehicle::shadows(const ShadowMapper & shadowMapper) const { - rvClass->shadows(shadowMapper, location); + rvClass->shadows(shadowMapper, location, bogies); } void diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index f172a28..bbf4df9 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -16,7 +16,7 @@ class Ray; class Train; class RailVehicle : public Renderable, Selectable { public: - explicit RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)} { } + explicit RailVehicle(RailVehicleClassPtr rvc); void move(const Train *, float & trailBy); diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index dff1416..41ef5e9 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -39,12 +39,24 @@ RailVehicleClass::RailVehicleClass(std::unique_ptr<ObjParser> o, std::shared_ptr bogies[1] = m.at("Bogie2"); } +RailVehicleClass::RailVehicleClass() { } + +bool +RailVehicleClass::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(length) && STORE_MEMBER(wheelBase) && STORE_MEMBER(maxSpeed) + && STORE_NAME_HELPER("bogie", bogies, Asset::MeshArrayConstruct) + && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store); +} + void RailVehicleClass::render( const SceneShader & shader, const Location & location, const std::array<Location, 2> & bl) const { shader.basic.use(location); - texture->bind(); + if (texture) { + texture->bind(); + } bodyMesh->Draw(); for (auto b = 0U; b < bogies.size(); ++b) { shader.basic.setModel(bl[b]); @@ -52,10 +64,15 @@ RailVehicleClass::render( } } void -RailVehicleClass::shadows(const ShadowMapper & shadowMapper, const Location & location) const +RailVehicleClass::shadows( + const ShadowMapper & shadowMapper, const Location & location, const std::array<Location, 2> & bl) const { shadowMapper.dynamicPoint.use(location); bodyMesh->Draw(); + for (auto b = 0U; b < bogies.size(); ++b) { + shadowMapper.dynamicPoint.setModel(bl[b]); + bogies[b]->Draw(); + } } float diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index bd74ab9..a2222fb 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -1,5 +1,6 @@ #pragma once +#include "assetFactory/asset.h" #include "gfx/models/mesh.h" #include <array> #include <memory> @@ -11,12 +12,13 @@ class Texture; class ObjParser; class Location; -class RailVehicleClass { +class RailVehicleClass : public Asset { public: explicit RailVehicleClass(const std::string & name); + RailVehicleClass(); void render(const SceneShader &, const Location &, const std::array<Location, 2> &) const; - void shadows(const ShadowMapper &, const Location &) const; + void shadows(const ShadowMapper &, const Location &, const std::array<Location, 2> &) const; std::array<Mesh::Ptr, 2> bogies; Mesh::Ptr bodyMesh; @@ -25,6 +27,10 @@ public: float length; float maxSpeed; +protected: + friend Persistence::SelectionPtrBase<std::shared_ptr<RailVehicleClass>>; + bool persist(Persistence::PersistenceStore & store) override; + private: RailVehicleClass(std::unique_ptr<ObjParser> obj, std::shared_ptr<Texture>); static float bogieOffset(ObjParser & o); |