From 7821de9e7e091cbe9a70837e8b5f133365f82c01 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 26 Jan 2023 22:03:41 +0000 Subject: [PATCH] Ensure controlling an NPC allows time for the view angles to be set correctly --- Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp | 3 +-- Projects/Android/jni/JKVR/VrClientInfo.h | 3 +++ Projects/Android/jni/OpenJK/codeJK2/cgame/cg_draw.cpp | 7 ++++++- Projects/Android/jni/OpenJK/codeJK2/cgame/cg_predict.cpp | 4 ++-- Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp | 5 ++++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp b/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp index b3bd307..ddf3e52 100644 --- a/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp +++ b/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp @@ -187,7 +187,6 @@ void VR_SetHMDPosition(float x, float y, float z ) //Reset snap turn too if in a cinematic vr.snapTurn = 0; } - vr.take_snap = false; } @@ -231,7 +230,7 @@ void VR_GetMove(float *forward, float *side, float *pos_forward, float *pos_side *up = 0.0f; *side = remote_movementSideways; *pos_side = 0.0f; - *yaw = vr.snapTurn + vr.hmdorientation[YAW] - vr.hmdorientation_first[YAW]; + *yaw = vr.hmdorientation[YAW] + vr.snapTurn; *pitch = vr.hmdorientation[PITCH]; *roll = 0.0f; } diff --git a/Projects/Android/jni/JKVR/VrClientInfo.h b/Projects/Android/jni/JKVR/VrClientInfo.h index 25ad80d..6452cb4 100644 --- a/Projects/Android/jni/JKVR/VrClientInfo.h +++ b/Projects/Android/jni/JKVR/VrClientInfo.h @@ -11,6 +11,9 @@ typedef struct { bool emplaced_gun; // controlling an emplaced gun bool remote_droid; // controlling a remote droid bool remote_npc; // controlling a remote NPC (will also be true when controlling a droid) + vec3_t remote_angles; // The view angles of the remote thing we are controlling + float remote_snapTurn; // how much turn has been applied to the yaw by joystick for a remote controlled entity + int remote_cooldown; bool using_screen_layer; bool third_person; diff --git a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_draw.cpp b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_draw.cpp index 2db7cca..7544881 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_draw.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_draw.cpp @@ -2980,8 +2980,13 @@ void CG_DrawActive( stereoFrame_t stereoView ) { if (vr->remote_npc && !vr->remote_droid) { + if (vr->remote_cooldown > cg.time) + { + VectorCopy(cg.refdefViewAngles, vr->remote_angles); + vr->take_snap = true; + } VectorCopy(vr->hmdorientation, cg.refdef.viewangles); - cg.refdef.viewangles[YAW] = cg.refdefViewAngles[YAW]; + cg.refdef.viewangles[YAW] = vr->remote_angles[YAW] + (vr->hmdorientation[YAW] - vr->hmdorientation_snap[YAW]) + (vr->snapTurn - vr->remote_snapTurn); AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis); } diff --git a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_predict.cpp b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_predict.cpp index a849076..8e33766 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_predict.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_predict.cpp @@ -205,9 +205,9 @@ void CG_SetClientViewAngles( vec3_t angles, qboolean overrideViewEnt ) {//don't clamp angles when looking through a viewEntity for( int i = 0; i < 3; i++ ) { - cg.predicted_player_state.viewangles[PITCH] = angles[i]; + cg.predicted_player_state.viewangles[i] = angles[i]; cg.predicted_player_state.delta_angles[i] = 0; - cg.snap->ps.viewangles[PITCH] = angles[i]; + cg.snap->ps.viewangles[i] = angles[i]; cg.snap->ps.delta_angles[i] = 0; g_entities[0].client->pers.cmd_angles[i] = ANGLE2SHORT(angles[i]); } diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp index ca179f6..a6e4ba7 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp @@ -217,7 +217,10 @@ void G_SetViewEntity( gentity_t *self, gentity_t *viewEntity ) { //vec3_t clear = {0,0,0}; CG_SetClientViewAngles( viewEntity->client->ps.viewangles, qtrue ); - vr->snapTurn = 0; + VectorCopy(viewEntity->client->ps.viewangles, vr->remote_angles); + vr->remote_snapTurn = vr->snapTurn; + vr->take_snap = true; + vr->remote_cooldown = cg.time + 250; //SetClientViewAngle( self, viewEntity->client->ps.viewangles ); //SetClientViewAngle( viewEntity, clear );