[Client] Add MechanicsHelper and move linear interpolation code to it

0.6.1
David Cernat 8 years ago
parent 2565816b22
commit cf155c9279

@ -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

@ -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();

@ -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;

@ -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;
};

@ -0,0 +1,22 @@
#include <components/openmw-mp/Log.hpp>
#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)));
}

@ -0,0 +1,19 @@
#ifndef OPENMW_MECHANICSHELPER_HPP
#define OPENMW_MECHANICSHELPER_HPP
#include <osg/Vec3f>
namespace mwmp
{
class MechanicsHelper
{
public:
MechanicsHelper();
~MechanicsHelper();
osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent);
};
}
#endif //OPENMW_MECHANICSHELPER_HPP
Loading…
Cancel
Save