Files
panopainter/src/hmd.h
2019-05-06 21:03:22 +02:00

61 lines
1.6 KiB
C++

#pragma once
#include "rtt.h"
struct ViveController
{
enum class kButton : uint8_t
{
Pad,
Trigger,
Menu,
Grip,
COUNT,
};
enum class kButtonMask : uint64_t
{
TriggerBit = 0x200000000,
PadBit = 0x100000000,
MenuBit = 0x000000002,
GripBit = 0x000000004,
};
enum class kAction
{
Press,
Release,
};
static std::map<kButton, kButtonMask> m_mask;
std::array<bool, (int)kButton::COUNT> m_buttons;
std::array<bool, (int)kButton::COUNT> m_analog_buttons;
glm::mat4 m_mat;
vr::VRControllerState_t m_state{ 0 };
bool m_valid = false;
glm::vec2 axis(kButton button) const {
return { m_state.rAxis[(int)button].x, m_state.rAxis[(int)button].y };
}
};
struct Vive
{
int comp_attempts = 0;
uint32_t m_eye_width = 0, m_eye_height = 0;
RTT m_eyes[2];
vr::IVRSystem* m_hmd = nullptr;
vr::IVRCompositor* m_comp = nullptr;
vr::IVRSettings* m_settings = nullptr;
ViveController m_controllers[2];
glm::mat4 m_view[2];
glm::mat4 m_proj[2];
glm::mat4 m_pose;
bool m_active = false;
std::function<void(const glm::mat4& m_proj, const glm::mat4& m_view, const glm::mat4& m_pose)> on_draw = nullptr;
std::function<void(const ViveController&, ViveController::kButton, ViveController::kAction)> on_button = nullptr;
std::function<void(const ViveController&, ViveController::kButton, ViveController::kAction)> on_analog_button = nullptr;
bool Initialize();
void Terminate();
void Update();
void Draw();
bool Valid();
glm::mat4 Pose2Mat(vr::HmdMatrix34_t const& m);
};