From 2825144e9bd49882327a2ababda07451453b1c88 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 1 Oct 2019 23:02:11 +0100 Subject: [PATCH] Various improvements - 6DoF weapons --- .../Android/jni/Quake2VR/Q2VR_SurfaceView.c | 1 + Projects/Android/jni/Quake2VR/VrCvars.h | 1 + Projects/Android/jni/Quake2VR/VrInputRight.c | 27 ++++++------- .../Android/jni/quake2/src/client/cl_ents.c | 26 ++++++++----- Projects/Android/jni/quake2/src/client/menu.c | 6 +-- .../Android/jni/quake2/src/game/p_client.c | 15 +++++--- Projects/Android/jni/quake2/src/game/p_view.c | 22 ----------- .../Android/jni/quake2/src/game/p_weapon.c | 4 +- .../Android/jni/quake2/src/game/q_shared.c | 1 + .../Android/jni/quake2/src/ref_gl/gl_mesh.c | 38 ++++++++++++++++--- .../Android/jni/quake2/src/ref_gl/gl_rmain.c | 2 +- assets/autoexec.cfg | 1 - assets/commandline.txt | 2 +- assets/config.cfg | 1 - 14 files changed, 78 insertions(+), 69 deletions(-) delete mode 100644 assets/autoexec.cfg diff --git a/Projects/Android/jni/Quake2VR/Q2VR_SurfaceView.c b/Projects/Android/jni/Quake2VR/Q2VR_SurfaceView.c index 0954600..6f92208 100644 --- a/Projects/Android/jni/Quake2VR/Q2VR_SurfaceView.c +++ b/Projects/Android/jni/Quake2VR/Q2VR_SurfaceView.c @@ -1327,6 +1327,7 @@ void VR_Init() vr_height_adjust = Cvar_Get( "vr_height_adjust", "0.0", CVAR_ARCHIVE); vr_flashlight_model = Cvar_Get( "vr_flashlight_model", "1", CVAR_ARCHIVE); vr_mirror_weapons = Cvar_Get( "vr_mirror_weapons", "0", CVAR_ARCHIVE); + vr_weaponscale = Cvar_Get( "vr_weaponscale", "0.4", CVAR_ARCHIVE); //The Engine (which is a derivative of Quake) uses a very specific unit size: //Wolfenstein 3D, DOOM and QUAKE use the same coordinate/unit system: diff --git a/Projects/Android/jni/Quake2VR/VrCvars.h b/Projects/Android/jni/Quake2VR/VrCvars.h index 9d55efe..62f0f89 100644 --- a/Projects/Android/jni/Quake2VR/VrCvars.h +++ b/Projects/Android/jni/Quake2VR/VrCvars.h @@ -13,3 +13,4 @@ cvar_t *vr_height_adjust; cvar_t *vr_flashlight_model; cvar_t *vr_mirror_weapons; cvar_t *vr_worldscale; +cvar_t *vr_weaponscale; diff --git a/Projects/Android/jni/Quake2VR/VrInputRight.c b/Projects/Android/jni/Quake2VR/VrInputRight.c index d0fc8e3..1d70175 100644 --- a/Projects/Android/jni/Quake2VR/VrInputRight.c +++ b/Projects/Android/jni/Quake2VR/VrInputRight.c @@ -106,7 +106,7 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) { vec2_t v; - rotateAboutOrigin(weaponoffset[0], weaponoffset[2], -(cl.viewangles[YAW] - hmdorientation[YAW]), v); + rotateAboutOrigin(-weaponoffset[0], weaponoffset[2], (cl.refdef.viewangles[YAW] - hmdorientation[YAW]), v); weaponoffset[0] = v[0]; weaponoffset[2] = v[1]; @@ -123,7 +123,7 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) { vec2_t v; - rotateAboutOrigin(weaponvelocity[0], weaponvelocity[2], -cl.viewangles[YAW], v); + rotateAboutOrigin(-weaponvelocity[0], weaponvelocity[2], (cl.refdef.viewangles[YAW] - hmdorientation[YAW]), v); weaponvelocity[0] = v[0]; weaponvelocity[2] = v[1]; @@ -137,6 +137,8 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) //Set gun angles - We need to calculate all those we might need (including adjustments) for the client to then take its pick const ovrQuatf quatRemote = rightRemoteTracking_new.HeadPose.Pose.Orientation; QuatToYawPitchRoll(quatRemote, vr_weapon_pitchadjust->value, weaponangles); + weaponangles[YAW] += (cl.refdef.viewangles[YAW] - hmdorientation[YAW]); + weaponangles[ROLL] *= -1.0f; if (vr_weapon_stabilised->value && @@ -149,13 +151,9 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) float zxDist = length(x, z); if (zxDist != 0.0f && z != 0.0f) { - VectorSet(weaponangles, degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ROLL]); + VectorSet(weaponangles, -degrees(atanf(y / zxDist)), (cl.refdef.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ROLL]); } } - else - { - weaponangles[YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]); - } //Use (Action) if ((rightTrackedRemoteState_new.Buttons & ovrButton_Joystick) != @@ -199,16 +197,16 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) flashlightoffset[2] = leftRemoteTracking_new.HeadPose.Pose.Position.z - hmdPosition[2]; vec2_t v; - rotateAboutOrigin(flashlightoffset[0], flashlightoffset[2], -(cl.viewangles[YAW] - hmdorientation[YAW]), v); + rotateAboutOrigin(-flashlightoffset[0], flashlightoffset[2], (cl.refdef.viewangles[YAW] - hmdorientation[YAW]), v); flashlightoffset[0] = v[0]; flashlightoffset[2] = v[1]; QuatToYawPitchRoll(leftRemoteTracking_new.HeadPose.Pose.Orientation, 15.0f, flashlightangles); - flashlightangles[YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]); + flashlightangles[YAW] += (cl.refdef.viewangles[YAW] - hmdorientation[YAW]); if (vr_walkdirection->value == 0) { - controllerYawHeading = -cl.viewangles[YAW] + flashlightangles[YAW]; + controllerYawHeading = -cl.refdef.viewangles[YAW] + flashlightangles[YAW]; } else { @@ -230,9 +228,9 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) vec2_t v; rotateAboutOrigin(-positionDeltaThisFrame[0] * multiplier, - positionDeltaThisFrame[2] * multiplier, -hmdorientation[YAW], v); - positional_movementSideways = v[0]; - positional_movementForward = v[1]; + positionDeltaThisFrame[2] * multiplier, (cl.refdef.viewangles[YAW] - hmdorientation[YAW]), v); + //positional_movementSideways = v[0]; + //positional_movementForward = v[1]; ALOGV(" positional_movementSideways: %f, positional_movementForward: %f", positional_movementSideways, @@ -324,9 +322,6 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime ) remote_movementSideways = v[0]; remote_movementForward = v[1]; -// remote_movementForward = cosf(radians(flashlightangles[PITCH])) * v[1]; -// remote_movementUp = sinf(radians(flashlightangles[PITCH])) * v[1]; - ALOGV(" remote_movementSideways: %f, remote_movementForward: %f", remote_movementSideways, remote_movementForward); diff --git a/Projects/Android/jni/quake2/src/client/cl_ents.c b/Projects/Android/jni/quake2/src/client/cl_ents.c index 3e499c2..04b3216 100644 --- a/Projects/Android/jni/quake2/src/client/cl_ents.c +++ b/Projects/Android/jni/quake2/src/client/cl_ents.c @@ -1341,6 +1341,21 @@ void CL_AddPacketEntities (frame_t *frame) } +extern cvar_t *vr_worldscale; +extern vec3_t weaponangles; +extern vec3_t weaponoffset; + +void convertFromVRtoQ2(vec3_t in, vec3_t offset, vec3_t out); + +static void SetWeapon6DOF(vec3_t origin, vec3_t gunorigin, vec3_t gunangles) +{ + vec3_t offset; + vec3_t gunoffset; + VectorSet(offset, 0, 0, 0); + convertFromVRtoQ2(weaponoffset, offset, gunoffset); + VectorAdd(origin, gunoffset, gunorigin); + VectorCopy(weaponangles, gunangles); +} /* ============== @@ -1366,16 +1381,7 @@ void CL_AddViewWeapon (player_state_t *ps, player_state_t *ops) return; // set up gun position - for (i=0 ; i<3 ; i++) - { - gun.origin[i] = cl.refdef.vieworg[i] + ps->gunoffset[i]; - gun.angles[i] = ps->gunangles[i]; - -/* gun.origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i] - + cl.lerpfrac * (ps->gunoffset[i] - ops->gunoffset[i]); - gun.angles[i] = cl.refdef.viewangles[i] + LerpAngle (ops->gunangles[i], - ps->gunangles[i], cl.lerpfrac); -*/ } + SetWeapon6DOF(cl.refdef.vieworg, gun.origin, gun.angles); if (gun_frame) { diff --git a/Projects/Android/jni/quake2/src/client/menu.c b/Projects/Android/jni/quake2/src/client/menu.c index bbc63cd..322524f 100644 --- a/Projects/Android/jni/quake2/src/client/menu.c +++ b/Projects/Android/jni/quake2/src/client/menu.c @@ -3971,13 +3971,11 @@ const char *M_Quit_Key (int key) switch (key) { case K_ESCAPE: - case 'n': - case 'N': M_PopMenu (); break; - case 'Y': - case 'y': + case K_ENTER: + case K_SPACE: cls.key_dest = key_console; CL_Quit_f (); break; diff --git a/Projects/Android/jni/quake2/src/game/p_client.c b/Projects/Android/jni/quake2/src/game/p_client.c index ede6a7b..c2c29d4 100644 --- a/Projects/Android/jni/quake2/src/game/p_client.c +++ b/Projects/Android/jni/quake2/src/game/p_client.c @@ -1577,12 +1577,13 @@ extern vec3_t weaponoffset; extern cvar_t *vr_worldscale; -static void convertFromVRtoQ2(vec3_t in, vec3_t out) +void convertFromVRtoQ2(vec3_t in, vec3_t offset, vec3_t out) { vec3_t vrSpace; VectorSet(vrSpace, -in[2], in[0], in[1]); - VectorScale(vrSpace, vr_worldscale->value, out); - out[2] += 16; + vec3_t temp; + VectorScale(vrSpace, vr_worldscale->value, temp); + VectorAdd(temp, offset, out); } static void SV_SetWeapon_Client6DOF(edict_t *ent) @@ -1592,10 +1593,12 @@ static void SV_SetWeapon_Client6DOF(edict_t *ent) VectorCopy(ent->client->v_angle, angles_b); vec3_t origin; - vec3_t offset; - convertFromVRtoQ2(weaponoffset, offset); + vec3_t weaponoffsetQ2; + vec3_t offset; + VectorSet(offset, 0, 0, 8); + convertFromVRtoQ2(weaponoffset, offset, weaponoffsetQ2); VectorCopy(ent->s.origin, origin); - VectorAdd(offset, origin, ent->s.origin); + VectorAdd(weaponoffsetQ2, origin, ent->s.origin); VectorCopy(weaponangles, ent->client->v_angle); // use adjusted angles } diff --git a/Projects/Android/jni/quake2/src/game/p_view.c b/Projects/Android/jni/quake2/src/game/p_view.c index 17ebcb8..59083d6 100644 --- a/Projects/Android/jni/quake2/src/game/p_view.c +++ b/Projects/Android/jni/quake2/src/game/p_view.c @@ -338,26 +338,6 @@ void SV_CalcViewOffset (edict_t *ent) } -extern cvar_t *vr_worldscale; -extern vec3_t weaponangles; -extern vec3_t weaponoffset; - -static void convertFromVRtoQ2(vec3_t in, vec3_t out) -{ - vec3_t vrSpace; - VectorSet(vrSpace, -in[2], in[0], in[1]); - VectorScale(vrSpace, vr_worldscale->value, out); - out[2] += 16; -} - -static void SetWeapon_Client6DOF(edict_t *ent) -{ - vec3_t origin; - vec3_t offset; - convertFromVRtoQ2(weaponoffset, ent->client->ps.gunoffset); - VectorCopy(weaponangles, ent->client->ps.gunangles); -} - /* ============== SV_CalcGunOffset @@ -408,8 +388,6 @@ void SV_CalcGunOffset (edict_t *ent) ent->client->ps.gunoffset[i] += up[i]* (-gun_z->value); } */ - - SetWeapon_Client6DOF(ent); } diff --git a/Projects/Android/jni/quake2/src/game/p_weapon.c b/Projects/Android/jni/quake2/src/game/p_weapon.c index 2fd220f..a45e954 100644 --- a/Projects/Android/jni/quake2/src/game/p_weapon.c +++ b/Projects/Android/jni/quake2/src/game/p_weapon.c @@ -490,7 +490,7 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, ent->client->ps.gunframe = FRAME_IDLE_FIRST; return; } - +/* if (pause_frames) { for (n = 0; pause_frames[n]; n++) @@ -502,7 +502,7 @@ void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, } } } - +*/ ent->client->ps.gunframe++; return; } diff --git a/Projects/Android/jni/quake2/src/game/q_shared.c b/Projects/Android/jni/quake2/src/game/q_shared.c index c741a29..0982cfe 100644 --- a/Projects/Android/jni/quake2/src/game/q_shared.c +++ b/Projects/Android/jni/quake2/src/game/q_shared.c @@ -29,6 +29,7 @@ vec3_t vec3_origin = {0,0,0}; #pragma optimize( "", off ) #endif + void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees ) { float m[3][3]; diff --git a/Projects/Android/jni/quake2/src/ref_gl/gl_mesh.c b/Projects/Android/jni/quake2/src/ref_gl/gl_mesh.c index 67c0639..2c3df4a 100644 --- a/Projects/Android/jni/quake2/src/ref_gl/gl_mesh.c +++ b/Projects/Android/jni/quake2/src/ref_gl/gl_mesh.c @@ -521,6 +521,8 @@ R_DrawAliasModel ================= */ +extern cvar_t *vr_weaponscale; +void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ); void R_DrawAliasModel (entity_t *e) { int i; @@ -740,7 +742,7 @@ void R_DrawAliasModel (entity_t *e) if (currententity->flags & RF_DEPTHHACK) // hack the depth range to prevent view model from poking into walls qglDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin)); - if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) ) +/* if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) ) { extern void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ); @@ -752,8 +754,30 @@ void R_DrawAliasModel (entity_t *e) qglMatrixMode( GL_MODELVIEW ); qglCullFace( GL_BACK ); + }*/ + + + if ( currententity->flags & RF_WEAPONMODEL ) + { + qglMatrixMode( GL_PROJECTION ); + qglPushMatrix(); + qglLoadIdentity(); + MYgluPerspective( r_newrefdef.fov_y, ( float ) r_newrefdef.width / r_newrefdef.height, 0.1, 8192); + + if ( r_lefthand->value == 1.0F ) { + qglScalef(-vr_weaponscale->value, vr_weaponscale->value, vr_weaponscale->value); + } else { + qglScalef(vr_weaponscale->value, vr_weaponscale->value, vr_weaponscale->value); + } + + qglMatrixMode( GL_MODELVIEW ); + + if ( r_lefthand->value == 1.0F ) { + qglCullFace( GL_BACK ); + } } + qglPushMatrix (); e->angles[PITCH] = -e->angles[PITCH]; // sigh. R_RotateForEntity (e); @@ -830,12 +854,16 @@ void R_DrawAliasModel (entity_t *e) qglEnable( GL_CULL_FACE ); #endif - if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) ) + if ( ( currententity->flags & RF_WEAPONMODEL ) ) { - qglMatrixMode( GL_PROJECTION ); + qglMatrixMode( GL_PROJECTION ); qglPopMatrix(); - qglMatrixMode( GL_MODELVIEW ); - qglCullFace( GL_FRONT ); + + qglMatrixMode( GL_MODELVIEW ); + + if ( r_lefthand->value == 1.0F ) { + qglCullFace(GL_FRONT); + } } if ( currententity->flags & RF_TRANSLUCENT ) diff --git a/Projects/Android/jni/quake2/src/ref_gl/gl_rmain.c b/Projects/Android/jni/quake2/src/ref_gl/gl_rmain.c index 182ccc4..5833df7 100644 --- a/Projects/Android/jni/quake2/src/ref_gl/gl_rmain.c +++ b/Projects/Android/jni/quake2/src/ref_gl/gl_rmain.c @@ -781,7 +781,7 @@ void R_SetupGL (void) // yfov = 2*atan((float)r_newrefdef.height/r_newrefdef.width)*180/M_PI; qglMatrixMode(GL_PROJECTION); qglLoadIdentity (); - MYgluPerspective (r_newrefdef.fov_y, screenaspect, 4, 8192); + MYgluPerspective (r_newrefdef.fov_y, screenaspect, 0.1, 8192); qglCullFace(GL_FRONT); diff --git a/assets/autoexec.cfg b/assets/autoexec.cfg deleted file mode 100644 index 47e60c1..0000000 --- a/assets/autoexec.cfg +++ /dev/null @@ -1 +0,0 @@ -map demo1 diff --git a/assets/commandline.txt b/assets/commandline.txt index 497a8c0..557fe51 100644 --- a/assets/commandline.txt +++ b/assets/commandline.txt @@ -1 +1 @@ -quake2 --supersampling 1.35 \ No newline at end of file +quake2 --supersampling 1.5 \ No newline at end of file diff --git a/assets/config.cfg b/assets/config.cfg index f05487b..5beed2d 100644 --- a/assets/config.cfg +++ b/assets/config.cfg @@ -1,7 +1,6 @@ // good config for Quake 2 on Android set cl_drawfps "1" -//set cl_maxfps "25" set gl_ext_multitexture "1" //set developer "1" /////////////////////// key bindings