mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-10-15 15:26:45 +00:00
Use Constants::UnitsPerMeter instead of rolling my own value.
This commit is contained in:
parent
010fc13b91
commit
f762088651
7 changed files with 21 additions and 33 deletions
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/npcstats.hpp"
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
@ -87,7 +89,7 @@ namespace MWVR
|
||||||
auto orientation = handStage.orientation;
|
auto orientation = handStage.orientation;
|
||||||
|
|
||||||
auto position = handStage.position - headStage.position;
|
auto position = handStage.position - headStage.position;
|
||||||
position = position * Environment::get().unitsPerMeter();
|
position = position * Constants::UnitsPerMeter;
|
||||||
|
|
||||||
// Align orientation with the game world
|
// Align orientation with the game world
|
||||||
auto stageRotation = reinterpret_cast<MWVR::VRCamera*>(MWBase::Environment::get().getWorld()->getRenderingManager().getCamera())->stageRotation();
|
auto stageRotation = reinterpret_cast<MWVR::VRCamera*>(MWBase::Environment::get().getWorld()->getRenderingManager().getCamera())->stageRotation();
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <components/sceneutil/visitor.hpp>
|
#include <components/sceneutil/visitor.hpp>
|
||||||
|
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
@ -84,7 +86,7 @@ namespace MWVR
|
||||||
if (frameMeta && frameMeta->mShouldRender)
|
if (frameMeta && frameMeta->mShouldRender)
|
||||||
{
|
{
|
||||||
auto currentHeadPose = frameMeta->mPredictedPoses.head;
|
auto currentHeadPose = frameMeta->mPredictedPoses.head;
|
||||||
currentHeadPose.position *= Environment::get().unitsPerMeter();
|
currentHeadPose.position *= Constants::UnitsPerMeter;
|
||||||
osg::Vec3 vrMovement = currentHeadPose.position - mHeadPose.position;
|
osg::Vec3 vrMovement = currentHeadPose.position - mHeadPose.position;
|
||||||
mHeadPose = currentHeadPose;
|
mHeadPose = currentHeadPose;
|
||||||
mHeadOffset += stageRotation() * vrMovement;
|
mHeadOffset += stageRotation() * vrMovement;
|
||||||
|
|
|
@ -105,13 +105,3 @@ void MWVR::Environment::setManager(MWVR::OpenXRManager* xrManager)
|
||||||
{
|
{
|
||||||
mOpenXRManager = xrManager;
|
mOpenXRManager = xrManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
float MWVR::Environment::unitsPerMeter() const
|
|
||||||
{
|
|
||||||
return mUnitsPerMeter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MWVR::Environment::setUnitsPerMeter(float unitsPerMeter)
|
|
||||||
{
|
|
||||||
mUnitsPerMeter = unitsPerMeter;
|
|
||||||
}
|
|
||||||
|
|
|
@ -60,16 +60,12 @@ namespace MWVR
|
||||||
MWVR::OpenXRManager* getManager() const;
|
MWVR::OpenXRManager* getManager() const;
|
||||||
void setManager(MWVR::OpenXRManager* xrManager);
|
void setManager(MWVR::OpenXRManager* xrManager);
|
||||||
|
|
||||||
float unitsPerMeter() const;
|
|
||||||
void setUnitsPerMeter(float unitsPerMeter);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MWVR::VRSession* mSession{ nullptr };
|
MWVR::VRSession* mSession{ nullptr };
|
||||||
MWVR::VRGUIManager* mGUIManager{ nullptr };
|
MWVR::VRGUIManager* mGUIManager{ nullptr };
|
||||||
MWVR::VRAnimation* mPlayerAnimation{ nullptr };
|
MWVR::VRAnimation* mPlayerAnimation{ nullptr };
|
||||||
MWVR::VRViewer* mViewer{ nullptr };
|
MWVR::VRViewer* mViewer{ nullptr };
|
||||||
MWVR::OpenXRManager* mOpenXRManager{ nullptr };
|
MWVR::OpenXRManager* mOpenXRManager{ nullptr };
|
||||||
float mUnitsPerMeter{ 1.f };
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <components/sceneutil/visitor.hpp>
|
#include <components/sceneutil/visitor.hpp>
|
||||||
#include <components/sceneutil/shadow.hpp>
|
#include <components/sceneutil/shadow.hpp>
|
||||||
#include <components/myguiplatform/myguirendermanager.hpp>
|
#include <components/myguiplatform/myguirendermanager.hpp>
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
#include "../mwrender/util.hpp"
|
#include "../mwrender/util.hpp"
|
||||||
#include "../mwrender/renderbin.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::Vec2Array> texCoords{ new osg::Vec2Array(4) };
|
||||||
osg::ref_ptr<osg::Vec3Array> normals{ new osg::Vec3Array(1) };
|
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 left = mConfig.center.x() - 0.5;
|
||||||
float right = left + 1.f;
|
float right = left + 1.f;
|
||||||
|
@ -293,7 +294,7 @@ namespace MWVR
|
||||||
orientation = orientation * vertical;
|
orientation = orientation * vertical;
|
||||||
}
|
}
|
||||||
// Orient the offset and move the layer
|
// 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->setAttitude(orientation);
|
||||||
mTransform->setPosition(position);
|
mTransform->setPosition(position);
|
||||||
|
@ -370,7 +371,7 @@ namespace MWVR
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pixels per unit
|
// 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)
|
if (mConfig.sizingMode == SizingMode::Auto)
|
||||||
{
|
{
|
||||||
|
@ -723,7 +724,7 @@ namespace MWVR
|
||||||
{
|
{
|
||||||
// If a camera is not available, use VR stage poses directly.
|
// If a camera is not available, use VR stage poses directly.
|
||||||
auto pose = MWVR::Environment::get().getSession()->predictedPoses(MWVR::VRSession::FramePhase::Update).head;
|
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;
|
osg::Quat orientation = pose.orientation;
|
||||||
headPose.position = position;
|
headPose.position = position;
|
||||||
headPose.orientation = orientation;
|
headPose.orientation = orientation;
|
||||||
|
@ -816,10 +817,10 @@ namespace MWVR
|
||||||
y = hitPoint.z() - bottomLeft.y();
|
y = hitPoint.z() - bottomLeft.y();
|
||||||
auto rect = mFocusLayer->mRealRect;
|
auto rect = mFocusLayer->mRealRect;
|
||||||
auto viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
auto viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||||
auto width = viewSize.width * rect.width();
|
float width = viewSize.width * rect.width();
|
||||||
auto height = viewSize.height * rect.height();
|
float height = viewSize.height * rect.height();
|
||||||
auto left = viewSize.width * rect.left;
|
float left = viewSize.width * rect.left;
|
||||||
auto bottom = viewSize.height * rect.bottom;
|
float bottom = viewSize.height * rect.bottom;
|
||||||
x = width * x + left;
|
x = width * x + left;
|
||||||
y = bottom - height * y;
|
y = bottom - height * y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/sdlutil/sdlgraphicswindow.hpp>
|
#include <components/sdlutil/sdlgraphicswindow.hpp>
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
#include <osg/Camera>
|
#include <osg/Camera>
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ namespace MWVR
|
||||||
|
|
||||||
osg::Matrix VRSession::viewMatrix(osg::Vec3 position, osg::Quat orientation)
|
osg::Matrix VRSession::viewMatrix(osg::Vec3 position, osg::Quat orientation)
|
||||||
{
|
{
|
||||||
position = position * Environment::get().unitsPerMeter();
|
position = position * Constants::UnitsPerMeter;
|
||||||
|
|
||||||
swapConvention(position);
|
swapConvention(position);
|
||||||
swapConvention(orientation);
|
swapConvention(orientation);
|
||||||
|
@ -100,7 +101,7 @@ namespace MWVR
|
||||||
if (offset)
|
if (offset)
|
||||||
{
|
{
|
||||||
MWVR::Pose pose = predictedPoses(phase).view[(int)side].pose;
|
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;
|
auto orientation = pose.orientation;
|
||||||
|
|
||||||
if (glConvention)
|
if (glConvention)
|
||||||
|
@ -117,7 +118,7 @@ namespace MWVR
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MWVR::Pose pose = predictedPoses(phase).eye[(int)side];
|
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::Quat orientation = pose.orientation;
|
||||||
osg::Vec3 forward = orientation * osg::Vec3(0, 1, 0);
|
osg::Vec3 forward = orientation * osg::Vec3(0, 1, 0);
|
||||||
osg::Vec3 up = orientation * osg::Vec3(0, 0, 1);
|
osg::Vec3 up = orientation * osg::Vec3(0, 0, 1);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
|
||||||
#include "mwvr/openxrmanager.hpp"
|
#include "mwvr/openxrmanager.hpp"
|
||||||
#include "mwvr/vrsession.hpp"
|
#include "mwvr/vrsession.hpp"
|
||||||
#include "mwvr/vrviewer.hpp"
|
#include "mwvr/vrviewer.hpp"
|
||||||
|
@ -13,13 +14,8 @@ void OMW::Engine::initVr()
|
||||||
if (!mViewer)
|
if (!mViewer)
|
||||||
throw std::logic_error("mViewer must be initialized before calling initVr()");
|
throw std::logic_error("mViewer must be initialized before calling initVr()");
|
||||||
|
|
||||||
|
mEnvironment.setVrMode(true);
|
||||||
mXrEnvironment.setManager(new MWVR::OpenXRManager);
|
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.setSession(new MWVR::VRSession());
|
||||||
mXrEnvironment.setViewer(new MWVR::VRViewer(mViewer));
|
mXrEnvironment.setViewer(new MWVR::VRViewer(mViewer));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue