Various...

- Teleport (rudimentary - needs work)
- Haptics
- Cleaner exit
- Handle pause to Oculus Home better
This commit is contained in:
Simon 2020-03-29 23:06:48 +01:00
parent 1bbcbb9f57
commit dbf0170cc2
10 changed files with 121 additions and 40 deletions

View file

@ -62,6 +62,8 @@ float vr_snapturn_angle;
vec3_t offhandangles;
vec3_t offhandoffset;
bool player_moving;
bool shutdown;
bool trigger_teleport;
#if !defined( EGL_OPENGL_ES3_BIT_KHR )
@ -150,7 +152,6 @@ LAMBDA1VR Stuff
//This is now controlled by the engine
static bool useVirtualScreen = true;
bool forceVirtualScreen = false;
extern bool automapactive;
void setUseScreenLayer(bool use)
@ -160,7 +161,7 @@ void setUseScreenLayer(bool use)
bool useScreenLayer()
{
return useVirtualScreen || forceVirtualScreen || automapactive;
return useVirtualScreen || automapactive;
}
static void UnEscapeQuotes( char *arg )
@ -1273,6 +1274,9 @@ void VR_Init()
//Initialise our cvar holders
vr_weapon_pitchadjust = -30.0;
shutdown = false;
trigger_teleport = false;
}
static ovrAppThread * gAppThread = NULL;
@ -1371,6 +1375,7 @@ bool processMessageQueue() {
{
gAppState.NativeWindow = NULL;
destroyed = true;
shutdown = true;
break;
}
case MESSAGE_ON_SURFACE_CREATED: { gAppState.NativeWindow = (ANativeWindow *)ovrMessage_GetPointerParm( &message, 0 ); break; }
@ -1427,9 +1432,6 @@ void * AppThreadFunction(void * parm ) {
processMessageQueue();
}
//Use floor based tracking space
vrapi_SetTrackingSpace(gAppState.Ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR);
ovrRenderer_Create(m_width, m_height, &gAppState.Renderer, &java);
if ( gAppState.Ovr == NULL )
@ -1458,6 +1460,13 @@ void * AppThreadFunction(void * parm ) {
return NULL;
}
//All the stuff we want to do each frame
void QzDoom_FrameSetup()
{
//Use floor based tracking space
vrapi_SetTrackingSpace(gAppState.Ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR);
}
void processHaptics() {//Handle haptics
static float lastFrameTime = 0.0f;
float timestamp = (float)(GetTimeInMilliSeconds());

View file

@ -58,6 +58,9 @@ extern vec3_t offhandoffset;
extern bool player_moving;
extern bool trigger_teleport;
extern bool shutdown;
void shutdownVR();
float radians(float deg);
@ -73,7 +76,8 @@ bool useScreenLayer();
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key);
void VR_GetScreenRes(uint32_t *width, uint32_t *height);
void VR_Vibrate( float duration, int channel, float intensity );
bool processMessageQueue();
void QzDoom_FrameSetup();
void C_DoCommandC (const char *cmd);

View file

@ -22,23 +22,11 @@ int getGameState();
int isMenuActive();
void Joy_GenerateButtonEvents(int oldbuttons, int newbuttons, int numbuttons, int base);
extern bool forceVirtualScreen;
void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 )
{
#ifdef _DEBUG
//Show screen view - for testing
if (((pOffTrackedRemoteNew->Buttons & offButton2) !=
(pOffTrackedRemoteOld->Buttons & offButton2)) &&
(pOffTrackedRemoteNew->Buttons & offButton2)) {
forceVirtualScreen = !forceVirtualScreen;
}
#endif
//Menu button - invoke menu
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, KEY_ESCAPE);
@ -164,12 +152,17 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
pOffTracking->HeadPose.Pose.Position.y,
pOffTracking->HeadPose.Pose.Position.z);
//Laser-sight
if ((pDominantTrackedRemoteNew->Buttons & ovrButton_Joystick) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Joystick)
&& (pDominantTrackedRemoteNew->Buttons & ovrButton_Joystick)) {
}
//Teleport - only does anything if vr_teleport cvar is true
static bool ready_teleport = false;
if (pOffTrackedRemoteOld->Joystick.y > 0.7f && !ready_teleport)
{
ready_teleport = true;
}
else if (pOffTrackedRemoteOld->Joystick.y < 0.7f & ready_teleport)
{
ready_teleport = false;
trigger_teleport = true;
}
//Apply a filter and quadratic scaler so small movements are easier to make
//and we don't get movement jitter when the joystick doesn't quite center properly

View file

@ -136,6 +136,7 @@ CVAR (String, save_dir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
CVAR (Bool, cl_waitforsave, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR (Bool, enablescriptscreenshot, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
EXTERN_CVAR (Float, con_midtime);
EXTERN_CVAR(Bool, vr_teleport);
//==========================================================================
//
@ -737,9 +738,11 @@ void G_BuildTiccmd (ticcmd_t *cmd)
float joyside=0;
float dummy=0;
VR_GetMove(&joyforward, &joyside, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy);
side += joyint(joyside * sidemove[speed]);
forward += joyint(joyforward * forwardmove[speed]);
if (!vr_teleport) {
VR_GetMove(&joyforward, &joyside, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy);
side += joyint(joyside * sidemove[speed]);
forward += joyint(joyforward * forwardmove[speed]);
}
cmd->ucmd.pitch = LocalViewPitch >> 16;

View file

@ -31,6 +31,8 @@
#include <map>
#include <cmath>
#include <VrApi_Ext.h>
#include "p_trace.h"
#include "p_linetracedata.h"
#include "gl/system/gl_system.h"
#include "doomtype.h" // Printf
#include "d_player.h"
@ -68,10 +70,13 @@ EXTERN_CVAR(Float, vr_weaponRotate);
EXTERN_CVAR(Float, vr_snapTurn);
EXTERN_CVAR(Float, vr_ipd);
EXTERN_CVAR(Float, vr_weaponScale);
EXTERN_CVAR(Bool, vr_teleport);
double P_XYMovement(AActor *mo, DVector2 scroll);
extern "C" void VR_GetMove( float *joy_forward, float *joy_side, float *hmd_forward, float *hmd_side, float *up, float *yaw, float *pitch, float *roll );
void I_Quit();
extern int game_running;
namespace s3d
{
@ -112,7 +117,8 @@ namespace s3d
// We want to align those two heights here
const player_t & player = players[consoleplayer];
double vh = player.viewheight; // Doom thinks this is where you are
double hh = (hmdPosition[1] - vr_floor_offset) * vr_vunits_per_meter; // HMD is actually here
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
double hh = ((hmdPosition[1] - vr_floor_offset) * vr_vunits_per_meter) / pixelstretch; // HMD is actually here
eyeOffset[2] += hh - vh;
outViewShift[0] = eyeOffset[0];
@ -289,9 +295,10 @@ namespace s3d
mat->scale(vr_vunits_per_meter, vr_vunits_per_meter, -vr_vunits_per_meter);
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
if ((vr_control_scheme < 10 && hand == 1)
|| (vr_control_scheme > 10 && hand == 0)) {
mat->translate(-weaponoffset[0], hmdPosition[1] + weaponoffset[1] - vr_floor_offset, weaponoffset[2]);
mat->translate(-weaponoffset[0], (hmdPosition[1] + weaponoffset[1] - vr_floor_offset) / pixelstretch, weaponoffset[2]);
mat->rotate(-90 + (doomYaw - hmdorientation[YAW]) + weaponangles[YAW], 0, 1, 0);
mat->rotate(-weaponangles[PITCH], 1, 0, 0);
@ -299,11 +306,11 @@ namespace s3d
}
else
{
mat->translate(-offhandoffset[0], (hmdPosition[1] + offhandoffset[1] - vr_floor_offset) / pixelstretch, offhandoffset[2]);
mat->rotate(-90 + (doomYaw - hmdorientation[YAW]) + offhandangles[YAW], 0, 1, 0);
mat->rotate(-offhandangles[PITCH], 1, 0, 0);
mat->rotate(-offhandangles[ROLL], 0, 0, 1);
mat->translate(-offhandoffset[0], hmdPosition[1] + offhandoffset[1] - vr_floor_offset, offhandoffset[2]);
}
return true;
@ -380,6 +387,18 @@ namespace s3d
{
super::SetUp();
QzDoom_FrameSetup();
if (shutdown)
{
game_running = false;
I_Quit();
return;
}
processMessageQueue();
// Set VR-appropriate settings
{
movebob = 0;
@ -423,22 +442,49 @@ namespace s3d
{
if (player)
{
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
//Weapon firing tracking - Thanks Fishbiter for the inspiration of how/where to use this!
{
player->mo->OverrideAttackPosDir = true;
player->mo->AttackPos.X = player->mo->X() - (weaponoffset[0] * vr_vunits_per_meter);
player->mo->AttackPos.Y = player->mo->Y() + (weaponoffset[2] * vr_vunits_per_meter);
player->mo->AttackPos.Z = player->mo->Z() + ((hmdPosition[1] + weaponoffset[1] + vr_floor_offset) * vr_vunits_per_meter);
player->mo->AttackPos.Y = player->mo->Y() - (weaponoffset[2] * vr_vunits_per_meter);
player->mo->AttackPos.Z = player->mo->Z() + (((hmdPosition[1] + weaponoffset[1] + vr_floor_offset) * vr_vunits_per_meter) / pixelstretch);
vec3_t angles;
VectorSet(angles, -GLRenderer->mAngles.Pitch.Degrees, (doomYaw - hmdorientation[YAW]) + weaponangles[YAW], 0);
vec3_t v_forward, v_right, v_up;
AngleVectors(angles, v_forward, v_right, v_up);
player->mo->AttackDir = MapAttackDir;
}
if (vr_teleport) {
// Teleport?
DAngle yaw((doomYaw - hmdorientation[YAW]) + offhandangles[YAW]);
DAngle pitch(offhandangles[PITCH]);
FLineTraceData trace;
if (trigger_teleport &&
P_LineTrace(player->mo, yaw, 8192, pitch, TRF_ABSOFFSET,
((hmdPosition[1] + weaponoffset[1] + vr_floor_offset) * vr_vunits_per_meter) / pixelstretch,
-(weaponoffset[2] * vr_vunits_per_meter),
-(weaponoffset[0] * vr_vunits_per_meter), &trace) &&
trace.HitType == TRACE_HitFloor) {
auto vel = player->mo->Vel;
player->mo->Vel = DVector3(trace.HitLocation.X - player->mo->X(),
trace.HitLocation.Y - player->mo->Y(), 0);
bool wasOnGround = player->mo->Z() <= player->mo->floorz;
double oldZ = player->mo->Z();
P_XYMovement(player->mo, DVector2(0, 0));
//if we were on the ground before offsetting, make sure we still are (this fixes not being able to move on lifts)
if (player->mo->Z() >= oldZ && wasOnGround) {
player->mo->SetZ(player->mo->floorz);
} else {
player->mo->SetZ(oldZ);
}
player->mo->Vel = vel;
}
trigger_teleport = false;
}
//Positional Movement
float hmd_forward=0;
float hmd_side=0;

View file

@ -64,6 +64,8 @@ CVAR(Int, vr_control_scheme, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, vr_moveFollowsOffHand, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, vr_teleport, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Float, vr_weaponRotate, -30, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Float, vr_weaponScale, 1.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)

View file

@ -4390,6 +4390,9 @@ static ETraceStatus CheckForActor(FTraceResults &res, void *userdata)
// if damage == 0, it is just a test trace that will leave linetarget set
//
//==========================================================================
EXTERN_CVAR(Int, vr_control_scheme)
extern "C" void VR_Vibrate( float duration, int channel, float intensity );
extern bool weaponStabilised;
AActor *P_LineAttack(AActor *t1, DAngle angle, double distance,
DAngle pitch, int damage, FName damageType, PClassActor *pufftype, int flags, FTranslatedLineTarget*victim, int *actualdamage,
@ -4428,6 +4431,14 @@ AActor *P_LineAttack(AActor *t1, DAngle angle, double distance,
// this is coming from a weapon attack function which needs to transfer information to the obituary code,
// We need to preserve this info from the damage type because the actual damage type can get overridden by the puff
pflag = DMG_PLAYERATTACK;
//Haptics
long rightHanded = vr_control_scheme < 10;
VR_Vibrate( 150, rightHanded ? 1 : 0, 0.8 );
if (weaponStabilised)
{
VR_Vibrate( 150, rightHanded ? 0 : 1, 0.6 );
}
}
// [MC] If overriding, set it to the base of the actor.

View file

@ -6677,6 +6677,9 @@ DEFINE_ACTION_FUNCTION(AActor, SpawnSubMissile)
= Tries to aim at a nearby monster
================
*/
EXTERN_CVAR(Int, vr_control_scheme)
extern "C" void VR_Vibrate( float duration, int channel, float intensity );
extern bool weaponStabilised;
AActor *P_SpawnPlayerMissile (AActor *source, double x, double y, double z,
PClassActor *type, DAngle angle, FTranslatedLineTarget *pLineTarget, AActor **pMissileActor,
@ -6768,6 +6771,16 @@ AActor *P_SpawnPlayerMissile (AActor *source, double x, double y, double z,
MissileActor->Vel3DFromAngle(pitch, MissileActor->Speed);
}
//Haptics
long rightHanded = vr_control_scheme < 10;
VR_Vibrate( 150, rightHanded ? 1 : 0, 0.8 );
if (weaponStabilised)
{
VR_Vibrate( 150, rightHanded ? 0 : 1, 0.6 );
}
if (MissileActor->flags4 & MF4_SPECTRAL)
{
MissileActor->SetFriendPlayer(source->player);

View file

@ -171,7 +171,7 @@ DFrameBuffer *NoSDLGLVideo::CreateFrameBuffer (int width, int height, bool bgra,
buffers = atoi(hwBuffers);
}
Printf("HW buffers = %d\n", buffers);
fb = new OpenGLFrameBuffer(0, width, height, 32, 60, fullscreen, buffers);
fb = new OpenGLFrameBuffer(0, width, height, 32, 72, true, buffers);
retry = 0;
return fb;

View file

@ -131,7 +131,7 @@ FRenderViewpoint::FRenderViewpoint()
TanSin = 0.0;
camera = nullptr;
sector = nullptr;
FieldOfView = 90.; // Angles in the SCREENWIDTH wide window
FieldOfView = 104.; // Angles in the SCREENWIDTH wide window
TicFrac = 0.0;
FrameTime = 0;
extralight = 0;