cl_dll/view.cpp
// Get the origin of the Observer based around the target's position and angles
Get the origin of the Observer based around the target's position and angles
Get the origin of the Observer based around the target ' s position and angles
void V_GetChaseOrigin(float* angles, float* origin, float distance, float* returnvec)
{
	Vector vecEnd;
	Vector forward;
	Vector vecStart;
	pmtrace_t* trace;
	int maxLoops = 8;
	int ignoreent = -1; 
	cl_entity_t* ent = NULL;
	AngleVectors(angles, forward, NULL, NULL);
	VectorScale(forward, -1, forward);
	VectorCopy(origin, vecStart);
	VectorMA(vecStart, distance, forward, vecEnd);
	while (maxLoops > 0)
	{
		trace = gEngfuncs.PM_TraceLine(vecStart, vecEnd, PM_TRACELINE_PHYSENTSONLY, 2, ignoreent);
		if (trace->ent <= 0)
			break; 
		ent = gEngfuncs.GetEntityByIndex(PM_GetPhysEntInfo(trace->ent));
		if (ent == NULL)
			break;
		if (ent->curstate.solid == SOLID_BSP && 0 == ent->player)
			break;
		if (Distance(trace->endpos, vecEnd) < 1.0f)
		{
			break;
		}
		else
		{
			ignoreent = trace->ent; 
			VectorCopy(trace->endpos, vecStart);
		}
		maxLoops--;
	}
	VectorMA(trace->endpos, 4, trace->plane.normal, returnvec);
	v_lastDistance = Distance(trace->endpos, origin); 
}
void V_GetChaseOrigin ( float * angles , float * origin , float distance , float * returnvec ) { Vector vecEnd ; Vector forward ; Vector vecStart ; pmtrace_t * trace ; int maxLoops = 8 ; int ignoreent = -1 ; cl_entity_t * ent = NULL ; AngleVectors ( angles , forward , NULL , NULL ) ; VectorScale ( forward , -1 , forward ) ; VectorCopy ( origin , vecStart ) ; VectorMA ( vecStart , distance , forward , vecEnd ) ; while ( maxLoops > 0 ) { trace = gEngfuncs . PM_TraceLine ( vecStart , vecEnd , PM_TRACELINE_PHYSENTSONLY , 2 , ignoreent ) ; if ( trace -> ent <= 0 ) break ; ent = gEngfuncs . GetEntityByIndex ( PM_GetPhysEntInfo ( trace -> ent ) ) ; if ( ent == NULL ) break ; if ( ent -> curstate . solid == SOLID_BSP && 0 == ent -> player ) break ; if ( Distance ( trace -> endpos , vecEnd ) < 1.0f ) { break ; } else { ignoreent = trace -> ent ; VectorCopy ( trace -> endpos , vecStart ) ; } maxLoops -- ; } VectorMA ( trace -> endpos , 4 , trace -> plane . normal , returnvec ) ; v_lastDistance = Distance ( trace -> endpos , origin ) ; }
Get the origin of the Observer based around the target's position and angles
Get the origin of the Observer based around the target ' s position and angles
// first, ignore no entity // Trace back from the target using the player's view angles // WARNING! trace->ent is is the number in physent list not the normal entity number // we hit the world or nothing, stop trace // hit non-player solid BSP , stop here // if close enought to end pos, stop, otherwise continue trace // ignore last hit entity /*	if ( ent )
	{
		gEngfuncs.Con_Printf("Trace loops %i , entity %i, model %s, solid %i\n",(8-maxLoops),ent->curstate.number, ent->model->name , ent->curstate.solid ); 
	} */ // real distance without offset