Files
OpenVR-AdvancedSettings-frame/src/overlaycontroller.h
T
Vasily 760d262a57 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.
2019-03-31 22:31:26 +02:00

223 lines
7.2 KiB
C++

#pragma once
#include <openvr.h>
#include <QtCore/QtCore>
// because of incompatibilities with QtOpenGL and GLEW we need to cherry pick
// includes
#include <QVector2D>
#include <QMatrix4x4>
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QObject>
#include <QSettings>
#include <QQmlEngine>
#include <QtGui/QOpenGLContext>
#include <QtWidgets/QGraphicsScene>
#include <QOffscreenSurface>
#include <QOpenGLFramebufferObject>
#include <QQuickWindow>
#include <QQuickItem>
#include <QQuickRenderControl>
#include <QSoundEffect>
#include <memory>
#include <easylogging++.h>
#include "openvr/openvr_init.h"
#include "utils/ChaperoneUtils.h"
#include "tabcontrollers/SteamVRTabController.h"
#include "tabcontrollers/ChaperoneTabController.h"
#include "tabcontrollers/MoveCenterTabController.h"
#include "tabcontrollers/FixFloorTabController.h"
#include "tabcontrollers/AudioTabController.h"
#include "tabcontrollers/StatisticsTabController.h"
#include "tabcontrollers/SettingsTabController.h"
#include "tabcontrollers/ReviveTabController.h"
#include "tabcontrollers/UtilitiesTabController.h"
#include "openvr/ivrinput.h"
#include "openvr/overlay_utils.h"
namespace application_strings
{
constexpr auto applicationOrganizationName = "AdvancedSettings-Team";
constexpr auto applicationName = "OpenVRAdvancedSettings";
constexpr const char* applicationKey = "OVRAS-Team.AdvancedSettings";
constexpr const char* applicationDisplayName = "Advanced Settings";
constexpr const char* applicationVersionString = "v3.0.1";
} // namespace application_strings
// application namespace
namespace advsettings
{
// These counters set timing for refreshing settings changes in tab ui
// SettingsUpdateCounter values are set as prime numbers to reduce overlap
// of simultaneous settings updates.
// Actual rates of updates are counter * vsync (~11ms)
// Values chosen based on update speed priority
// Avoid setting values to the same numbers.
constexpr int k_audioSettingsUpdateCounter = 89;
constexpr int k_chaperoneSettingsUpdateCounter = 101;
constexpr int k_moveCenterSettingsUpdateCounter = 149;
constexpr int k_reviveSettingsUpdateCounter = 139;
constexpr int k_settingsTabSettingsUpdateCounter = 157;
constexpr int k_steamVrSettingsUpdateCounter = 97;
constexpr int k_utilitiesSettingsUpdateCounter = 19;
// k_nonVsyncTickRate determines number of ms we wait to force the next event
// loop tick when vsync is too late due to dropped frames.
constexpr int k_nonVsyncTickRate = 20;
constexpr int k_hmdRotationCounterUpdateRate = 7;
class OverlayController : public QObject
{
Q_OBJECT
Q_PROPERTY( bool m_desktopMode READ isDesktopMode )
private:
vr::VROverlayHandle_t m_ulOverlayHandle = vr::k_ulOverlayHandleInvalid;
vr::VROverlayHandle_t m_ulOverlayThumbnailHandle
= vr::k_ulOverlayHandleInvalid;
std::unique_ptr<QQuickRenderControl> m_pRenderControl;
std::unique_ptr<QQuickWindow> m_pWindow;
std::unique_ptr<QOpenGLFramebufferObject> m_pFbo;
std::unique_ptr<QOpenGLContext> m_pOpenGLContext;
std::unique_ptr<QOffscreenSurface> m_pOffscreenSurface;
std::unique_ptr<QTimer> m_pPumpEventsTimer;
std::unique_ptr<QTimer> m_pRenderTimer;
bool m_dashboardVisible = false;
QPoint m_ptLastMouse;
Qt::MouseButtons m_lastMouseButtons = nullptr;
bool m_desktopMode;
bool m_noSound;
QUrl m_runtimePathUrl;
utils::ChaperoneUtils m_chaperoneUtils;
QSoundEffect m_activationSoundEffect;
QSoundEffect m_focusChangedSoundEffect;
QSoundEffect m_alarm01SoundEffect;
uint64_t m_currentFrame = 0;
uint64_t m_lastFrame = 0;
int m_vsyncTooLateCounter = 0;
input::SteamIVRInput m_actions;
public: // I know it's an ugly hack to make them public to enable external
// access, but I am too lazy to implement getters.
SteamVRTabController m_steamVRTabController;
ChaperoneTabController m_chaperoneTabController;
MoveCenterTabController m_moveCenterTabController;
FixFloorTabController m_fixFloorTabController;
AudioTabController m_audioTabController;
StatisticsTabController m_statisticsTabController;
SettingsTabController m_settingsTabController;
ReviveTabController m_reviveTabController;
UtilitiesTabController m_utilitiesTabController;
overlay::DesktopOverlay m_desktopOverlay;
private:
QPoint getMousePositionForEvent( vr::VREvent_Mouse_t mouse );
void processInputBindings();
void processMediaKeyBindings();
void processMotionBindings();
void processPushToTalkBindings();
public:
OverlayController( bool desktopMode, bool noSound, QQmlEngine& qmlEngine );
virtual ~OverlayController();
void Shutdown();
bool isDashboardVisible()
{
return m_dashboardVisible;
}
void SetWidget( QQuickItem* quickItem,
const std::string& name,
const std::string& key = "" );
void AddOffsetToUniverseCenter( vr::ETrackingUniverseOrigin universe,
unsigned axisId,
float offset,
bool adjustBounds = true,
bool commit = true );
void AddOffsetToUniverseCenter( vr::ETrackingUniverseOrigin universe,
float offset[3],
bool adjustBounds = true,
bool commit = true );
void RotateUniverseCenter( vr::ETrackingUniverseOrigin universe,
float yAngle,
bool adjustBounds = true,
bool commit = true ); // around y axis
void AddOffsetToCollisionBounds( unsigned axisId,
float offset,
bool commit = true );
void AddOffsetToCollisionBounds( float offset[3], bool commit = true );
void RotateCollisionBounds( float angle,
bool commit = true ); // around y axis
bool isDesktopMode()
{
return m_desktopMode;
}
utils::ChaperoneUtils& chaperoneUtils() noexcept
{
return m_chaperoneUtils;
}
Q_INVOKABLE QString getVersionString();
Q_INVOKABLE QUrl getVRRuntimePathUrl();
Q_INVOKABLE bool soundDisabled();
const vr::VROverlayHandle_t& overlayHandle();
const vr::VROverlayHandle_t& overlayThumbnailHandle();
bool pollNextEvent( vr::VROverlayHandle_t ulOverlayHandle,
vr::VREvent_t* pEvent );
void mainEventLoop();
public slots:
void renderOverlay();
void OnRenderRequest();
void OnTimeoutPumpEvents();
void showKeyboard( QString existingText, unsigned long userValue = 0 );
void playActivationSound();
void playFocusChangedSound();
void playAlarm01Sound( bool loop = false );
void setAlarm01SoundVolume( float vol );
void cancelAlarm01Sound();
signals:
void keyBoardInputSignal( QString input, unsigned long userValue = 0 );
private:
static QSettings* _appSettings;
public:
static QSettings* appSettings()
{
return _appSettings;
}
static void setAppSettings( QSettings* settings )
{
_appSettings = settings;
}
};
} // namespace advsettings