VR HUD Attached to off hand controller

Thanks again to the Fully Possesed Mod for the functionality for this one!
This commit is contained in:
Simon 2020-09-25 00:10:19 +01:00
parent 66c7052713
commit aaa37bbe69
11 changed files with 155 additions and 64 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drbeef.doom3quest"
android:versionCode="9"
android:versionName="0.0.15" android:installLocation="auto" >
android:versionCode="11"
android:versionName="0.0.17" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>

View file

@ -26,8 +26,6 @@ extern "C" {
#define ALOGV(...)
#endif
#define TIC_RATE 60
float screenYaw;
float radians(float deg);

View file

@ -59,6 +59,7 @@ extern bool inMenu;
extern bool inGameGuiActive;
extern bool objectiveSystemActive;
extern bool inCinematic;
const int USERCMD_HZ = 60;
void HandleInput_Default( int controlscheme, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
@ -360,6 +361,7 @@ void HandleInput_Default( int controlscheme, ovrInputStateTrackedRemote *pDomina
pVRClientInfo->offhandoffset[2] = pOff->HeadPose.Pose.Position.z - pVRClientInfo->hmdposition[2];
vec3_t rotation = {0};
rotation[PITCH] = -45;
QuatToYawPitchRoll(pOff->HeadPose.Pose.Orientation, rotation, pVRClientInfo->offhandangles);
if (vr_walkdirection == 0) {
@ -375,10 +377,9 @@ void HandleInput_Default( int controlscheme, ovrInputStateTrackedRemote *pDomina
{
//Adjust positional factor for this sample based on how long the last frame took, it should
//approximately even out the positional movement on a per frame basis (especially when fps is much lower than 60)
//NOTE: it'll never be above ~60fps since we use com_fixedTic of "-1"
static float lastSampleTime = 0;
float sampleTime = Sys_Milliseconds();
float vr_positional_factor = 2400.0f * ((1000.0f / TIC_RATE) / (sampleTime-lastSampleTime));
float vr_positional_factor = 2400.0f * ((1000.0f / USERCMD_HZ) / (sampleTime-lastSampleTime));
lastSampleTime = sampleTime;
//This section corrects for the fact that the controller actually controls direction of movement, but we want to move relative to the direction the

View file

@ -1043,6 +1043,9 @@ idPlayer::idPlayer() {
flashlightModelDefHandle = -1;
hudHandle = -1;
memset( &hudEntity, 0, sizeof( hudEntity ) );
skin = NULL;
powerUpSkin = NULL;
baseSkinName = "";
@ -1422,6 +1425,12 @@ void idPlayer::Init( void ) {
SetupFlashlightHolster();
SetupLaserSight();
// re-init hud model
memset( &hudEntity, 0, sizeof( hudEntity ) );
hudEntity.hModel = renderModelManager->FindModel( "/models/mapobjects/hud.lwo" );
hudEntity.customShader = declManager->FindMaterial( "vr/hud" );
hudEntity.weaponDepthHack = true;
}
/*
@ -2103,6 +2112,12 @@ void idPlayer::Restore( idRestoreGame *savefile ) {
SetupFlashlightHolster();
SetupLaserSight();
// re-init hud model
memset( &hudEntity, 0, sizeof( hudEntity ) );
hudEntity.hModel = renderModelManager->FindModel( "/models/mapobjects/hud.lwo" );
hudEntity.customShader = declManager->FindMaterial( "vr/hud" );
hudEntity.weaponDepthHack = true;
}
void idPlayer::SetupLaserSight()
@ -2688,6 +2703,94 @@ void idPlayer::DrawHUD( idUserInterface *_hud ) {
//cursor->Redraw( gameLocal.realClientTime );
}
}
renderSystem->CaptureRenderToImage( "_hudImage" );
}
/*
==============
Koz
idPlayer::UpdateVrHud
==============
*/
void idPlayer::UpdateVrHud()
{
static idVec3 hudOrigin;
static idMat3 hudAxis;
float hudPitch;
if (pVRClientInfo != nullptr)
// update the hud model
if ( (pVRClientInfo == nullptr) || !pVRClientInfo->visible_hud || gameLocal.inCinematic)
{
// hide it
hudEntity.allowSurfaceInViewID = -1;
}
else
{
hudEntity.allowSurfaceInViewID = entityNumber + 1;
{
hudPitch = 10.0f;
float yaw;
{
// CalculateRenderView must have been called first
const idVec3 &viewOrigin = firstPersonViewOrigin;
const idMat3 &viewAxis = firstPersonViewAxis;
if (pVRClientInfo)
{
idAngles angles;
float *pAngles = pVRClientInfo->offhandangles;
angles.pitch = pVRClientInfo->offhandangles[PITCH];
angles.yaw = viewAngles.yaw +
(pVRClientInfo->offhandangles[YAW] - pVRClientInfo->hmdorientation[YAW]);
angles.roll = pVRClientInfo->offhandangles[ROLL];
hudAxis = angles.ToMat3();
idVec3 offpos( -pVRClientInfo->offhandoffset[2],
-pVRClientInfo->offhandoffset[0],
pVRClientInfo->offhandoffset[1]);
idAngles a(0, viewAngles.yaw - pVRClientInfo->hmdorientation[YAW], 0);
offpos *= a.ToMat3();
offpos *= cvarSystem->GetCVarFloat( "vr_worldscale" );
{
hudOrigin = viewOrigin + offpos;
}
}
// GetViewPos( hudOrigin, hudAxis );
// yaw = viewAngles.yaw;
}
//hudAxis = idAngles( hudPitch, yaw, 0.0f ).ToMat3();
//hudOrigin += hudAxis[0] * 24.0f;//vr_hudPosDis.GetFloat();
hudOrigin += hudAxis[1] * -8.0f;
hudOrigin += hudAxis[2] * 16.0f;
}
hudAxis *= 0.7;
hudEntity.axis = hudAxis;
hudEntity.origin = hudOrigin;
hudEntity.weaponDepthHack = true;
}
if ( hudHandle == -1 )
{
hudHandle = gameRenderWorld->AddEntityDef( &hudEntity );
}
else
{
gameRenderWorld->UpdateEntityDef( hudHandle, &hudEntity );
}
}
/*
@ -6367,10 +6470,7 @@ void idPlayer::Think( void ) {
pVRClientInfo->weaponid = -1;
}
cvarSystem->SetCVarBool("vr_weapon_stabilised", pVRClientInfo->weapon_stabilised);
pVRClientInfo->velocitytriggered = (
currentWeapon == WEAPON_FISTS ||
currentWeapon == WEAPON_FLASHLIGHT);
pVRClientInfo->velocitytriggered = currentWeapon == WEAPON_FLASHLIGHT;
pVRClientInfo->pistol = currentWeapon == WEAPON_PISTOL;
}
@ -6511,6 +6611,8 @@ void idPlayer::Think( void ) {
UpdateLaserSight();
UpdateVrHud();
UpdateDeathSkin( false );
if ( gameLocal.isMultiplayer ) {

View file

@ -237,6 +237,9 @@ public:
renderEntity_t flashlightRenderEntity; // used to present a model to the renderer
qhandle_t flashlightModelDefHandle; // handle to static renderer model
renderEntity_t hudEntity;
qhandle_t hudHandle;
bool noclip;
bool godmode;
@ -416,7 +419,7 @@ public:
virtual void UpdateFlashlightHolster();
virtual void SetupLaserSight();
virtual void UpdateLaserSight( );
virtual void UpdateVrHud();
void Kill( bool delayRespawn, bool nodamage );
virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );

View file

@ -462,6 +462,8 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view )
return;
}
player->DrawHUD(hud);
// place the sound origin for the player
gameSoundWorld->PlaceListener( view->vieworg, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined" );
@ -501,16 +503,6 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view )
}
}
vrClientInfo *pVRClientInfo = player->GetVRClientInfo();
if (pVRClientInfo != nullptr &&
pVRClientInfo->visible_hud) {
cvarSystem->SetCVarBool("vr_hud", true);
player->DrawHUD(hud);
cvarSystem->SetCVarBool("vr_hud", false);
}
// armor impulse feedback
float armorPulse = ( gameLocal.time - player->lastArmorPulse ) / 250.0f;

View file

@ -406,6 +406,8 @@ public:
idImage * specular2DTableImage; // 2D intensity texture with our specular function with variable specularity
idImage * borderClampImage; // white inside, black outside
idImage* hudImage;
//--------------------------------------------------------
idImage * AllocImage( const char *name );

View file

@ -369,6 +369,18 @@ static void R_RGBA8Image( idImage *image ) {
TF_DEFAULT, false, TR_REPEAT, TD_HIGH_QUALITY );
}
// Koz begin
// used for Hud and PDA surfaces in VR
static void R_VRSurfaceImage( idImage* image )
{
byte *data = (byte*)malloc(1024 * 1024 * 4);
memset( data, 0, sizeof( data ) );
image->GenerateImage( (byte *)data, 1024, 1024,
TF_DEFAULT, false, TR_CLAMP, TD_HIGH_QUALITY );
}
#if 0
static void R_RGB8Image( idImage *image ) {
byte data[DEFAULT_SIZE][DEFAULT_SIZE][4];
@ -1782,6 +1794,9 @@ void idImageManager::Init() {
scratchCubeMapImage = ImageFromFunction("_scratchCubeMap", makeNormalizeVectorCubeMap );
currentRenderImage = ImageFromFunction("_currentRender", R_RGBA8Image );
hudImage = ImageFromFunction( "_hudImage", R_VRSurfaceImage ); // R_RGBA8Image );
cmdSystem->AddCommand( "reloadImages", R_ReloadImages_f, CMD_FL_RENDERER, "reloads images" );
cmdSystem->AddCommand( "listImages", R_ListImages_f, CMD_FL_RENDERER, "lists images" );
cmdSystem->AddCommand( "combineCubeImages", R_CombineCubeImages_f, CMD_FL_RENDERER, "combines six images for roq compression" );

View file

@ -1197,18 +1197,9 @@ idWindow::Redraw
================
*/
enum eScalingType {
NONE,
SCALETO43,
VRHUD
};
void idWindow::Redraw(float x, float y) {
idStr str;
static int recursiveCount = 0;
recursiveCount++;
if (r_skipGuiShaders.GetInteger() == 1 || dc == NULL ) {
return;
}
@ -1223,32 +1214,19 @@ void idWindow::Redraw(float x, float y) {
return;
}
eScalingType scalingType = NONE;
// DG: allow scaling menus to 4:3
bool fixupFor43 = false;
if ( flags & WIN_DESKTOP ) {
// only scale desktop windows (will automatically scale its sub-windows)
// that EITHER have the scaleto43 flag set OR are fullscreen menus and r_scaleMenusTo43 is 1
if( (flags & WIN_SCALETO43) ||
((flags & WIN_MENUGUI) && r_scaleMenusTo43.GetBool()) )
{
scalingType = SCALETO43;
fixupFor43 = true;
dc->SetMenuScaleFix(true);
}
}
if (scalingType == NONE) {
bool scaledHUDForVR = cvarSystem->GetCVarBool("vr_hud");
if (scaledHUDForVR) {
scalingType = VRHUD;
//Only set this on the first call
if (recursiveCount == 1) {
dc->SetMenuScaleForVR(true);
}
}
}
if ( flags & WIN_SHOWTIME ) {
dc->DrawText(va(" %0.1f seconds\n%s", (float)(time - timeLine) / 1000, gui->State().GetString("name")), 0.35f, 0, dc->colorWhite, idRectangle(100, 0, 80, 80), false);
}
@ -1261,14 +1239,7 @@ void idWindow::Redraw(float x, float y) {
}
if (!visible) {
if (scalingType == SCALETO43) { // DG: gotta reset that before returning this function
dc->SetMenuScaleFix(false);
}
recursiveCount--;
if (scalingType == VRHUD &&
recursiveCount == 0)
{
if (fixupFor43) { // DG: gotta reset that before returning this function
dc->SetMenuScaleFix(false);
}
return;
@ -1339,14 +1310,7 @@ void idWindow::Redraw(float x, float y) {
dc->EnableClipping(true);
}
if (scalingType == SCALETO43) { // DG: gotta reset that before returning this function
dc->SetMenuScaleFix(false);
}
recursiveCount--;
if (scalingType == VRHUD &&
recursiveCount == 0)
{
if (fixupFor43) { // DG: gotta reset that before returning this function
dc->SetMenuScaleFix(false);
}

View file

@ -0,0 +1,14 @@
vr/hud
{
qer_editorimage textures/zaphod/shotgun_laser.TGA
translucent
noShadows
{
blend add
map _hudImage
}
}

Binary file not shown.