add openvr support, switch to 8.1 sdk, prepare for vr ui

This commit is contained in:
2018-10-28 00:29:09 +02:00
parent 4c41be1336
commit 0fff9f2010
19 changed files with 506 additions and 23 deletions

73
src/hmd.h Normal file
View File

@@ -0,0 +1,73 @@
#pragma once
#include "rtt.h"
struct Controller
{
enum class Button : uint64_t
{
Trigger = 0x200000000,
Pad = 0x100000000,
Menu = 0x000000002,
Grip = 0x000000004,
};
enum class Action
{
Press,
Release,
};
int index = 0;
bool active = false;
std::map<uint64_t, bool> buttons;
uint64_t buttons_bits{ 0 };
glm::vec2 axis[5];
glm::mat4 xform{ 1 };
glm::vec3 pos{ 0 };
glm::vec3 rot{ 0 };
vr::VRControllerState_t state;
bool valid = false;
int role = 0;
void update(const glm::mat4& m)
{
xform = m;
pos = glm::vec3(m[3]);
//float sx = glm::length(glm::vec3(m[0]));
//float sy = glm::length(glm::vec3(m[1]));
//float sz = glm::length(glm::vec3(m[2]));
glm::extractEulerAngleXYZ(m, rot.x, rot.y, rot.z);
}
};
struct Vive
{
int comp_attempts = 0;
uint32_t eyeWidth = 0, eyeHeight = 0;
RTT eyes[2];
vr::IVRSystem* hmd = nullptr;
vr::IVRCompositor* comp = nullptr;
glm::vec3 euler{ 0 };
glm::vec4 background{ .5, .2, .2, 1 };
float yaw_offset = 0;
glm::mat4 view[2];
glm::mat4 proj[2];
glm::mat4 pose;
Controller controllers[32];
Controller trackers[32];
bool swap_controllers = false;
std::string dev_serial{ "0000001" };
std::string dev_model{ "Vive" };
std::string dev_tracksys{ "lighthouse" };
std::string dev_manufacturer{ "HTC" };
std::function<void(const glm::mat4& proj, const glm::mat4& view)> on_draw = nullptr;
std::function<void(const Controller&, Controller::Button, Controller::Action)> on_button = nullptr;
Vive();
bool Initialize();
void Terminate();
void ResetYaw();
void Draw();
bool Valid();
};