aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWebFreak001 <gh@webfreak.org>2020-06-12 23:01:30 +0200
committerdec05eba <dec05eba@protonmail.com>2020-06-13 07:21:25 +0200
commitaf94cbca3243c21fe03d7895da439532ce4bc24e (patch)
tree943ddb92bb7b8964776d98cf1e4744a13ba5fa17
parent6bde0531a61212a075490d2701d44ede7b35211b (diff)
add ability to reset rotation via signal + gamepad
The gamepad change isn't the best as it requires the window to be focused, but it allows to use a wireless gamepad to reset the rotation and position like using the w key on the keyboard. I currently hardcoded the reset button to 6 on a joystick, which was equal to the select button on my steam controller using sc-controller simulating an xbox controller. Maybe the controller update isn't quite fit to stay and should use the VR controllers instead & work without focus. The more interesting part of this patch is adding signal handling of SIGUSR1 or SIGUSR2 to do the same thing. This allows to simply run a command like `killall -USR1 vr-video-player` to reset the rotation and position even without window focus. This is especially useful for example for adding a custom command action to KDE connect so you can reset the VR view from your phone without needing to have any special software. However I believe even this signal handling should eventually be replaced with some more advanced API like dbus or a unix socket to also allow for more advanced features like changing tracked windows on the fly.
-rw-r--r--README.md6
-rw-r--r--src/main.cpp32
2 files changed, 35 insertions, 3 deletions
diff --git a/README.md b/README.md
index b9ac1b2..bfb53a7 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,11 @@ If the video is not meant to be viewed as a sphere but as a rectangle, then pass
If the video is flipped where the right eye is on the left side, then pass the `--right-left` option when running vr video player.\
If the video is stretched, then pass the `--no-stretch`option when running vr video player. Note: This option only works when also using the `--flat` option.
-To rotate the video to be in front of you, pull the trigger on the vr controller or press `w` on your keyboard while the vr video player is focused.
+To rotate and move the video to be in front of you, pull the trigger on the vr controller or press `w` on your keyboard while the vr video player is focused. You can also use the select/back button on an xbox controller while the application is focused or send the SIGUSR1 signal to the application to do the same thing like using the following command:
+
+```
+killall -USR1 vr-video-player
+```
# Games
This vr video player can also be used to play games in VR to to get a 3D effect, and even for games that don't support VR.\
diff --git a/src/main.cpp b/src/main.cpp
index dddee0e..e2627e0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -53,6 +53,7 @@ extern "C" {
#include <vector>
#include <unistd.h>
+#include <signal.h>
#include <libgen.h>
#ifndef _countof
@@ -107,6 +108,7 @@ public:
void ProcessVREvent( const vr::VREvent_t & event );
void RenderFrame();
+ void ResetRotation();
void SetupScene();
void AddCubeToScene( const glm::mat4 &mat, std::vector<float> &vertdata );
void AddCubeVertex( float fl0, float fl1, float fl2, float fl3, float fl4, std::vector<float> &vertdata );
@@ -543,7 +545,7 @@ bool CMainApplication::BInit()
XSelectInput(x_display, src_window_id, StructureNotifyMask);
- if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 )
+ if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ) < 0 )
{
printf("%s - SDL could not initialize! SDL Error: %s\n", __FUNCTION__, SDL_GetError());
return false;
@@ -978,6 +980,11 @@ void CMainApplication::RunMainLoop()
SDL_StartTextInput();
SDL_ShowCursor( SDL_DISABLE );
+ SDL_Joystick *controller = SDL_JoystickOpen(0);
+ if (!controller)
+ fprintf(stderr, "Could not open gamecontroller: %s\n", SDL_GetError());
+
+
while ( !bQuit )
{
bQuit = HandleInput();
@@ -985,6 +992,9 @@ void CMainApplication::RunMainLoop()
RenderFrame();
}
+ if (controller)
+ SDL_JoystickClose(controller);
+
SDL_StopTextInput();
}
@@ -1069,6 +1079,14 @@ void CMainApplication::RenderFrame()
UpdateHMDMatrixPose();
}
+//-----------------------------------------------------------------------------
+// Purpose: resets rotation & position of the screen
+//-----------------------------------------------------------------------------
+void CMainApplication::ResetRotation()
+{
+ m_bResetRotation = true;
+}
+
//-----------------------------------------------------------------------------
// Purpose: Compiles a GL shader program and returns the handle. Returns 0 if
@@ -2200,13 +2218,23 @@ void CGLRenderModel::Draw()
glBindVertexArray( 0 );
}
+CMainApplication *pMainApplication;
+
+void reset_position(int signum)
+{
+ printf("ok\n");
+ pMainApplication->ResetRotation();
+}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
- CMainApplication *pMainApplication = new CMainApplication( argc, argv );
+ pMainApplication = new CMainApplication( argc, argv );
+
+ signal(SIGUSR1, reset_position);
+ signal(SIGUSR2, reset_position);
if (!pMainApplication->BInit())
{