aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-17 10:26:54 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-17 10:26:54 +0200
commit6411ee34ad3efbad8665047f3593fe9426ca7722 (patch)
treea70f687e980b1151bf126d6d93029dc29de3a251
parente0ffb9e18d38e386ec97c2eb4fc7821269899f18 (diff)
Remove startup delay, restrict yaw rotation
-rw-r--r--src/main.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4ff7009..9b7968a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -81,6 +81,8 @@ enum class PendingWindowEventType {
REMOVE
};
+static const float half_pi = 1.5707963267948f;
+
//-----------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
@@ -193,8 +195,8 @@ private: // OpenGL bookkeeping
glm::vec3 current_pos = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 hmd_pos = glm::vec3(0.0f, 0.0f, 0.0f);
- glm::quat hmd_rot = glm::quat(0.0f, 0.0f, 0.0f, 1.0f);
- glm::quat m_reset_rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
+ float hmd_rot = 0.0f;
+ float m_reset_rotation = 0.0f;
struct VertexDataScene
{
@@ -273,6 +275,7 @@ private: // X compositor
/* TODO: Set initial value if alt key is pressed down before vrwm is started */
bool holding_alt_key = false;
+ bool monitor_rotation_move_cursor = false;
std::atomic_int window_rotation_offset;
enum class ViewMode {
@@ -538,9 +541,13 @@ void CMainApplication::GetFocusedWindowData(Window *window, int *x, int *y) {
void CMainApplication::MoveCursor(Display *display, int diff_x, int diff_y) {
if(holding_alt_key) {
- window_rotation_offset += diff_x;
- diff_x = -diff_x;
- diff_y = 0;
+ window_rotation_offset += diff_x*2;
+ if(monitor_rotation_move_cursor) {
+ diff_x = -diff_x*2;
+ diff_y = 0;
+ } else {
+ return;
+ }
}
{
@@ -707,9 +714,6 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee) {
//-----------------------------------------------------------------------------
bool CMainApplication::BInit()
{
- sleep(5);
- fprintf(stderr, "gpu initialized? TODO: Wait properly until gpu has been initialized. This is slow with nvidia for example!\n");
-
// Loading the SteamVR Runtime
vr::EVRInitError eError = vr::VRInitError_None;
m_pHMD = vr::VR_Init( &eError, vr::VRApplication_Scene );
@@ -952,6 +956,7 @@ void CMainApplication::Shutdown()
{
if( m_bDebugOpenGL )
{
+ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_FALSE );
glDebugMessageCallback(nullptr, nullptr);
}
@@ -1079,7 +1084,7 @@ bool CMainApplication::HandleInput()
// m_resetPos = m_mat4HMDPose;
hmd_pos = current_pos;
m_bResetRotation = false;
- m_reset_rotation = glm::inverse(hmd_rot);
+ m_reset_rotation = hmd_rot;
}
if(projection_mode == ProjectionMode::SPHERE) {
@@ -2008,7 +2013,7 @@ glm::mat4 CMainApplication::GetCurrentViewProjectionMatrix( vr::Hmd_Eye nEye )
glm::mat4 matMVP;
glm::mat4 hmd_pose = m_mat4HMDPose;
hmd_pose = glm::translate(hmd_pose, hmd_pos);
- hmd_pose = hmd_pose * mat4_cast(m_reset_rotation);
+ hmd_pose = glm::rotate(hmd_pose, m_reset_rotation, glm::vec3(0.0f, 1.0f, 0.0f));
if( nEye == vr::Eye_Left )
{
matMVP = m_mat4ProjectionLeft * m_mat4eyePosLeft * hmd_pose;
@@ -2049,8 +2054,8 @@ void CMainApplication::UpdateHMDMatrixPose()
current_pos.y = m_rTrackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[1][3];
current_pos.z = m_rTrackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[2][3];
- glm::mat4 *mat = (glm::mat4*)&m_rTrackedDevicePose[nDevice].mDeviceToAbsoluteTracking;
- hmd_rot = glm::quat_cast(*mat);
+ glm::vec3 *vec_z = (glm::vec3*)&m_rTrackedDevicePose[nDevice].mDeviceToAbsoluteTracking.m[2];
+ hmd_rot = atan2(vec_z->z, vec_z->x) - half_pi;
m_rDevClassChar[nDevice] = 'H';
break;
}