1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 10:53:51 +00:00

Use Constants::UnitsPerMeter instead of rolling my own value.

This commit is contained in:
Mads Buvik Sandvei 2020-11-01 15:45:14 +01:00
parent 010fc13b91
commit f762088651
7 changed files with 21 additions and 33 deletions

View file

@ -18,6 +18,8 @@
#include <components/settings/settings.hpp>
#include <components/misc/constants.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwmechanics/npcstats.hpp"
@ -87,7 +89,7 @@ namespace MWVR
auto orientation = handStage.orientation;
auto position = handStage.position - headStage.position;
position = position * Environment::get().unitsPerMeter();
position = position * Constants::UnitsPerMeter;
// Align orientation with the game world
auto stageRotation = reinterpret_cast<MWVR::VRCamera*>(MWBase::Environment::get().getWorld()->getRenderingManager().getCamera())->stageRotation();

View file

@ -6,6 +6,8 @@
#include <components/sceneutil/visitor.hpp>
#include <components/misc/constants.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
@ -84,7 +86,7 @@ namespace MWVR
if (frameMeta && frameMeta->mShouldRender)
{
auto currentHeadPose = frameMeta->mPredictedPoses.head;
currentHeadPose.position *= Environment::get().unitsPerMeter();
currentHeadPose.position *= Constants::UnitsPerMeter;
osg::Vec3 vrMovement = currentHeadPose.position - mHeadPose.position;
mHeadPose = currentHeadPose;
mHeadOffset += stageRotation() * vrMovement;

View file

@ -105,13 +105,3 @@ void MWVR::Environment::setManager(MWVR::OpenXRManager* xrManager)
{
mOpenXRManager = xrManager;
}
float MWVR::Environment::unitsPerMeter() const
{
return mUnitsPerMeter;
}
void MWVR::Environment::setUnitsPerMeter(float unitsPerMeter)
{
mUnitsPerMeter = unitsPerMeter;
}

View file

@ -60,16 +60,12 @@ namespace MWVR
MWVR::OpenXRManager* getManager() const;
void setManager(MWVR::OpenXRManager* xrManager);
float unitsPerMeter() const;
void setUnitsPerMeter(float unitsPerMeter);
private:
MWVR::VRSession* mSession{ nullptr };
MWVR::VRGUIManager* mGUIManager{ nullptr };
MWVR::VRAnimation* mPlayerAnimation{ nullptr };
MWVR::VRViewer* mViewer{ nullptr };
MWVR::OpenXRManager* mOpenXRManager{ nullptr };
float mUnitsPerMeter{ 1.f };
};
}

View file

@ -19,6 +19,7 @@
#include <components/sceneutil/visitor.hpp>
#include <components/sceneutil/shadow.hpp>
#include <components/myguiplatform/myguirendermanager.hpp>
#include <components/misc/constants.hpp>
#include "../mwrender/util.hpp"
#include "../mwrender/renderbin.hpp"
@ -157,7 +158,7 @@ namespace MWVR
osg::ref_ptr<osg::Vec2Array> texCoords{ new osg::Vec2Array(4) };
osg::ref_ptr<osg::Vec3Array> normals{ new osg::Vec3Array(1) };
auto extent_units = config.extent * Environment::get().unitsPerMeter();
auto extent_units = config.extent * Constants::UnitsPerMeter;
float left = mConfig.center.x() - 0.5;
float right = left + 1.f;
@ -293,7 +294,7 @@ namespace MWVR
orientation = orientation * vertical;
}
// Orient the offset and move the layer
auto position = mTrackedPose.position + orientation * mConfig.offset * MWVR::Environment::get().unitsPerMeter();
auto position = mTrackedPose.position + orientation * mConfig.offset * Constants::UnitsPerMeter;
mTransform->setAttitude(orientation);
mTransform->setPosition(position);
@ -370,7 +371,7 @@ namespace MWVR
}
// Pixels per unit
float res = static_cast<float>(mConfig.spatialResolution) / Environment::get().unitsPerMeter();
float res = static_cast<float>(mConfig.spatialResolution) / Constants::UnitsPerMeter;
if (mConfig.sizingMode == SizingMode::Auto)
{
@ -723,7 +724,7 @@ namespace MWVR
{
// If a camera is not available, use VR stage poses directly.
auto pose = MWVR::Environment::get().getSession()->predictedPoses(MWVR::VRSession::FramePhase::Update).head;
osg::Vec3 position = pose.position * Environment::get().unitsPerMeter();
osg::Vec3 position = pose.position * Constants::UnitsPerMeter;
osg::Quat orientation = pose.orientation;
headPose.position = position;
headPose.orientation = orientation;
@ -816,10 +817,10 @@ namespace MWVR
y = hitPoint.z() - bottomLeft.y();
auto rect = mFocusLayer->mRealRect;
auto viewSize = MyGUI::RenderManager::getInstance().getViewSize();
auto width = viewSize.width * rect.width();
auto height = viewSize.height * rect.height();
auto left = viewSize.width * rect.left;
auto bottom = viewSize.height * rect.bottom;
float width = viewSize.width * rect.width();
float height = viewSize.height * rect.height();
float left = viewSize.width * rect.left;
float bottom = viewSize.height * rect.bottom;
x = width * x + left;
y = bottom - height * y;
}

View file

@ -11,6 +11,7 @@
#include <components/debug/debuglog.hpp>
#include <components/sdlutil/sdlgraphicswindow.hpp>
#include <components/misc/stringops.hpp>
#include <components/misc/constants.hpp>
#include <osg/Camera>
@ -84,7 +85,7 @@ namespace MWVR
osg::Matrix VRSession::viewMatrix(osg::Vec3 position, osg::Quat orientation)
{
position = position * Environment::get().unitsPerMeter();
position = position * Constants::UnitsPerMeter;
swapConvention(position);
swapConvention(orientation);
@ -100,7 +101,7 @@ namespace MWVR
if (offset)
{
MWVR::Pose pose = predictedPoses(phase).view[(int)side].pose;
auto position = pose.position * Environment::get().unitsPerMeter();
auto position = pose.position * Constants::UnitsPerMeter;
auto orientation = pose.orientation;
if (glConvention)
@ -117,7 +118,7 @@ namespace MWVR
else
{
MWVR::Pose pose = predictedPoses(phase).eye[(int)side];
osg::Vec3 position = pose.position * Environment::get().unitsPerMeter();
osg::Vec3 position = pose.position * Constants::UnitsPerMeter;
osg::Quat orientation = pose.orientation;
osg::Vec3 forward = orientation * osg::Vec3(0, 1, 0);
osg::Vec3 up = orientation * osg::Vec3(0, 0, 1);

View file

@ -1,4 +1,5 @@
#include "engine.hpp"
#include "mwvr/openxrmanager.hpp"
#include "mwvr/vrsession.hpp"
#include "mwvr/vrviewer.hpp"
@ -13,13 +14,8 @@ void OMW::Engine::initVr()
if (!mViewer)
throw std::logic_error("mViewer must be initialized before calling initVr()");
mEnvironment.setVrMode(true);
mXrEnvironment.setManager(new MWVR::OpenXRManager);
// Ref: https://wiki.openmw.org/index.php?title=Measurement_Units
float unitsPerYard = 64.f;
float yardsPerMeter = 0.9144f;
float unitsPerMeter = unitsPerYard / yardsPerMeter;
mXrEnvironment.setUnitsPerMeter(unitsPerMeter);
mXrEnvironment.setSession(new MWVR::VRSession());
mXrEnvironment.setViewer(new MWVR::VRViewer(mViewer));
}