Skip to content

Commit

Permalink
Room scale movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishbiter committed Dec 31, 2018
1 parent 38b4ee5 commit 5660604
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 53 deletions.
18 changes: 9 additions & 9 deletions Quake/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,17 +498,17 @@ void R_SetupGL (void)
GL_SetFrustum(r_fovx, r_fovy); //johnfitz -- use r_fov* vars

// glCullFace(GL_BACK); //johnfitz -- glquake used CCW with backwards culling -- let's do it right
}

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(-90, 1, 0, 0); // put Z going up
glRotatef(90, 0, 0, 1); // put Z going up
glRotatef(-r_refdef.viewangles[2], 1, 0, 0);
glRotatef(-r_refdef.viewangles[0], 0, 1, 0);
glRotatef(-r_refdef.viewangles[1], 0, 0, 1);
glTranslatef(-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);
}
glRotatef(-90, 1, 0, 0); // put Z going up
glRotatef(90, 0, 0, 1); // put Z going up
glRotatef(-r_refdef.viewangles[2], 1, 0, 0);
glRotatef(-r_refdef.viewangles[0], 0, 1, 0);
glRotatef(-r_refdef.viewangles[1], 0, 0, 1);
glTranslatef(-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);

//
// set drawing parms
Expand Down
63 changes: 51 additions & 12 deletions Quake/sv_phys.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,38 +926,77 @@ void SV_Physics_Client (edict_t *ent, int num)
switch ((int)ent->v.movetype)
{
case MOVETYPE_NONE:
if (!SV_RunThink (ent))
if (!SV_RunThink(ent))
return;
break;

case MOVETYPE_WALK:
if (!SV_RunThink (ent))
if (!SV_RunThink(ent))
return;
if (!SV_CheckWater (ent) && ! ((int)ent->v.flags & FL_WATERJUMP) )
SV_AddGravity (ent);
SV_CheckStuck (ent);
SV_WalkMove (ent);
if (!SV_CheckWater(ent) && !((int)ent->v.flags & FL_WATERJUMP))
SV_AddGravity(ent);
SV_CheckStuck(ent);
SV_WalkMove(ent);

break;

case MOVETYPE_TOSS:
case MOVETYPE_BOUNCE:
SV_Physics_Toss (ent);
SV_Physics_Toss(ent);
break;

case MOVETYPE_FLY:
if (!SV_RunThink (ent))
if (!SV_RunThink(ent))
return;
SV_FlyMove (ent, host_frametime, NULL);
SV_FlyMove(ent, host_frametime, NULL);
break;

case MOVETYPE_NOCLIP:
if (!SV_RunThink (ent))
if (!SV_RunThink(ent))
return;
VectorMA (ent->v.origin, host_frametime, ent->v.velocity, ent->v.origin);
VectorMA(ent->v.origin, host_frametime, ent->v.velocity, ent->v.origin);
break;

default:
Sys_Error ("SV_Physics_client: bad movetype %i", (int)ent->v.movetype);
Sys_Error("SV_Physics_client: bad movetype %i", (int)ent->v.movetype);
}

if (num == cl.viewentity && vr_enabled.value)
{
vec3_t restoreVel;
_VectorCopy(ent->v.velocity, restoreVel);
extern vec3_t vr_room_scale_move;
VectorScale(vr_room_scale_move, 1.0f / host_frametime, ent->v.velocity);

switch ((int)ent->v.movetype)
{
case MOVETYPE_NONE:
break;

case MOVETYPE_WALK:
ent->v.velocity[2] = -1.0f;
SV_CheckStuck(ent);
SV_WalkMove(ent);

break;

case MOVETYPE_TOSS:
case MOVETYPE_BOUNCE:
break;

case MOVETYPE_FLY:
SV_FlyMove(ent, host_frametime, NULL);
break;

case MOVETYPE_NOCLIP:
VectorMA(ent->v.origin, host_frametime, ent->v.velocity, ent->v.origin);
break;

default:
Sys_Error("SV_Physics_client: bad movetype %i", (int)ent->v.movetype);
}

_VectorCopy(restoreVel, ent->v.velocity);
}

//
Expand Down
69 changes: 37 additions & 32 deletions Quake/vr.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ static GLuint mirror_fbo = 0;
static int attempt_to_refocus_retry = 0;

static vec3_t headOrigin;
static vec3_t lastHeadOrigin;

vec3_t vr_room_scale_move;

// Wolfenstein 3D, DOOM and QUAKE use the same coordinate/unit system:
// 8 foot (96 inch) height wall == 64 units, 1.5 inches per pixel unit
Expand All @@ -137,8 +140,8 @@ cvar_t vr_deadzone = { "vr_deadzone","30",CVAR_ARCHIVE };
cvar_t vr_viewkick = { "vr_viewkick", "0", CVAR_NONE };
cvar_t vr_lefthanded = { "vr_lefthanded", "0", CVAR_NONE };
cvar_t vr_gunangle = { "vr_gunangle", "32", CVAR_ARCHIVE };
cvar_t vr_world_scale = { "vr_world_scale", "0.75", CVAR_ARCHIVE };

cvar_t vr_world_scale = { "vr_world_scale", "1.0", CVAR_ARCHIVE };
cvar_t vr_floor_offset = { "vr_floor_offset", "-16", CVAR_ARCHIVE };

static qboolean InitOpenGLExtensions()
{
Expand Down Expand Up @@ -478,11 +481,14 @@ void Mod_Weapon(const char* name, aliashdr_t* hdr)

if (state->cvarId != -1)
{
VectorScale(state->scale, vr_weapon_offset[state->cvarId * VARS_PER_WEAPON + 3].value, hdr->scale);

float scaleCorrect = vr_world_scale.value / 0.75f; //initial version had 0.75 default world scale, so weapons reflect that
VectorScale(state->scale, vr_weapon_offset[state->cvarId * VARS_PER_WEAPON + 3].value * scaleCorrect, hdr->scale);

vec3_t ofs = { vr_weapon_offset[state->cvarId * VARS_PER_WEAPON].value, vr_weapon_offset[state->cvarId * VARS_PER_WEAPON + 1].value, vr_weapon_offset[state->cvarId * VARS_PER_WEAPON + 2].value };

VectorAdd(state->scale_origin, ofs, hdr->scale_origin);
VectorScale(hdr->scale_origin, scaleCorrect, hdr->scale_origin);
}
}

Expand Down Expand Up @@ -553,6 +559,7 @@ void VID_VR_Init()
Cvar_RegisterVariable(&vr_lefthanded);
Cvar_RegisterVariable(&vr_gunangle);
Cvar_RegisterVariable(&vr_world_scale);
Cvar_RegisterVariable(&vr_floor_offset);
Cvar_SetCallback(&vr_deadzone, VR_Deadzone_f);

InitAllWeaponCVars();
Expand Down Expand Up @@ -604,7 +611,7 @@ qboolean VR_Enable()
eyes[i].fov_y = (atan(-UpTan) + atan(DownTan)) / M_PI_DIV_180;
}

//VR_SetTrackingSpace(0); // Put us into seated tracking position
VR_SetTrackingSpace(TrackingUniverseStanding); // Put us into standing tracking position
VR_ResetOrientation(); // Recenter the HMD

wglSwapIntervalEXT(0); // Disable V-Sync
Expand Down Expand Up @@ -693,7 +700,7 @@ void SetHandPos(int index, entity_t *player)

cl.handpos[index][0] = -headLocal[0] + player->origin[0];
cl.handpos[index][1] = -headLocal[1] + player->origin[1];
cl.handpos[index][2] = headLocal[2] + player->origin[2];
cl.handpos[index][2] = headLocal[2] + player->origin[2] + vr_floor_offset.value;
}

void IdentifyAxes(int device);
Expand All @@ -711,12 +718,11 @@ void VR_UpdateScreenContent()
return;
}

// Update hand position values
entity_t *player = &cl_entities[cl.viewentity];

w = glwidth;
h = glheight;

entity_t *player = &cl_entities[cl.viewentity];

// Update poses
IVRCompositor_WaitGetPoses(VRCompositor(), ovr_DevicePose, k_unMaxTrackedDeviceCount, NULL, 0);

Expand All @@ -731,6 +737,18 @@ void VR_UpdateScreenContent()
headOrigin[1] = headPos.v[0];
headOrigin[2] = headPos.v[1];

vec3_t moveInTracking;
_VectorSubtract(headOrigin, lastHeadOrigin, moveInTracking);
moveInTracking[0] *= -meters_to_units;
moveInTracking[1] *= -meters_to_units;
moveInTracking[2] = 0;
Vec3RotateZ(moveInTracking, vrYaw * M_PI_DIV_180, vr_room_scale_move);

_VectorCopy(headOrigin, lastHeadOrigin);
_VectorSubtract(headOrigin, lastHeadOrigin, headOrigin);
headPos.v[0] -= lastHeadOrigin[1];
headPos.v[2] -= lastHeadOrigin[0];

HmdQuaternion_t headQuat = Matrix34ToQuaternion(ovr_DevicePose->mDeviceToAbsoluteTracking);
HmdVector3_t leyePos = Matrix34ToVector(IVRSystem_GetEyeToHeadTransform(ovrHMD, eyes[0].eye));
HmdVector3_t reyePos = Matrix34ToVector(IVRSystem_GetEyeToHeadTransform(ovrHMD, eyes[1].eye));
Expand Down Expand Up @@ -777,9 +795,9 @@ void VR_UpdateScreenContent()
IVRSystem_GetControllerState(VRSystem(), iDevice, &controller->state);
controller->rawvector = rawControllerPos;
controller->raworientation = rawControllerQuat;
controller->position[0] = rawControllerPos.v[2] * meters_to_units;
controller->position[1] = rawControllerPos.v[0] * meters_to_units;
controller->position[2] = rawControllerPos.v[1] * meters_to_units;
controller->position[0] = (rawControllerPos.v[2] - lastHeadOrigin[0]) * meters_to_units;
controller->position[1] = (rawControllerPos.v[0] - lastHeadOrigin[1]) * meters_to_units;
controller->position[2] = (rawControllerPos.v[1]) * meters_to_units;
QuatToYawPitchRoll(rawControllerQuat, controller->orientation);
}
}
Expand Down Expand Up @@ -867,9 +885,6 @@ void VR_UpdateScreenContent()
AngleVectorFromRotMat(mat, cl.handrot[i]);
}

// TODO: Add indipendant move angle for offhand controller
// TODO: Fix shoot origin not being the gun's

if (cl.viewent.model)
{
aliashdr_t* hdr = (aliashdr_t *)Mod_Extradata(cl.viewent.model);
Expand Down Expand Up @@ -903,6 +918,7 @@ void VR_UpdateScreenContent()
temp[1] = -current_eye->position.v[0] * meters_to_units; // Y
temp[2] = current_eye->position.v[1] * meters_to_units; // Z
Vec3RotateZ(temp, (r_refdef.viewangles[YAW] - orientation[YAW])*M_PI_DIV_180, vr_viewOffset);
vr_viewOffset[2] += vr_floor_offset.value;

RenderScreenForCurrentEye_OVR();
}
Expand All @@ -915,28 +931,17 @@ void VR_UpdateScreenContent()
}

void VR_SetMatrices() {
HmdMatrix44_t projection;

// Calculate HMD projection matrix and view offset position
projection = TransposeMatrix(IVRSystem_GetProjectionMatrix(ovrHMD, current_eye->eye, 4.f, gl_farclip.value));

// Set OpenGL projection and view matrices
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((GLfloat*)projection.m);
HmdMatrix44_t projection;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Calculate HMD projection matrix and view offset position
projection = TransposeMatrix(IVRSystem_GetProjectionMatrix(ovrHMD, current_eye->eye, 4.f, gl_farclip.value));

glRotatef(-90, 1, 0, 0); // put Z going up
glRotatef(90, 0, 0, 1); // put Z going up

glRotatef(-r_refdef.viewangles[ROLL], 1, 0, 0);
glRotatef(-r_refdef.viewangles[PITCH], 0, 1, 0);
glRotatef(-r_refdef.viewangles[YAW], 0, 0, 1);

glTranslatef(-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);
// Set OpenGL projection and view matrices
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((GLfloat*)projection.m);
}


void VR_AddOrientationToViewAngles(vec3_t angles)
{
vec3_t orientation;
Expand Down
15 changes: 15 additions & 0 deletions Quake/vr_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ static void VR_MenuPrintOptionValue(int cx, int cy, int option)
case VR_AIMMODE_BLENDED_NOPITCH:
value_string = "BLENDED_NOPITCH";
break;
case VR_AIMMODE_CONTROLLER:
value_string = "CONTROLLER";
break;
}
break;
case VR_OPTION_DEADZONE:
Expand Down Expand Up @@ -112,6 +115,9 @@ static void VR_MenuPrintOptionValue(int cx, int cy, int option)
case VR_OPTION_CROSSHAIR_ALPHA:
M_DrawSlider( cx, cy, vr_crosshair_alpha.value );
break;
case VR_OPTION_WORLD_SCALE:
M_DrawSlider(cx, cy, vr_world_scale.value / 2.0f);
break;
}
#ifdef _MSC_VER
#undef snprintf
Expand Down Expand Up @@ -185,6 +191,11 @@ static void VR_MenuKeyOption(int key, int option)
floatValue = CLAMP( 0.0f, isLeft ? floatValue - crosshairAlphaDiff : floatValue + crosshairAlphaDiff, 1.0f );
Cvar_SetValue( "vr_crosshair_alpha", floatValue );
break;
case VR_OPTION_WORLD_SCALE:
floatValue = vr_world_scale.value;
floatValue = CLAMP(0.0f, isLeft ? floatValue - crosshairAlphaDiff : floatValue + crosshairAlphaDiff, 2.0f);
Cvar_SetValue("vr_world_scale", floatValue);
break;
}

#undef _maxarray
Expand Down Expand Up @@ -295,6 +306,10 @@ static void VR_MenuDraw (void)
M_Print( 16, y, " Crosshair Alpha" );
VR_MenuPrintOptionValue( 220, y, i );
break;
case VR_OPTION_WORLD_SCALE:
M_Print(16, y, " World Scale");
VR_MenuPrintOptionValue(220, y, i);
break;

default: break;
}
Expand Down
1 change: 1 addition & 0 deletions Quake/vr_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum _vr_menu_options_t
VR_OPTION_CROSSHAIR_DEPTH,
VR_OPTION_CROSSHAIR_SIZE,
VR_OPTION_CROSSHAIR_ALPHA,
VR_OPTION_WORLD_SCALE,

VR_OPTION_MAX
} vr_menu_options_t;
Expand Down

0 comments on commit 5660604

Please sign in to comment.