219 lines
4.5 KiB
C++
Raw Normal View History

2016-08-28 00:39:01 +05:00
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
#include "triangleapi.h"
#include "pm_shared.h"
#include "pm_defs.h"
#include "pmtrace.h"
2020-04-08 12:17:35 +05:00
extern bool bDrawScope;
2016-08-28 00:39:01 +05:00
extern vec3_t v_origin; // last view origin
extern vec3_t v_angles; // last view angle
extern vec3_t v_cl_angles; // last client/mouse angle
extern vec3_t v_sim_org; // last sim origin
2020-04-08 12:17:35 +05:00
extern cvar_t *adjust_fov;
2016-08-28 00:39:01 +05:00
2021-04-04 06:11:57 +05:00
int CHudScope::Init( void )
{
gHUD.AddHudElem( this );
return 1;
}
int CHudScope::VidInit( void )
{
m_hSprite = 0;
return 1;
}
int CHudScope::DrawScope()
2016-08-28 00:39:01 +05:00
{
2020-04-08 12:17:35 +05:00
vec3_t angles, forward, right, up;
vec3_t dir, delta, vert;
int frame;
float flDist, x, y;
pmtrace_t *trace;
if( !bDrawScope )
2016-08-28 00:39:01 +05:00
return 1;
2020-04-08 12:17:35 +05:00
if( !m_hSprite )
{
m_hSprite = SPR_Load( "sprites/scopeborder.spr" );
m_hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer( m_hSprite );
}
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
gEngfuncs.GetViewAngles( angles );
AngleVectors( angles, forward, right, up );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
VectorMA( v_origin, 8192.0f, forward, dir );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
trace = gEngfuncs.PM_TraceLine( v_origin, dir, PM_TRACELINE_PHYSENTSONLY, 2, -1 );
VectorSubtract( trace->endpos, v_origin, delta );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
flDist = Length( delta );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
if( flDist >= 118.0f )
2021-04-04 06:11:57 +05:00
sprintf( m_szDist, "%.2f m", (double)(flDist / 39.37f) );
2020-04-08 12:17:35 +05:00
else
strcpy( m_szDist, "-.-- m" );
2016-08-28 00:39:01 +05:00
2021-04-04 06:11:57 +05:00
x = tan( gHUD.m_iFOV / 114.6f ) * 11.0f;
2021-04-04 07:49:48 +05:00
y = x / 255.0f;
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture ); //additive
gEngfuncs.pTriAPI->CullFace( TRI_NONE );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
if( adjust_fov && adjust_fov->value )
VectorMA( v_origin, 8.0f, forward, dir );
else
VectorMA( v_origin, 10.0f, forward, dir );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
frame = 0;
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
while( true )
2016-08-28 00:39:01 +05:00
{
2020-04-08 12:17:35 +05:00
if( !gEngfuncs.pTriAPI->SpriteTexture( m_hSpriteModel, frame ) )
break;
gEngfuncs.pTriAPI->Color4f( 1.0f, 1.0f, 1.0f, 1.0f );
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
switch( frame )
{
case 0:
VectorMA( dir, -x, right, vert );
break;
case 1:
VectorCopy( dir, vert );
break;
case 2:
VectorMA( dir, -x, up, vert );
VectorMA( vert, -x, right, vert );
break;
case 3:
VectorMA( dir, -x, up, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
switch( frame )
{
case 0:
VectorMA( dir, x, up, vert );
VectorMA( vert, -x, right, vert );
break;
case 1:
VectorMA( dir, x, up, vert );
break;
case 2:
VectorMA( dir, y, up, vert );
VectorMA( vert, -x, right, vert );
break;
case 3:
VectorCopy( dir, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
switch( frame )
{
case 0:
VectorMA( dir, x, up, vert );
break;
case 1:
VectorMA( dir, x, up, vert );
VectorMA( vert, x, right, vert );
break;
case 2:
VectorCopy( dir, vert );
break;
case 3:
VectorMA( dir, y, up, vert );
VectorMA( vert, x, right, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
switch( frame )
{
case 0:
VectorCopy( dir, vert );
break;
case 1:
VectorMA( dir, x, right, vert );
break;
case 2:
VectorMA( dir, -x, up, vert );
break;
case 3:
VectorMA( dir, -x, up, vert );
VectorMA( vert, x, right, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->End();
if( ++frame >= 4 )
{
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
cl_entity_t *viewmodel = gEngfuncs.GetViewModel();
viewmodel->curstate.rendermode = kRenderGlow;
viewmodel->curstate.renderamt = 5;
break;
}
2016-08-28 00:39:01 +05:00
}
2020-04-08 12:17:35 +05:00
return 1;
}
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
int CHudScope::DrawText()
{
int w, h;
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
if( !bDrawScope )
return 1;
GetConsoleStringSize( m_szDist, &w, &h );
2016-08-28 00:39:01 +05:00
2020-04-08 12:17:35 +05:00
DrawSetTextColor( 1.0f, 0.25f, 0.25f );
DrawConsoleString( ScreenWidth * 0.82f - w, ScreenHeight * 0.49f - h, m_szDist );
2016-08-28 00:39:01 +05:00
return 1;
}