Add page to change desktop overlay translation
The implementation is simple 3D vector scaling and addition. The HmdMatrix34_t consists of a 3x3 rotation matrix and a 3D vector for position. The overlay position is only updated whenever a new overlay is changed because we need the old overlay position in order to modify it. The openvr call to get the position is only updated whenever you open the menu. A new page was created due to lack of space on the utilities page.
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
#include "overlay_utils.h"
|
||||
|
||||
namespace overlay
|
||||
{
|
||||
vr::VROverlayHandle_t getOverlayHandle()
|
||||
{
|
||||
vr::VROverlayHandle_t pOverlayHandle;
|
||||
vr::VROverlay()->FindOverlay( strings::overlaykey, &pOverlayHandle );
|
||||
return pOverlayHandle;
|
||||
}
|
||||
|
||||
vr::HmdMatrix34_t getDesktopOverlayPositions()
|
||||
{
|
||||
vr::HmdMatrix34_t currentPosition = {};
|
||||
|
||||
const auto overlayHandle = getOverlayHandle();
|
||||
|
||||
vr::ETrackingUniverseOrigin origin
|
||||
= vr::ETrackingUniverseOrigin::TrackingUniverseStanding;
|
||||
|
||||
vr::VROverlay()->GetOverlayTransformAbsolute(
|
||||
overlayHandle, &origin, ¤tPosition );
|
||||
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
void setDesktopOverlayPositions( vr::HmdMatrix34_t& positions )
|
||||
{
|
||||
const auto overlayHandle = getOverlayHandle();
|
||||
|
||||
// We need to make sure we get the same Universe Origin as before.
|
||||
vr::HmdMatrix34_t currentPosition = {};
|
||||
vr::ETrackingUniverseOrigin origin
|
||||
= vr::ETrackingUniverseOrigin::TrackingUniverseStanding;
|
||||
vr::VROverlay()->GetOverlayTransformAbsolute(
|
||||
overlayHandle, &origin, ¤tPosition );
|
||||
|
||||
vr::VROverlay()->SetOverlayTransformAbsolute(
|
||||
overlayHandle, origin, &positions );
|
||||
}
|
||||
|
||||
void setDesktopOverlayWidth( double width )
|
||||
{
|
||||
const auto overlayHandle = getOverlayHandle();
|
||||
auto error = vr::VROverlay()->SetOverlayWidthInMeters(
|
||||
overlayHandle, static_cast<float>( width ) );
|
||||
if ( error != vr::VROverlayError_None )
|
||||
{
|
||||
LOG( ERROR ) << "Could not modify overlay width of \""
|
||||
<< strings::overlaykey << "\": "
|
||||
<< vr::VROverlay()->GetOverlayErrorNameFromEnum( error );
|
||||
}
|
||||
}
|
||||
|
||||
void setSettingsToValue( const std::string setting, const double value )
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup( strings::settingsGroupName );
|
||||
settings.setValue( setting.c_str(), value );
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
overlay::DesktopOverlay::DesktopOverlay()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup( strings::settingsGroupName );
|
||||
m_width = settings.value( strings::widthSettingsName, defaultOverlayWidth )
|
||||
.toDouble();
|
||||
m_forwardsMovement
|
||||
= settings.value( strings::forwardsSettingsName, defaultMovement )
|
||||
.toDouble();
|
||||
m_rightMovement
|
||||
= settings.value( strings::rightMovementSettingsName, defaultMovement )
|
||||
.toDouble();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void DesktopOverlay::update()
|
||||
{
|
||||
auto positionMatrix = getDesktopOverlayPositions();
|
||||
|
||||
auto position = QVector3D( positionMatrix.m[0][3],
|
||||
positionMatrix.m[1][3],
|
||||
positionMatrix.m[2][3] );
|
||||
|
||||
const auto screenRight = QVector3D( positionMatrix.m[0][0],
|
||||
positionMatrix.m[1][0],
|
||||
positionMatrix.m[2][0] );
|
||||
|
||||
const auto screenForwards = QVector3D( positionMatrix.m[0][2],
|
||||
positionMatrix.m[1][2],
|
||||
positionMatrix.m[2][2] );
|
||||
|
||||
const auto screenUp = QVector3D( positionMatrix.m[0][1],
|
||||
positionMatrix.m[1][1],
|
||||
positionMatrix.m[2][1] );
|
||||
|
||||
position += ( static_cast<float>( m_rightMovement ) * screenRight );
|
||||
|
||||
position += ( static_cast<float>( m_forwardsMovement ) * screenForwards );
|
||||
|
||||
position += ( static_cast<float>( m_upMovement ) * screenUp );
|
||||
|
||||
positionMatrix.m[0][3] = position.x();
|
||||
positionMatrix.m[1][3] = position.y();
|
||||
positionMatrix.m[2][3] = position.z();
|
||||
|
||||
setDesktopOverlayPositions( positionMatrix );
|
||||
|
||||
setDesktopOverlayWidth( m_width );
|
||||
}
|
||||
|
||||
bool DesktopOverlay::isAvailable() const
|
||||
{
|
||||
vr::VROverlayHandle_t pOverlayHandle = 0;
|
||||
auto error
|
||||
= vr::VROverlay()->FindOverlay( strings::overlaykey, &pOverlayHandle );
|
||||
if ( error != vr::VROverlayError_None )
|
||||
{
|
||||
LOG( INFO ) << "Could not find overlay \"" << strings::overlaykey
|
||||
<< "\": "
|
||||
<< vr::VROverlay()->GetOverlayErrorNameFromEnum( error );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void overlay::DesktopOverlay::setWidth( double width )
|
||||
{
|
||||
if ( width < 0.01 )
|
||||
{
|
||||
width = 0.01;
|
||||
}
|
||||
|
||||
setSettingsToValue( strings::widthSettingsName, width );
|
||||
m_width = width;
|
||||
}
|
||||
|
||||
double DesktopOverlay::getCurrentWidth() const noexcept
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
void DesktopOverlay::setRightMovement( double distance )
|
||||
{
|
||||
setSettingsToValue( strings::rightMovementSettingsName, distance );
|
||||
m_rightMovement = distance;
|
||||
}
|
||||
|
||||
double DesktopOverlay::getCurrentRightMovement() const noexcept
|
||||
{
|
||||
return m_rightMovement;
|
||||
}
|
||||
|
||||
void DesktopOverlay::setForwardsMovement( double distance )
|
||||
{
|
||||
setSettingsToValue( strings::forwardsSettingsName, distance );
|
||||
m_forwardsMovement = distance;
|
||||
}
|
||||
|
||||
double DesktopOverlay::getCurrentForwardsMovement() const noexcept
|
||||
{
|
||||
return m_forwardsMovement;
|
||||
}
|
||||
|
||||
void DesktopOverlay::setHeight( double height )
|
||||
{
|
||||
setSettingsToValue( strings::upMovementSettingsName, height );
|
||||
m_upMovement = height;
|
||||
}
|
||||
|
||||
double DesktopOverlay::getCurrentHeight() const noexcept
|
||||
{
|
||||
return m_upMovement;
|
||||
}
|
||||
|
||||
} // namespace overlay
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <openvr.h>
|
||||
#include <easylogging++.h>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QSettings>
|
||||
|
||||
void outputMat();
|
||||
void transformMat();
|
||||
|
||||
namespace overlay
|
||||
{
|
||||
namespace strings
|
||||
{
|
||||
constexpr auto overlaykey = "valve.steam.desktop";
|
||||
constexpr auto settingsGroupName = "utilitiesSettings";
|
||||
constexpr auto widthSettingsName = "desktopWidth";
|
||||
constexpr auto forwardsSettingsName = "desktopForwardsMovement";
|
||||
constexpr auto rightMovementSettingsName = "desktopRightMovement";
|
||||
constexpr auto upMovementSettingsName = "desktopUpMovement";
|
||||
constexpr auto positionSettingsName = "desktopOverlayPosition";
|
||||
} // namespace strings
|
||||
|
||||
constexpr auto defaultOverlayWidth = 4.0;
|
||||
constexpr auto defaultMovement = 0.0;
|
||||
|
||||
class DesktopOverlay : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY( double rightMovement READ getCurrentRightMovement()
|
||||
WRITE setRightMovement )
|
||||
Q_PROPERTY( double forwardsMovement READ getCurrentForwardsMovement WRITE
|
||||
setForwardsMovement )
|
||||
Q_PROPERTY( double width READ getCurrentWidth WRITE setWidth )
|
||||
Q_PROPERTY( double height READ getCurrentHeight WRITE setHeight )
|
||||
|
||||
DesktopOverlay();
|
||||
|
||||
Q_INVOKABLE void update();
|
||||
|
||||
bool isAvailable() const;
|
||||
|
||||
void setWidth( double width );
|
||||
double getCurrentWidth() const noexcept;
|
||||
|
||||
void setRightMovement( double distance );
|
||||
double getCurrentRightMovement() const noexcept;
|
||||
|
||||
void setForwardsMovement( double distance );
|
||||
double getCurrentForwardsMovement() const noexcept;
|
||||
|
||||
void setHeight( double height );
|
||||
double getCurrentHeight() const noexcept;
|
||||
|
||||
private:
|
||||
double m_width = defaultOverlayWidth;
|
||||
double m_forwardsMovement = defaultMovement;
|
||||
double m_rightMovement = defaultMovement;
|
||||
double m_upMovement = defaultMovement;
|
||||
};
|
||||
|
||||
} // namespace overlay
|
||||
Reference in New Issue
Block a user