mirror of
https://github.com/astromaddie/lambda1-vr.git
synced 2026-10-25 11:00:14 +01:00
Final bits for OpenXR support
fixed projection
This commit is contained in:
1 parent
1f60a9d2c4
commit
2aa7dfddc5
10 files changed
+130
-103
No files matched your search
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.drbeef.lambda1vr"
|
||||
android:versionCode="29"
|
||||
android:versionName="1.5.1" android:installLocation="auto" >
|
||||
android:versionCode="30"
|
||||
android:versionName="1.6.0" android:installLocation="auto" >
|
||||
|
||||
<!-- Tell the system this app requires OpenGL ES 3.1. -->
|
||||
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>
|
||||
|
||||
@@ -28,14 +28,6 @@
|
||||
//Let's go to the maximum!
|
||||
extern float SS_MULTIPLIER;
|
||||
|
||||
float radians(float deg) {
|
||||
return (deg * M_PI) / 180.0;
|
||||
}
|
||||
|
||||
float degrees(float rad) {
|
||||
return (rad * 180.0) / M_PI;
|
||||
}
|
||||
|
||||
/* global arg_xxx structs */
|
||||
struct arg_dbl *ss;
|
||||
struct arg_int *cpu;
|
||||
@@ -161,6 +153,8 @@ void setWorldPosition( float x, float y, float z )
|
||||
|
||||
void VR_SetHMDOrientation(float pitch, float yaw, float roll)
|
||||
{
|
||||
VectorSet(hmdorientation, pitch, yaw, roll);
|
||||
|
||||
if (!VR_UseScreenLayer())
|
||||
{
|
||||
playerYaw = yaw;
|
||||
@@ -245,6 +239,34 @@ float VR_GetScreenLayerDistance()
|
||||
return (4.5f);
|
||||
}
|
||||
|
||||
bool VR_GetVRProjection(int eye, float zNear, float zFar, float* projection)
|
||||
{
|
||||
if (strstr(gAppState.OpenXRHMD, "pico") != NULL)
|
||||
{
|
||||
XrMatrix4x4f_CreateProjectionFov(
|
||||
&(gAppState.ProjectionMatrices[eye]), GRAPHICS_OPENGL_ES,
|
||||
gAppState.Projections[eye].fov, zNear, zFar);
|
||||
}
|
||||
|
||||
if (strstr(gAppState.OpenXRHMD, "meta") != NULL)
|
||||
{
|
||||
XrFovf fov = {};
|
||||
for (int eye = 0; eye < ovrMaxNumEyes; eye++)
|
||||
{
|
||||
fov.angleLeft += gAppState.Projections[eye].fov.angleLeft / 2.0f;
|
||||
fov.angleRight += gAppState.Projections[eye].fov.angleRight / 2.0f;
|
||||
fov.angleUp += gAppState.Projections[eye].fov.angleUp / 2.0f;
|
||||
fov.angleDown += gAppState.Projections[eye].fov.angleDown / 2.0f;
|
||||
}
|
||||
XrMatrix4x4f_CreateProjectionFov(
|
||||
&(gAppState.ProjectionMatrices[eye]), GRAPHICS_OPENGL_ES,
|
||||
fov, zNear, zFar);
|
||||
}
|
||||
|
||||
memcpy(projection, gAppState.ProjectionMatrices[eye].m, 16 * sizeof(float));
|
||||
return true;
|
||||
}
|
||||
|
||||
void R_ChangeDisplaySettings( int width, int height, qboolean fullscreen );
|
||||
|
||||
//All the stuff we want to do each frame specifically for this game
|
||||
@@ -447,77 +469,73 @@ void * AppThreadFunction( void * parm )
|
||||
bool destroyed = false;
|
||||
while (!destroyed)
|
||||
{
|
||||
TBXR_FrameSetup();
|
||||
//We are now shutting down
|
||||
if (runStatus == 0)
|
||||
{
|
||||
destroyed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TBXR_FrameSetup();
|
||||
|
||||
//Call the game drawing code to populate the cylinder layer texture
|
||||
//if we are now shutting down, drop out here
|
||||
if (isHostAlive()) {
|
||||
|
||||
//Seed the random number generator the same for each eye to ensure electricity is drawn the same
|
||||
int lSeed = rand();
|
||||
|
||||
//Set everything up
|
||||
Host_BeginFrame();
|
||||
|
||||
// Render the eye images.
|
||||
for (int eye = 0; eye < ovrMaxNumEyes; eye++)
|
||||
//Call the game drawing code to populate the cylinder layer texture
|
||||
//if we are now shutting down, drop out here
|
||||
if (isHostAlive())
|
||||
{
|
||||
TBXR_prepareEyeBuffer(eye);
|
||||
|
||||
if (gAppState.FrameState.shouldRender)
|
||||
//Seed the random number generator the same for each eye to ensure electricity is drawn the same
|
||||
int lSeed = rand();
|
||||
|
||||
//Set everything up
|
||||
Host_BeginFrame();
|
||||
|
||||
// Render the eye images.
|
||||
for (int eye = 0; eye < ovrMaxNumEyes && isHostAlive(); eye++)
|
||||
{
|
||||
if (isScopeEngaged()) {
|
||||
//Now do the drawing for this eye - Force the set as it is a "read only" cvar
|
||||
char buffer[5];
|
||||
Q_snprintf(buffer, 5, "%i", eye+2);
|
||||
Cvar_Set2("vr_stereo_side", buffer, true);
|
||||
}
|
||||
else
|
||||
TBXR_prepareEyeBuffer(eye);
|
||||
|
||||
if (gAppState.FrameState.shouldRender)
|
||||
{
|
||||
//Now do the drawing for this eye - Force the set as it is a "read only" cvar
|
||||
char buffer[5];
|
||||
Q_snprintf(buffer, 5, "%i", eye);
|
||||
Cvar_Set2("vr_stereo_side", buffer, true);
|
||||
if (isScopeEngaged())
|
||||
{
|
||||
//Now do the drawing for this eye - Force the set as it is a "read only" cvar
|
||||
char buffer[5];
|
||||
Q_snprintf(buffer, 5, "%i", eye + 2);
|
||||
Cvar_Set2("vr_stereo_side", buffer, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Now do the drawing for this eye - Force the set as it is a "read only" cvar
|
||||
char buffer[5];
|
||||
Q_snprintf(buffer, 5, "%i", eye);
|
||||
Cvar_Set2("vr_stereo_side", buffer, true);
|
||||
}
|
||||
|
||||
|
||||
//Sow the seed
|
||||
COM_SetRandomSeed(lSeed);
|
||||
|
||||
Host_Frame();
|
||||
}
|
||||
|
||||
|
||||
//Sow the seed
|
||||
COM_SetRandomSeed(lSeed);
|
||||
|
||||
Host_Frame();
|
||||
TBXR_finishEyeBuffer(eye);
|
||||
}
|
||||
|
||||
TBXR_finishEyeBuffer(eye);
|
||||
Host_EndFrame();
|
||||
|
||||
TBXR_submitFrame();
|
||||
}
|
||||
|
||||
Host_EndFrame();
|
||||
|
||||
TBXR_submitFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
//We are now shutting down
|
||||
if (runStatus == 0)
|
||||
{
|
||||
//Give us half a second (36 frames)
|
||||
shutdownCountdown = 36;
|
||||
runStatus++;
|
||||
} else if (runStatus == 1)
|
||||
{
|
||||
if (--shutdownCountdown == 0) {
|
||||
runStatus++;
|
||||
}
|
||||
} else if (runStatus == 2)
|
||||
{
|
||||
Host_Shutdown();
|
||||
runStatus++;
|
||||
} else if (runStatus == 3)
|
||||
{
|
||||
destroyed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
TBXR_LeaveVR();
|
||||
//Ask Java to shut down
|
||||
VR_Shutdown();
|
||||
|
||||
// exit(0); // in case Java doesn't do the job
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -492,10 +492,9 @@ float vibration_channel_intensity[2] = {0.0f, 0.0f};
|
||||
|
||||
void TBXR_Vibrate( int duration, int chan, float intensity )
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
for (int channel = 0; channel < 2; ++channel)
|
||||
{
|
||||
int channel = i;
|
||||
if ((i + 1) & chan)
|
||||
if ((channel + 1) & (chan+1))
|
||||
{
|
||||
if (vibration_channel_duration[channel] > 0.0f)
|
||||
return;
|
||||
|
||||
@@ -68,7 +68,6 @@ bool isMultiplayer();
|
||||
bool isScopeEngaged();
|
||||
bool isPlayerDead();
|
||||
|
||||
|
||||
float length(float x, float y);
|
||||
float nonLinearFilter(float in);
|
||||
bool between(float min, float val, float max);
|
||||
|
||||
@@ -178,8 +178,8 @@ void HandleInput_Alt( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovr
|
||||
float zxDist = length(x, z);
|
||||
|
||||
if (zxDist != 0.0f && z != 0.0f) {
|
||||
VectorSet(weaponangles[ADJUSTED], degrees(atanf(y / zxDist)), (cl.refdef.cl_viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[UNADJUSTED], degrees(atanf(y / zxDist)), (cl.refdef.cl_viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[ADJUSTED], RAD2DEG(atanf(y / zxDist)), (cl.refdef.cl_viewangles[YAW] - hmdorientation[YAW]) - RAD2DEG(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[UNADJUSTED], RAD2DEG(atanf(y / zxDist)), (cl.refdef.cl_viewangles[YAW] - hmdorientation[YAW]) - RAD2DEG(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -190,8 +190,8 @@ void HandleInput_Alt2( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ov
|
||||
float zxDist = length(x, z);
|
||||
|
||||
if (zxDist != 0.0f && z != 0.0f) {
|
||||
VectorSet(weaponangles[ADJUSTED], degrees(atanf(y / zxDist)), (forwardYaw+snapTurn) - degrees(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[UNADJUSTED], degrees(atanf(y / zxDist)), (forwardYaw+snapTurn) - degrees(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[ADJUSTED], RAD2DEG(atanf(y / zxDist)), (forwardYaw+snapTurn) - RAD2DEG(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[UNADJUSTED], RAD2DEG(atanf(y / zxDist)), (forwardYaw+snapTurn) - RAD2DEG(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -191,8 +191,8 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
||||
float zxDist = length(x, z);
|
||||
|
||||
if (zxDist != 0.0f && z != 0.0f) {
|
||||
VectorSet(weaponangles[ADJUSTED], degrees(atanf(y / zxDist)), (forwardYaw+snapTurn) - degrees(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[UNADJUSTED], degrees(atanf(y / zxDist)), (forwardYaw+snapTurn) - degrees(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[ADJUSTED], RAD2DEG(atanf(y / zxDist)), (forwardYaw+snapTurn) - RAD2DEG(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
|
||||
VectorSet(weaponangles[UNADJUSTED], RAD2DEG(atanf(y / zxDist)), (forwardYaw+snapTurn) - RAD2DEG(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -413,12 +413,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
||||
static bool weaponSwitched = false;
|
||||
if (vr_snapturn_angle->value != 0) // if snap angle feature is enabled
|
||||
{
|
||||
if (between(-0.25f, pDominantTrackedRemoteNew->Joystick.x, 0.25f) &&
|
||||
(between(0.75f, pDominantTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.75f)))
|
||||
if (between(0.6f, pDominantTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.6f))
|
||||
{
|
||||
if (!weaponSwitched) {
|
||||
if (between(0.75f, pDominantTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
if (between(0.6f, pDominantTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
{
|
||||
sendButtonActionSimple("invprev");
|
||||
}
|
||||
@@ -435,27 +434,27 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
||||
}
|
||||
else // allow slot selection (columns of weapon hud)
|
||||
{
|
||||
if (between(0.75f, pDominantTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.75f) ||
|
||||
between(0.75f, pDominantTrackedRemoteNew->Joystick.x, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.x, -0.75f))
|
||||
if (between(0.6f, pDominantTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.6f) ||
|
||||
between(0.6f, pDominantTrackedRemoteNew->Joystick.x, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.x, -0.6f))
|
||||
{
|
||||
if (!weaponSwitched) {
|
||||
if (!weaponSwitched)
|
||||
{
|
||||
if (between(0.75f, pDominantTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
if (between(0.6f, pDominantTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
{
|
||||
sendButtonActionSimple("invnext"); // in this mode is makes more sense to select the next item with Joystick down; this is the mouse wheel behaviour in hl
|
||||
}
|
||||
else if (between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.75f))
|
||||
else if (between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.6f))
|
||||
{
|
||||
sendButtonActionSimple("invprev");
|
||||
}
|
||||
else if (between(0.75f, pDominantTrackedRemoteNew->Joystick.x, 1.0f))
|
||||
else if (between(0.6f, pDominantTrackedRemoteNew->Joystick.x, 1.0f))
|
||||
{
|
||||
sendButtonActionSimple("invprevslot"); // not an original hl methode -> needs update from hlsdk-xash3d
|
||||
}
|
||||
else if (between(-1.0f, pDominantTrackedRemoteNew->Joystick.x, -0.75f))
|
||||
else if (between(-1.0f, pDominantTrackedRemoteNew->Joystick.x, -0.6f))
|
||||
{
|
||||
sendButtonActionSimple("invnextslot");
|
||||
}
|
||||
@@ -519,16 +518,16 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
||||
remote_movementForward);
|
||||
} else {
|
||||
static bool scopeZoomed = false;
|
||||
if (between(0.75f, pOffTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pOffTrackedRemoteNew->Joystick.y, -0.75f))
|
||||
if (between(0.6f, pOffTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pOffTrackedRemoteNew->Joystick.y, -0.6f))
|
||||
{
|
||||
if (!scopeZoomed)
|
||||
{
|
||||
if (between(0.75f, pOffTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
if (between(0.6f, pOffTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
{
|
||||
sendButtonActionSimple("impulse 104"); //zoom in
|
||||
}
|
||||
else if (between(-1.0f, pOffTrackedRemoteNew->Joystick.y, -0.75f))
|
||||
else if (between(-1.0f, pOffTrackedRemoteNew->Joystick.y, -0.6f))
|
||||
{
|
||||
sendButtonActionSimple("impulse 105"); //zoom out
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ GNU General Public License for more details.
|
||||
|
||||
#ifndef XASH_DEDICATED
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "common.h"
|
||||
#include "client.h"
|
||||
#include "gl_local.h"
|
||||
@@ -35,6 +36,9 @@ ref_instance_t RI, prevRI;
|
||||
mleaf_t *r_viewleaf, *r_oldviewleaf;
|
||||
mleaf_t *r_viewleaf2, *r_oldviewleaf2;
|
||||
|
||||
extern convar_t *vr_worldscale;
|
||||
extern convar_t *vr_stereo_side;
|
||||
|
||||
static int R_RankForRenderMode( cl_entity_t *ent )
|
||||
{
|
||||
switch( ent->curstate.rendermode )
|
||||
@@ -625,6 +629,8 @@ void R_SetupFrustum( void )
|
||||
R_SetupProjectionMatrix
|
||||
=============
|
||||
*/
|
||||
bool VR_GetVRProjection(int eye, float zNear, float zFar, float* projection);
|
||||
|
||||
static void R_SetupProjectionMatrix( const ref_params_t *fd, matrix4x4 m )
|
||||
{
|
||||
GLdouble xMin, xMax, yMin, yMax, zNear, zFar;
|
||||
@@ -642,13 +648,21 @@ static void R_SetupProjectionMatrix( const ref_params_t *fd, matrix4x4 m )
|
||||
zNear = 4.0f;
|
||||
zFar = max( 256.0f, RI.farClip );
|
||||
|
||||
yMax = zNear * tan( fd->fov_y * M_PI / 360.0 );
|
||||
yMin = -yMax;
|
||||
float vrProjection[16];
|
||||
if (!VR_GetVRProjection(vr_stereo_side->value, zNear, zFar, vrProjection))
|
||||
{
|
||||
yMax = zNear * tan(fd->fov_y * M_PI / 360.0);
|
||||
yMin = -yMax;
|
||||
|
||||
xMax = zNear * tan( fd->fov_x * M_PI / 360.0 );
|
||||
xMin = -xMax;
|
||||
xMax = zNear * tan(fd->fov_x * M_PI / 360.0);
|
||||
xMin = -xMax;
|
||||
|
||||
Matrix4x4_CreateProjection( m, xMax, xMin, yMax, yMin, zNear, zFar );
|
||||
Matrix4x4_CreateProjection(m, xMax, xMin, yMax, yMin, zNear, zFar);
|
||||
}
|
||||
else
|
||||
{
|
||||
Matrix4x4_FromArrayFloatGL(m, vrProjection);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VR
|
||||
@@ -657,8 +671,6 @@ static void R_SetupProjectionMatrix( const ref_params_t *fd, matrix4x4 m )
|
||||
R_SetupModelviewMatrix
|
||||
=============
|
||||
*/
|
||||
extern convar_t *vr_worldscale;
|
||||
extern convar_t *vr_stereo_side;
|
||||
static void R_SetupModelviewMatrix( const ref_params_t *fd, matrix4x4 m )
|
||||
{
|
||||
Matrix4x4_CreateModelview( m );
|
||||
|
||||
@@ -139,7 +139,7 @@ Q_buildcommit will identify this build as release or "notset"
|
||||
*/
|
||||
const char *Q_buildcommit( void )
|
||||
{
|
||||
return "Lambda1VR-v1.5.1";
|
||||
return "Lambda1VR-v1.6.0";
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1 +1 @@
|
||||
xash3d -log
|
||||
xash3d -game valve
|
||||
Reference in new issue
Block a user