how to tell texturename of where Trace Vector end Created 6 years ago2018-09-01 21:12:40 UTC by hfc hfc

Created 6 years ago2018-09-01 21:12:40 UTC by hfc hfc

Posted 6 years ago2018-09-01 21:12:40 UTC Post #340764
when coding HL1, how to tell a brushes textures name from bullet trace?

i mean how to tell texture name using only "pTrace->endpos" argument

because i want to sky brushes dont make bullet hit sparks/debris.
void EV_HLDM_GunshotDecalTrace( pmtrace_t *pTrace, char *decalName )
{
int iRand;
physent_t *pe;
gEngfuncs.pEfxAPI->R_BulletImpactParticles( pTrace->endpos );
iRand = gEngfuncs.pfnRandomLong(0,0x7FFF);
if ( iRand < (0x7fff/2) )// not every bullet makes a sound.
{
	switch( iRand % 5)
	{
	case 0:	gEngfuncs.pEventAPI->EV_PlaySound( -1, pTrace->endpos, 0, "weapons/ric1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM ); break;
	case 1:	gEngfuncs.pEventAPI->EV_PlaySound( -1, pTrace->endpos, 0, "weapons/ric2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM ); break;
	case 2:	gEngfuncs.pEventAPI->EV_PlaySound( -1, pTrace->endpos, 0, "weapons/ric3.wav", 1.0, ATTN_NORM, 0, PITCH_NORM ); break;
	case 3:	gEngfuncs.pEventAPI->EV_PlaySound( -1, pTrace->endpos, 0, "weapons/ric4.wav", 1.0, ATTN_NORM, 0, PITCH_NORM ); break;
	case 4:	gEngfuncs.pEventAPI->EV_PlaySound( -1, pTrace->endpos, 0, "weapons/ric5.wav", 1.0, ATTN_NORM, 0, PITCH_NORM ); break;}
}
pe = gEngfuncs.pEventAPI->EV_GetPhysent( pTrace->ent );
// Only decal brush models such as the world etc.
if (  decalName && decalName[0] && pe && ( pe->solid == SOLID_BSP || pe->movetype == MOVETYPE_PUSHSTEP ) )
{
	if ( CVAR_GET_FLOAT( "r_decals" ) )
	{
		gEngfuncs.pEfxAPI->R_DecalShoot(
			gEngfuncs.pEfxAPI->Draw_DecalIndex( gEngfuncs.pEfxAPI->Draw_DecalIndexFromName( decalName ) ),
			gEngfuncs.pEventAPI->EV_IndexFromTrace( pTrace ), 0, pTrace->endpos, 0 );
	}
}
}
Posted 6 years ago2018-09-01 22:02:22 UTC Post #340765
Use gEngfuncs.pEventAPI->EV_TraceTexture to get the name. This function will do a trace and returns the name of the first brush texture it hits, or null if it didn't hit anything or if it hit something other than a brush.
Posted 6 years ago2018-09-02 13:39:38 UTC Post #340766
i know i have already found example of ( *EV_TraceTexture ) ( int ground, float *vstart, float *vend )

but in my function below there is only 1 argument, pTrace->endpos argument.

how to add vecsrc argument in void EV_HLDM_GunshotDecalTrace( pmtrace_t *pTrace, char *decalName )

and below is the pntrace_t structure
struct pmtrace_s
{
qboolean	allsolid;	      // if true, plane is not valid
qboolean	startsolid;	      // if true, the initial point was in a solid area
qboolean	inopen, inwater;  // End point is in empty space or in water
float		fraction;		  // time completed, 1.0 = didn't hit anything
vec3_t		endpos;			  // final position
pmplane_t	plane;		      // surface normal at impact
int			ent;			  // entity at impact
vec3_t      deltavelocity;    // Change in player's velocity caused by impact.
							  // Only run on server.
int         hitgroup;
};
Posted 6 years ago2018-09-02 14:22:19 UTC Post #340767
Unfortunately there is no way to directly access the engine functions for getting surfaces from positions in the world, so you'll have to fake it by creating a trace that uses the original start and end positions. Since pmtrace_t doesn't have that, you'll have to pass it into the function yourself.

EV_HLDM_GunshotDecalTrace gets called by EV_HLDM_DecalGunshot, which is called by the code that performs the trace. Modify both to take the start position as a parameter, and pass it in.
Posted 6 years ago2018-09-02 14:43:26 UTC Post #340768
OK. Thank you.
You must be logged in to post a response.