E11 Blaster Rifle Scope

also a small change to allow proper rendering of the view when controlling an NPC that isn't a droid
This commit is contained in:
Simon 2022-11-16 21:12:28 +00:00
parent d450d55dc8
commit c372dd455b
13 changed files with 129 additions and 31 deletions

View file

@ -810,7 +810,7 @@ void updateHMDOrientation()
//Keep this for our records //Keep this for our records
VectorCopy(vr.hmdorientation, vr.hmdorientation_last); VectorCopy(vr.hmdorientation, vr.hmdorientation_last);
if (!vr.third_person){ if (!vr.third_person && !vr.remote_npc){
VectorCopy(vr.hmdorientation, vr.hmdorientation_first); VectorCopy(vr.hmdorientation, vr.hmdorientation_first);
} }
@ -874,7 +874,7 @@ void JKVR_GetMove(float *forward, float *side, float *pos_forward, float *pos_si
*pitch = vr.weaponangles[PITCH]; *pitch = vr.weaponangles[PITCH];
*roll = 0.0f; *roll = 0.0f;
} }
else if (vr.cgzoommode == 2) else if (vr.cgzoommode == 2 || vr.cgzoommode == 4)
{ {
*forward = 0.0f; *forward = 0.0f;
*pos_forward = 0.0f; *pos_forward = 0.0f;
@ -885,6 +885,16 @@ void JKVR_GetMove(float *forward, float *side, float *pos_forward, float *pos_si
*pitch = vr.weaponangles[PITCH]; *pitch = vr.weaponangles[PITCH];
*roll = vr.hmdorientation[ROLL]; *roll = vr.hmdorientation[ROLL];
} }
else if (vr.remote_npc) {
*forward = remote_movementForward;
*pos_forward = 0.0f;
*up = 0.0f;
*side = remote_movementSideways;
*pos_side = 0.0f;
*yaw = vr.hmdorientation[YAW] - vr.hmdorientation_first[YAW];
*pitch = vr.hmdorientation[PITCH];
*roll = 0.0f;
}
else if (!vr.third_person) { else if (!vr.third_person) {
*forward = remote_movementForward; *forward = remote_movementForward;
*pos_forward = positional_movementForward; *pos_forward = positional_movementForward;

View file

@ -5,8 +5,12 @@
typedef struct { typedef struct {
bool cin_camera; // cinematic camera taken over bool cin_camera; // cinematic camera taken over
bool misc_camera; // looking through a misc camera view entity bool misc_camera; // looking through a misc camera view entity
bool remote_turret; // controlling a remote turret bool remote_turret; // controlling a remote turret
bool remote_droid; // controlling a remote droid
bool remote_npc; // controlling a remote NPC (will also be true when controlling a droid)
bool using_screen_layer; bool using_screen_layer;
bool third_person; bool third_person;
float fov; float fov;

View file

@ -237,20 +237,21 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG
} }
//Should we trigger the disruptor scope? //Should we trigger the disruptor scope?
if (cl.frame.ps.weapon == WP_DISRUPTOR && if ((cl.frame.ps.weapon == WP_DISRUPTOR ||
cl.frame.ps.weapon == WP_BLASTER) &&
cl.frame.ps.stats[STAT_HEALTH] > 0) cl.frame.ps.stats[STAT_HEALTH] > 0)
{ {
if (vr.weapon_stabilised && if (vr.weapon_stabilised &&
VectorLength(vr.weaponoffset) < 0.24f && VectorLength(vr.weaponoffset) < 0.24f &&
vr.cgzoommode == 0) { vr.cgzoommode == 0) {
sendButtonAction("disruptorscope", true); sendButtonAction("enterscope", true);
} else if ((VectorLength(vr.weaponoffset) >= 0.24f || !vr.weapon_stabilised) && } else if ((VectorLength(vr.weaponoffset) >= 0.24f || !vr.weapon_stabilised) &&
vr.cgzoommode == 2) { (vr.cgzoommode == 2 || vr.cgzoommode == 4)) {
sendButtonActionSimple("exitzoom"); sendButtonActionSimple("exitscope");
} }
} }
if (vr.cgzoommode > 0) if (vr.cgzoommode > 0 && vr.cgzoommode < 4)
{ {
if (between(-0.2f, primaryJoystickX, 0.2f)) { if (between(-0.2f, primaryJoystickX, 0.2f)) {
if (cl.frame.ps.weapon == WP_DISRUPTOR) if (cl.frame.ps.weapon == WP_DISRUPTOR)
@ -399,7 +400,7 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG
-degrees(atan2f(x, -z)), 0); -degrees(atan2f(x, -z)), 0);
} }
} }
else if (vr.cgzoommode == 2) else if (vr.cgzoommode == 2 || vr.cgzoommode == 4)
{ {
float x = float x =
pOff->HeadPose.Pose.Position.x - vr.hmdposition[0]; pOff->HeadPose.Pose.Position.x - vr.hmdposition[0];
@ -724,7 +725,7 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG
(!vr.third_person && vr_turn_mode->integer == 1); (!vr.third_person && vr_turn_mode->integer == 1);
static int increaseSnap = true; static int increaseSnap = true;
if (!vr.item_selector) { if (!vr.item_selector && !vr.remote_npc) {
if (usingSnapTurn) { if (usingSnapTurn) {
if (primaryJoystickX > 0.7f) { if (primaryJoystickX > 0.7f) {
if (increaseSnap) { if (increaseSnap) {

View file

@ -606,7 +606,7 @@ typedef struct {
*/ */
#define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535) #define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535)
#define SHORT2ANGLE(x) ((x)*(360.0/65536)) #define SHORT2ANGLE(x) ((x)*(360.0f/65536))
#define SNAPFLAG_RATE_DELAYED 1 #define SNAPFLAG_RATE_DELAYED 1
#define SNAPFLAG_NOT_ACTIVE 2 // snapshot used during connection and for zombies #define SNAPFLAG_NOT_ACTIVE 2 // snapshot used during connection and for zombies

View file

@ -207,8 +207,8 @@ void CG_ItemSelectorSelect_f( void );
void CG_ItemSelectorNext_f( void ); void CG_ItemSelectorNext_f( void );
void CG_ItemSelectorPrev_f( void ); void CG_ItemSelectorPrev_f( void );
void CG_ToggleSaber_f( void ); void CG_ToggleSaber_f( void );
void CG_ExitZoom_f( void ); void CG_ExitScope_f( void );
void CG_DisruptorScope_f( void ); void CG_EnterScope_f( void );
/* This array MUST be sorted correctly by alphabetical name field */ /* This array MUST be sorted correctly by alphabetical name field */
static consoleCommand_t commands[] = { static consoleCommand_t commands[] = {
@ -251,8 +251,8 @@ static consoleCommand_t commands[] = {
{ "itemselectornext", CG_ItemSelectorNext_f }, { "itemselectornext", CG_ItemSelectorNext_f },
{ "itemselectorprev", CG_ItemSelectorPrev_f }, { "itemselectorprev", CG_ItemSelectorPrev_f },
{ "togglesaber", CG_ToggleSaber_f }, { "togglesaber", CG_ToggleSaber_f },
{ "exitzoom", CG_ExitZoom_f }, { "exitscope", CG_ExitScope_f },
{ "disruptorscope", CG_DisruptorScope_f }, { "enterscope", CG_EnterScope_f },
}; };
static const size_t numCommands = ARRAY_LEN( commands ); static const size_t numCommands = ARRAY_LEN( commands );

View file

@ -715,6 +715,47 @@ static qboolean CG_DrawCustomHealthHud( centity_t *cent )
return qtrue; return qtrue;
} }
/*
==============
CG_DrawWeapReticle
==============
*/
static void CG_DrawWeapReticle( void )
{
vec4_t light_color = {0.7, 0.7, 0.7, 1};
vec4_t black = {0.0, 0.0, 0.0, 1};
float indent = 0.16;
float X_WIDTH=640;
float Y_HEIGHT=480;
float x = (X_WIDTH * indent), y = (Y_HEIGHT * indent), w = (X_WIDTH * (1-(2*indent))) / 2.0f, h = (Y_HEIGHT * (1-(2*indent))) / 2;
// sides
CG_FillRect( 0, 0, (X_WIDTH * indent), Y_HEIGHT, black );
CG_FillRect( X_WIDTH * (1 - indent), 0, (X_WIDTH * indent), Y_HEIGHT, black );
// top/bottom
CG_FillRect( X_WIDTH * indent, 0, X_WIDTH * (1-indent), Y_HEIGHT * indent, black );
CG_FillRect( X_WIDTH * indent, Y_HEIGHT * (1-indent), X_WIDTH * (1-indent), Y_HEIGHT * indent, black );
{
// center
if ( cgs.media.reticleShader ) {
cgi_R_DrawStretchPic( x, y, w, h, 0, 0, 1, 1, cgs.media.reticleShader ); // tl
cgi_R_DrawStretchPic( x + w, y, w, h, 1, 0, 0, 1, cgs.media.reticleShader ); // tr
cgi_R_DrawStretchPic( x, y + h, w, h, 0, 1, 1, 0, cgs.media.reticleShader ); // bl
cgi_R_DrawStretchPic( x + w, y + h, w, h, 1, 1, 0, 0, cgs.media.reticleShader ); // br
}
// hairs
CG_FillRect( 84, 239, 177, 2, black ); // left
CG_FillRect( 320, 242, 1, 58, black ); // center top
CG_FillRect( 319, 300, 2, 178, black ); // center bot
CG_FillRect( 380, 239, 177, 2, black ); // right
}
}
//-------------------------------------- //--------------------------------------
static void CG_DrawBatteryCharge( void ) static void CG_DrawBatteryCharge( void )
{ {
@ -1838,7 +1879,7 @@ static void CG_DrawCrosshair3D(int type) // 0 - force, 1 - weapons
return; return;
} }
if ( cg.zoomMode > 0 && cg.zoomMode < 3 ) if ( cg.zoomMode )
{ {
//not while scoped //not while scoped
return; return;
@ -2490,7 +2531,7 @@ static qboolean CG_RenderingFromMiscCamera()
// don't render other 2d stuff // don't render other 2d stuff
return qtrue; return qtrue;
} }
if ( !Q_stricmp( "NPC", g_entities[cg.snap->ps.viewEntity].classname )) if (vr->remote_droid)
{ {
//Render as if we are looking through a camera //Render as if we are looking through a camera
CG_DrawPic( 0, 0, 640, 480, cgi_R_RegisterShader( "gfx/2d/workingCamera" )); CG_DrawPic( 0, 0, 640, 480, cgi_R_RegisterShader( "gfx/2d/workingCamera" ));
@ -2573,7 +2614,11 @@ static void CG_Draw2D( void )
CGCam_DrawWideScreen(); CGCam_DrawWideScreen();
} }
if (cg.zoomMode) if (cg.zoomMode == 4)
{
CG_DrawWeapReticle();
}
else if (cg.zoomMode != 0)
{ {
CG_DrawZoomBorders(); CG_DrawZoomBorders();
} }
@ -2806,16 +2851,27 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
CG_Error( "CG_DrawActive: Undefined stereoView" ); CG_Error( "CG_DrawActive: Undefined stereoView" );
} }
vr->remote_npc = !Q_stricmp( "NPC", g_entities[cg.snap->ps.viewEntity].classname );
vr->remote_droid = vr->remote_npc &&
( !Q_stricmp( "mouse", g_entities[cg.snap->ps.viewEntity].NPC_type) ||
!Q_stricmp( "r2d2", g_entities[cg.snap->ps.viewEntity].NPC_type) ||
!Q_stricmp( "r5d2", g_entities[cg.snap->ps.viewEntity].NPC_type));
vr->remote_turret = (!Q_stricmp( "misc_panel_turret", g_entities[cg.snap->ps.viewEntity].classname )); vr->remote_turret = (!Q_stricmp( "misc_panel_turret", g_entities[cg.snap->ps.viewEntity].classname ));
in_misccamera = ( !Q_stricmp( "misc_camera", g_entities[cg.snap->ps.viewEntity].classname )) in_misccamera = ( !Q_stricmp( "misc_camera", g_entities[cg.snap->ps.viewEntity].classname ))
|| ( !Q_stricmp( "NPC", g_entities[cg.snap->ps.viewEntity].classname ) || vr->remote_droid
|| vr->remote_turret); || vr->remote_turret;
bool emplaced_gun = ( cg_entities[cg.snap->ps.clientNum].currentState.eFlags & EF_LOCKED_TO_WEAPON ); bool emplaced_gun = ( cg_entities[cg.snap->ps.clientNum].currentState.eFlags & EF_LOCKED_TO_WEAPON );
cg.refdef.worldscale = cg_worldScale.value; cg.refdef.worldscale = cg_worldScale.value;
bool usingScope = (cg.zoomMode == 2 || cg.zoomMode == 4);
//Normal 1st person view angles
if (!in_camera && if (!in_camera &&
!in_misccamera && !in_misccamera &&
cg.zoomMode != 2 && !vr->remote_droid &&
!vr->remote_npc &&
!usingScope &&
!cg.renderingThirdPerson) !cg.renderingThirdPerson)
{ {
VectorCopy(vr->hmdorientation, cg.refdef.viewangles); VectorCopy(vr->hmdorientation, cg.refdef.viewangles);
@ -2824,7 +2880,17 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis); AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis);
} }
if (cg.zoomMode == 2) //Controlling an NPC that isn't a droid
if (vr->remote_npc &&
!vr->remote_droid)
{
VectorCopy(vr->hmdorientation, cg.refdef.viewangles);
cg.refdef.viewangles[YAW] = cg.refdefViewAngles[YAW]; // Need to do this better.. results in laggy YAW, which is unpleasant
AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis);
}
//Sniper/E11 scope
if (usingScope)
{ {
cg.refdef.viewangles[ROLL] = vr->clientviewangles[ROLL]; cg.refdef.viewangles[ROLL] = vr->clientviewangles[ROLL];
cg.refdef.viewangles[PITCH] = vr->weaponangles[PITCH]; cg.refdef.viewangles[PITCH] = vr->weaponangles[PITCH];
@ -2833,6 +2899,7 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis); AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis);
} }
//Normal 3rd person view angles
if (!in_camera && if (!in_camera &&
!in_misccamera && !in_misccamera &&
cg.renderingThirdPerson) cg.renderingThirdPerson)
@ -2844,6 +2911,7 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis); AnglesToAxis(cg.refdef.viewangles, cg.refdef.viewaxis);
} }
//Immersive cinematic sequence 6DoF
if ((in_camera && vr->immersive_cinematics) || emplaced_gun || cg.renderingThirdPerson) if ((in_camera && vr->immersive_cinematics) || emplaced_gun || cg.renderingThirdPerson)
{ {
BG_ConvertFromVR(vr->hmdposition_offset, cg.refdef.vieworg, cg.refdef.vieworg); BG_ConvertFromVR(vr->hmdposition_offset, cg.refdef.vieworg, cg.refdef.vieworg);
@ -2854,7 +2922,7 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
// offset vieworg appropriately if we're doing stereo separation // offset vieworg appropriately if we're doing stereo separation
VectorCopy( cg.refdef.vieworg, baseOrg ); VectorCopy( cg.refdef.vieworg, baseOrg );
if ( separation != 0 && (!in_camera || vr->immersive_cinematics) && !in_misccamera && cg.zoomMode != 2 ) { if ( separation != 0 && (!in_camera || vr->immersive_cinematics) && !in_misccamera && !usingScope ) {
VectorMA( cg.refdef.vieworg, -separation, cg.refdef.viewaxis[1], cg.refdef.vieworg ); VectorMA( cg.refdef.vieworg, -separation, cg.refdef.viewaxis[1], cg.refdef.vieworg );
} }

View file

@ -1309,6 +1309,9 @@ static void CG_RegisterGraphics( void ) {
cgs.media.boltShader = cgi_R_RegisterShader( "gfx/misc/blueLine" ); cgs.media.boltShader = cgi_R_RegisterShader( "gfx/misc/blueLine" );
cgs.media.reticleShader = cgi_R_RegisterShader( "gfx/weapon/scope" );
// FIXME: do these conditionally // FIXME: do these conditionally
cgi_R_RegisterShader( "gfx/2d/workingCamera" ); cgi_R_RegisterShader( "gfx/2d/workingCamera" );
cgi_R_RegisterShader( "gfx/2d/brokenCamera" ); cgi_R_RegisterShader( "gfx/2d/brokenCamera" );

View file

@ -149,6 +149,8 @@ typedef struct {
qhandle_t shieldShader; qhandle_t shieldShader;
qhandle_t boltShader; qhandle_t boltShader;
qhandle_t reticleShader;
// Disruptor zoom graphics // Disruptor zoom graphics
qhandle_t disruptorMask; qhandle_t disruptorMask;
qhandle_t disruptorInsert; qhandle_t disruptorInsert;

View file

@ -1411,7 +1411,7 @@ static qboolean CG_CalcFov( void ) {
fov_x = vr ? vr->fov : cg_fov.value; fov_x = vr ? vr->fov : cg_fov.value;
// Disable zooming when in third person // Disable zooming when in third person
if ( cg.zoomMode && cg.zoomMode < 3 )//&& !cg.renderingThirdPerson ) // light amp goggles do none of the zoom silliness if (( cg.zoomMode && cg.zoomMode < 3 ) || cg.zoomMode == 4)//&& !cg.renderingThirdPerson ) // light amp goggles do none of the zoom silliness
{ {
if ( !cg.zoomLocked ) if ( !cg.zoomLocked )
{ {

View file

@ -2653,7 +2653,7 @@ void Cmd_UseInventory_f(gentity_t *ent);
extern float cg_zoomFov; //from cg_view.cpp extern float cg_zoomFov; //from cg_view.cpp
void CG_ExitZoom_f( ) void CG_ExitScope_f( )
{ {
if ( cg.zoomMode ) if ( cg.zoomMode )
{ {
@ -2665,15 +2665,22 @@ void CG_ExitZoom_f( )
} }
} }
void CG_DisruptorScope_f( ) void CG_EnterScope_f( )
{ {
if ( cg.zoomMode == 0 || cg.zoomMode == 3 ) if ( cg.zoomMode == 0 || cg.zoomMode == 3 )
{ {
G_SoundOnEnt( pm->gent, CHAN_AUTO, "sound/weapons/disruptor/zoomstart.wav" ); G_SoundOnEnt( pm->gent, CHAN_AUTO, "sound/weapons/disruptor/zoomstart.wav" );
// not already zooming, so do it now // not already zooming, so do it now
cg.zoomMode = 2; if (cg.weaponSelect == WP_DISRUPTOR) {
cg.zoomLocked = qfalse; cg.zoomMode = 2;
cg_zoomFov = 80.0f;//(cg.overrides.active&CG_OVERRIDE_FOV) ? cg.overrides.fov : cg_fov.value; cg_zoomFov = 80.0f;
cg.zoomLocked = qfalse;
} else {
//Our specially created E11 Blaster scope
cg.zoomMode = 4;
cg_zoomFov = 30.0f;
cg.zoomLocked = qtrue;
}
} }
} }

View file

@ -28,6 +28,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include "w_local.h" #include "w_local.h"
#include "g_functions.h" #include "g_functions.h"
#include "bg_local.h" #include "bg_local.h"
#include <JKVR/VrClientInfo.h>
//--------------- //---------------
// Blaster // Blaster
@ -137,9 +138,11 @@ void WP_FireBlaster( gentity_t *ent, qboolean alt_fire )
} }
else else
{ {
// add some slop to the main-fire direction if (vr->cgzoommode != 4) { // much more accurate if using the scope
angs[PITCH] += Q_flrand(-1.0f, 1.0f) * BLASTER_MAIN_SPREAD; // add some slop to the main-fire direction
angs[YAW] += Q_flrand(-1.0f, 1.0f) * BLASTER_MAIN_SPREAD; angs[PITCH] += Q_flrand(-1.0f, 1.0f) * BLASTER_MAIN_SPREAD;
angs[YAW] += Q_flrand(-1.0f, 1.0f) * BLASTER_MAIN_SPREAD;
}
} }
} }

Binary file not shown.

Binary file not shown.