Skip to content

Commit

Permalink
Refactor VR HeadTracking
Browse files Browse the repository at this point in the history
  • Loading branch information
MadDeCoDeR committed Nov 21, 2024
1 parent 542ef62 commit eb58d64
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 15 deletions.
18 changes: 17 additions & 1 deletion neo/framework/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class idConsoleLocal : public idConsole

float DrawFPS( float y );
float DrawMemoryUsage( float y );

float DrawViewAngles(float c);

void DrawOverlayText( float& leftY, float& rightY, float& centerY );
void DrawDebugGraphs();
Expand Down Expand Up @@ -497,6 +499,16 @@ float idConsoleLocal::DrawMemoryUsage( float y )
return y;
}

float idConsoleLocal::DrawViewAngles(float c)
{
idVec3 viewAngles = usercmdGen->GetAngles();
idStr angleStr;
angleStr.Format("PITCH: %4.4f YAW: %4.4f ROLL: %4.4f", viewAngles[PITCH], viewAngles[YAW], viewAngles[ROLL]);
int w = (angleStr.LengthWithoutColors() * SMALLCHAR_WIDTH) / 2;
renderSystem->DrawSmallStringExt((LOCALSAFE_WIDTH /2) - w, (LOCALSAFE_HEIGHT / 2) + (2 * SMALLCHAR_HEIGHT), angleStr.c_str(), colorWhite, false);
return c;
}

//=========================================================================

/*
Expand Down Expand Up @@ -1481,7 +1493,7 @@ void idConsoleLocal::DrawSolidConsole( float frac )
renderSystem->SetColor( colorCyan );
}


extern idCVar in_showViewAngles;
/*
==============
Draw
Expand Down Expand Up @@ -1535,6 +1547,10 @@ void idConsoleLocal::Draw( bool forceFullScreen )
{
righty = DrawMemoryUsage( righty );
}
if (in_showViewAngles.GetBool())
{
centery = DrawViewAngles(centery);
}
DrawOverlayText( lefty, righty, centery );
DrawDebugGraphs();
}
Expand Down
17 changes: 9 additions & 8 deletions neo/framework/UsercmdGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ idCVar in_joyjpn("in_joyjpn", "0", CVAR_NOCHEAT | CVAR_BOOL, "Enable/Disable JPN

idCVar in_photomode("in_photomode", "0", CVAR_NOCHEAT | CVAR_BOOL, "Enable/Disable Photo Mode");

idCVar in_showViewAngles("in_showViewAngles", "0", CVAR_NOCHEAT | CVAR_BOOL, "Show View Angles");

extern idCVar com_pause;
//GK End
/*
Expand Down Expand Up @@ -254,7 +256,13 @@ class idUsercmdGenLocal : public idUsercmdGen

void ClearAngles();

void SetAngles(idAngles angle);
void SetAngles(idVec3 angle) {
viewangles = angle;
}

idVec3 GetAngles() {
return viewangles;
}

void InhibitUsercmd( inhibit_t subsystem, bool inhibit );

Expand Down Expand Up @@ -1408,13 +1416,6 @@ void idUsercmdGenLocal::ClearAngles()
viewangles.Zero();
}

void idUsercmdGenLocal::SetAngles(idAngles angle)
{
viewangles = angle.ToAngularVelocity() * 100.0f;
viewangles[PITCH] *= in_invertLook.GetBool() ? 1.0f : -1.0f;
viewangles[ROLL] *= -1.0f;
}

//======================================================================


Expand Down
3 changes: 2 additions & 1 deletion neo/framework/UsercmdGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class idUsercmdGen
virtual void ClearAngles() = 0;

//GK: Set view angles.
virtual void SetAngles(idAngles angle) = 0;
virtual void SetAngles(idVec3 angle) = 0;
virtual idVec3 GetAngles() = 0;

// When the console is down or the menu is up, only emit default usercmd, so the player isn't moving around.
// Each subsystem (session and game) may want an inhibit will OR the requests.
Expand Down
2 changes: 2 additions & 0 deletions neo/renderer/OpenXR/XRCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <vector>
#include <string>



class idXR {
public:
virtual bool InitXR() = 0;
Expand Down
7 changes: 4 additions & 3 deletions neo/sys/win32/win_glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,16 @@ static int GLW_ChoosePixelFormat( const HDC hdc, const int multisamples, const b
WGL_SAMPLE_BUFFERS_ARB, ( ( multisamples > 1 ) ? 1 : 0 ),
WGL_SAMPLES_ARB, multisamples,
WGL_DOUBLE_BUFFER_ARB, TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_STENCIL_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24,
WGL_COLOR_BITS_ARB, 32,/*
WGL_RED_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,*/
WGL_STEREO_ARB, ( stereo3D ? TRUE : FALSE ),
WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE,
0, 0
};

Expand Down Expand Up @@ -506,8 +509,6 @@ static bool GLW_InitDriver( glimpParms_t parms )
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_GENERIC_FORMAT |
PFD_GENERIC_ACCELERATED |
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
32, // 32-bit color depth
Expand Down
29 changes: 28 additions & 1 deletion neo/sys/win32/win_oxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
#include "precompiled.h"
#include "win_oxr.h"
idCVar vr_recordInitialPosition("vr_recordInitialPosition", "1", CVAR_BOOL, "Boolean to Determine if the current HMD Input must be recorded for initial Position");
extern idCVar in_invertLook;

idXR_Win xrWinSystem;
idXR* xrSystem = &xrWinSystem;
Expand Down Expand Up @@ -163,8 +165,14 @@ void idXR_Win::StartFrame()
return;
}
//HMD input
if (vr_recordInitialPosition.GetBool()) {
initialView = views[0];
initialViewAngles = ConvertQuatToVec3(initialView.pose.orientation);
vr_recordInitialPosition.SetBool(false);
previousViewAngles = initialViewAngles;
}
if (!expectedActionSet.Cmp("GAME")) {
usercmdGen->SetAngles(idQuat(views[0].pose.orientation.x, views[0].pose.orientation.y, views[0].pose.orientation.z, views[0].pose.orientation.w).ToAngles());
ProccessHMDInput();
}
layers.resize(viewCount, { XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW });
PollActions();
Expand Down Expand Up @@ -549,6 +557,25 @@ void idXR_Win::MapActionStateToUsrCmd(idXrAction action)
}
}

void idXR_Win::ProccessHMDInput()
{
idVec3 viewAngles = ConvertQuatToVec3(views[0].pose.orientation);
viewAngles[YAW] = initialViewAngles[YAW] - viewAngles[YAW];
viewAngles[YAW] *= - 1.0f;
viewAngles[PITCH] = initialViewAngles[PITCH] - viewAngles[PITCH];
viewAngles[PITCH] *= -1.0f;
previousViewAngles = viewAngles;
usercmdGen->SetAngles(viewAngles);
}

idVec3 idXR_Win::ConvertQuatToVec3(XrQuaternionf viewQuat)
{
idVec3 viewAngles = idQuat(viewQuat.x, viewQuat.y, viewQuat.z, viewQuat.w).ToAngles().ToAngularVelocity() * 100.0f;
viewAngles[PITCH] *= in_invertLook.GetBool() ? 1.0f : -1.0f;
viewAngles[ROLL] *= 0.0f;
return viewAngles;
}

uint idXR_Win::EnumerateSwapchainImage(std::vector<SwapchainInfo> swapchainInfo, idXRSwapchainType type, int index)
{
uint imageCount = 0;
Expand Down
6 changes: 5 additions & 1 deletion neo/sys/win32/win_oxr.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class idXR_Win :public idXR {
std::unordered_map<XrSwapchain, std::pair<idXRSwapchainType, std::vector<XrSwapchainImageOpenGLKHR>>> swapchainImageMap{};
int renderingEye = -1;
std::vector<XrView> views;
XrView initialView;
idVec3 initialViewAngles;
idVec3 previousViewAngles;
XrTime predictedDisplayTime;
XrEnvironmentBlendMode environmentBlendMode;
std::vector<XrCompositionLayerProjectionView> layers;
Expand Down Expand Up @@ -168,5 +171,6 @@ class idXR_Win :public idXR {
idXrAction GetActionByName(idStr setName, idStr name);
idXrActionSet GetActionSetByName(idStr setName);
void MapActionStateToUsrCmd(idXrAction action);

void ProccessHMDInput();
idVec3 ConvertQuatToVec3(XrQuaternionf viewQuat);
};

0 comments on commit eb58d64

Please sign in to comment.