Skip to content

Commit

Permalink
cgame - game: Make the traceable crosshair move smoothly like BFP van…
Browse files Browse the repository at this point in the history
…illa does and apply some adjustments to the crosshair
  • Loading branch information
LegendaryGuard committed Sep 10, 2023
1 parent 589be4a commit 1ecb533
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions source/cgame/cg_draw.c
Expand Up @@ -1702,6 +1702,7 @@ static void CG_DrawCrosshair(void) {
trace_t trace;
playerState_t *ps;
vec3_t muzzle, forward, up, start, end;
static float lastPositionY = 240.0f; // BFP - Last Y position for traceable crosshair to move smoothly like BFP vanilla does

ps = &cg.predictedPlayerState;

Expand Down Expand Up @@ -1742,7 +1743,6 @@ static void CG_DrawCrosshair(void) {

x = cg_crosshairX.integer;
y = cg_crosshairY.integer;
CG_AdjustFrom640( &x, &y, &w, &h );

ca = cg_drawCrosshair.integer;
if (ca < 0) {
Expand All @@ -1751,7 +1751,6 @@ static void CG_DrawCrosshair(void) {
hShader = cgs.media.crosshairShader[ ca % NUM_CROSSHAIRS ];

if ( cg_thirdPerson.integer >= 1 && cg_stableCrosshair.integer <= 0 ) { // BFP - Third person traceable crosshair
w = h = cg_crosshairSize.value; // set the same size, if this isn't set here, the size is changed
AngleVectors( ps->viewangles, forward, NULL, up );
VectorCopy( ps->origin, muzzle );
VectorMA( muzzle, ps->viewheight, up, muzzle );
Expand All @@ -1764,12 +1763,19 @@ static void CG_DrawCrosshair(void) {
}

CG_AdjustFrom640( &x, &y, &w, &h );

// BFP - Make the traceable crosshair move smoothly like BFP vanilla does
// LERP( <last (or initial) position>, <destination>, (float)(cg.frametime / 1000.00f) * <speed factor> );
y = LERP( lastPositionY, y, (float)(cg.frametime / 1000.00f) * 12.0f );

trap_R_DrawStretchPic( x - 0.5f * w, // 492.799987
y - 0.5f * h,
w, h, 0, 0, 1, 1, hShader );
lastPositionY = y; // last Y position where it was "lerped"
} else { // Q3 default crosshair position
// x: 492.799987
// y: 364.799987
CG_AdjustFrom640( &x, &y, &w, &h );
trap_R_DrawStretchPic( x + cg.refdef.x + 0.5 * (cg.refdef.width - w),
y + cg.refdef.y + 0.5 * (cg.refdef.height - h),
w, h, 0, 0, 1, 1, hShader );
Expand Down
5 changes: 4 additions & 1 deletion source/game/q_shared.h
Expand Up @@ -1434,5 +1434,8 @@ typedef enum _flag_status {
#define CDKEY_LEN 16
#define CDCHKSUM_LEN 2


// BFP - LERP function for crosshair or any other feature, LERP is an engine side function. So, this macro conditional will avoid showing a warning/error in the compiler if someone copies this piece of source code
#ifndef LERP
#define LERP( a, b, w ) ( ( a ) * ( 1.0f - ( w ) ) + ( b ) * ( w ) )
#endif
#endif // __Q_SHARED_H

0 comments on commit 1ecb533

Please sign in to comment.