1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 10:23:51 +00:00
openmw-tes3mp/apps/openmw/mwvr/vrinput.hpp
Mads Buvik Sandvei c3a312f80d Squashed commit of the following:
commit d8564b8e501c98fa2e3cde582b8d06d7c78ba6ce
Author: Mads Buvik Sandvei <madssandvei@protonmail.com>
Date:   Fri Oct 16 23:43:39 2020 +0200

    bad assignment

commit 84f66e4bf1050ce8a316a27f8b10dc2243e35406
Author: Mads Buvik Sandvei <madssandvei@protonmail.com>
Date:   Fri Oct 16 21:08:27 2020 +0200

    Removed the approach of abstracting xr paths with enums. It is not turning out to be useful. Use the explicit paths instead. Added some default bindings for most currently available controllers, except the xbox controller.

commit ae525d0a239c087a7344528634a078e0812af66d
Author: Mads Buvik Sandvei <madssandvei@protonmail.com>
Date:   Fri Oct 16 21:05:37 2020 +0200

    Cleaned up openxr extensions code. Upgraded openxr to version 1.0.12 to enable support for certain controllers.

commit 2d71a5ecbf699c59f1fcdbebcad867fd28552929
Author: Mads Buvik Sandvei <madssandvei@protonmail.com>
Date:   Thu Sep 24 22:18:25 2020 +0200

    simple_controller
2020-10-17 12:33:46 +02:00

205 lines
5.8 KiB
C++

#ifndef VR_INPUT_HPP
#define VR_INPUT_HPP
#include "vrviewer.hpp"
#include "openxraction.hpp"
#include "../mwinput/inputmanagerimp.hpp"
namespace MWVR
{
/// Extension of MWInput's set of actions.
enum VrActions
{
A_VrFirst = MWInput::A_Last + 1,
A_ActivateTouch,
A_HapticsLeft,
A_HapticsRight,
A_HandPoseLeft,
A_HandPoseRight,
A_MenuUpDown,
A_MenuLeftRight,
A_MenuSelect,
A_MenuBack,
A_Recenter,
A_VrLast
};
/// \brief Suggest a binding by binding an action to a path on a given hand (left or right).
struct SuggestedBinding
{
int action;
std::string path;
};
using SuggestedBindings = std::vector<SuggestedBinding>;
/// \brief Enumeration of action sets
enum class ActionSet
{
GUI = 0,
Gameplay = 1,
};
/// \brief Action for applying haptics
class HapticsAction
{
public:
HapticsAction(std::unique_ptr<OpenXRAction> xrAction) : mXRAction{ std::move(xrAction) } {};
//! Apply vibration at the given amplitude
void apply(float amplitude);
//! Convenience
operator XrAction() { return *mXRAction; }
private:
std::unique_ptr<OpenXRAction> mXRAction;
float mAmplitude{ 0.f };
};
/// \brief Action for capturing tracking information
class PoseAction
{
public:
PoseAction(std::unique_ptr<OpenXRAction> xrAction);
//! Current value of an axis or lever action
Pose value() const { return mValue; }
//! Previous value
Pose previousValue() const { return mPrevious; }
//! Convenience
operator XrAction() { return *mXRAction; }
//! Update pose value
void update(long long time);
private:
std::unique_ptr<OpenXRAction> mXRAction;
XrSpace mXRSpace;
Pose mValue{};
Pose mPrevious{};
};
/// \brief Generic action
/// \sa ButtonPressAction ButtonLongPressAction ButtonHoldAction AxisAction
class Action
{
public:
Action(int openMWAction, std::unique_ptr<OpenXRAction> xrAction) : mXRAction(std::move(xrAction)), mOpenMWAction(openMWAction) {}
virtual ~Action() {};
//! True if action changed to being released in the last update
bool isActive() const { return mActive; };
//! True if activation turned on this update (i.e. onPress)
bool onActivate() const { return mOnActivate; }
//! True if activation turned off this update (i.e. onRelease)
bool onDeactivate() const { return mOnDeactivate; }
//! OpenMW Action code of this action
int openMWActionCode() const { return mOpenMWAction; }
//! Current value of an axis or lever action
float value() const { return mValue; }
//! Previous value
float previousValue() const { return mPrevious; }
//! Update internal states. Note that subclasses maintain both mValue and mActivate to allow
//! axis and press to subtitute one another.
virtual void update() = 0;
//! Determines if an action update should be queued
virtual bool shouldQueue() const = 0;
//! Convenience
operator XrAction() { return *mXRAction; }
//! Update and queue action if applicable
void updateAndQueue(std::deque<const Action*>& queue);
protected:
std::unique_ptr<OpenXRAction> mXRAction;
int mOpenMWAction;
float mValue{ 0.f };
float mPrevious{ 0.f };
bool mActive{ false };
bool mOnActivate{ false };
bool mOnDeactivate{ false };
};
//! Action that activates once on release.
//! Times out if the button is held longer than gHoldDelay.
class ButtonPressAction : public Action
{
public:
using Action::Action;
static const XrActionType ActionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
void update() override;
virtual bool shouldQueue() const override { return onActivate() || onDeactivate(); }
bool mPressed{ false };
std::chrono::steady_clock::time_point mPressTime{};
std::chrono::steady_clock::time_point mTimeout{};
};
//! Action that activates once on a long press
//! The press time is the same as the timeout for a regular press, allowing keys with double roles.
class ButtonLongPressAction : public Action
{
public:
using Action::Action;
static const XrActionType ActionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
void update() override;
virtual bool shouldQueue() const override { return onActivate() || onDeactivate(); }
bool mPressed{ false };
bool mActivated{ false };
std::chrono::steady_clock::time_point mPressTime{};
std::chrono::steady_clock::time_point mTimein{};
};
//! Action that is active whenever the button is pressed down.
//! Useful for e.g. non-toggling sneak and automatically repeating actions
class ButtonHoldAction : public Action
{
public:
using Action::Action;
static const XrActionType ActionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
void update() override;
virtual bool shouldQueue() const override { return mActive || onDeactivate(); }
bool mPressed{ false };
};
//! Action for axis actions, such as thumbstick axes or certain triggers/squeeze levers.
//! Float axis are considered active whenever their magnitude is greater than gAxisEpsilon. This is useful
//! as a touch subtitute on levers without touch.
class AxisAction : public Action
{
public:
using Action::Action;
static const XrActionType ActionType = XR_ACTION_TYPE_FLOAT_INPUT;
void update() override;
virtual bool shouldQueue() const override { return mActive || onDeactivate(); }
};
}
#endif