From cf155c9279d117bb0178a1372b96b3f99415a68c Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 17 Apr 2017 14:37:19 +0300 Subject: [PATCH] [Client] Add MechanicsHelper and move linear interpolation code to it --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwmp/DedicatedPlayer.cpp | 10 ++-------- apps/openmw/mwmp/Main.cpp | 7 +++++++ apps/openmw/mwmp/Main.hpp | 6 +++++- apps/openmw/mwmp/MechanicsHelper.cpp | 22 ++++++++++++++++++++++ apps/openmw/mwmp/MechanicsHelper.hpp | 19 +++++++++++++++++++ 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 apps/openmw/mwmp/MechanicsHelper.cpp create mode 100644 apps/openmw/mwmp/MechanicsHelper.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 27212a13c..958c23d89 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -96,7 +96,7 @@ add_openmw_dir (mwbase inputmanager windowmanager statemanager ) -add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell CellController GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList) +add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList) # Main executable diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index edf825217..a9dbab106 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -33,6 +33,7 @@ #include "Main.hpp" #include "GUIController.hpp" #include "CellController.hpp" +#include "MechanicsHelper.hpp" using namespace mwmp; @@ -209,13 +210,6 @@ ESM::Position Slerp(ESM::Position start, ESM::Position end, float percent) return result; } -osg::Vec3f Lerp(osg::Vec3f start, osg::Vec3f end, float percent) -{ - osg::Vec3f p(percent, percent, percent); - - return (start + osg::componentMultiply(p, (end - start))); -} - void DedicatedPlayer::move(float dt) { if (state != 2) return; @@ -225,7 +219,7 @@ void DedicatedPlayer::move(float dt) { static const int timeMultiplier = 15; - osg::Vec3f lerp = Lerp(refPos.asVec3(), position.asVec3(), dt * timeMultiplier); + osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier); refPos.pos[0] = lerp.x(); refPos.pos[1] = lerp.y(); refPos.pos[2] = lerp.z(); diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 11094f824..abb94d57b 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -32,6 +32,7 @@ #include "DedicatedPlayer.hpp" #include "GUIController.hpp" #include "CellController.hpp" +#include "MechanicsHelper.hpp" using namespace mwmp; using namespace std; @@ -70,6 +71,7 @@ Main::Main() mLocalPlayer = new LocalPlayer(); mGUIController = new GUIController(); mCellController = new CellController(); + mMechanicsHelper = new MechanicsHelper(); //mLocalPlayer->CharGen(0, 4); server = "mp.tes3mp.com"; @@ -241,6 +243,11 @@ CellController *Main::getCellController() const return mCellController; } +MechanicsHelper *Main::getMechanicsHelper() const +{ + return mMechanicsHelper; +} + void Main::pressedKey(int key) { if (pMain == nullptr) return; diff --git a/apps/openmw/mwmp/Main.hpp b/apps/openmw/mwmp/Main.hpp index bfce83468..6592ebc28 100644 --- a/apps/openmw/mwmp/Main.hpp +++ b/apps/openmw/mwmp/Main.hpp @@ -4,8 +4,9 @@ namespace mwmp { - class CellController; class GUIController; + class CellController; + class MechanicsHelper; class LocalPlayer; class Networking; @@ -30,6 +31,7 @@ namespace mwmp LocalPlayer *getLocalPlayer() const; GUIController *getGUIController() const; CellController *getCellController() const; + MechanicsHelper *getMechanicsHelper() const; void updateWorld(float dt) const; @@ -46,6 +48,8 @@ namespace mwmp GUIController *mGUIController; CellController *mCellController; + MechanicsHelper *mMechanicsHelper; + std::string server; unsigned short port; }; diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp new file mode 100644 index 000000000..863c85932 --- /dev/null +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -0,0 +1,22 @@ +#include + +#include "MechanicsHelper.hpp" +#include "Main.hpp" +using namespace mwmp; + +mwmp::MechanicsHelper::MechanicsHelper() +{ + +} + +mwmp::MechanicsHelper::~MechanicsHelper() +{ + +} + +osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent) +{ + osg::Vec3f position(percent, percent, percent); + + return (start + osg::componentMultiply(position, (end - start))); +} diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp new file mode 100644 index 000000000..28522fc8a --- /dev/null +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -0,0 +1,19 @@ +#ifndef OPENMW_MECHANICSHELPER_HPP +#define OPENMW_MECHANICSHELPER_HPP + +#include + +namespace mwmp +{ + class MechanicsHelper + { + public: + + MechanicsHelper(); + ~MechanicsHelper(); + + osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent); + }; +} + +#endif //OPENMW_MECHANICSHELPER_HPP