Пользователь
-
Автор темы
- #1
Gamesense trace to exit.
C++:
bool penetration::trace_to_exit(CGameTrace* enter_trace, vec3_t start_pos, float distance_factor, float max_distance, CTraceFilter* filter, CGameTrace* exit_trace)
{
float distance = 0.0f;
int contents = 0;
int first_contents = 0;
vec3_t end;
vec3_t start;
if (max_distance <= 0.0f)
return false;
while (max_distance > distance)
{
distance += distance_factor;
end = start_pos + enter_trace->end * new_distance;
start = end - enter_trace->end * 4.0f;
contents = get_point_contents(end, MASK_SHOT);
if (!first_contents)
first_contents = contents;
if (contents & MASK_SHOT_HULL && (!(contents & CONTENTS_HITBOX) || first_contents == contents))
continue;
g_engine_trace->TraceRay(ray_t(end, start), MASK_SHOT, filter, exit_trace);
if (exit_trace->startsolid && (exit_trace->surface.flags & SURF_HITBOX))
{
g_engine_trace->TraceRay(vec3_t(end, enter_trace->end), MASK_SHOT_HULL, filter, exit_trace);
if ((exit_trace->fraction < 1.0 || exit_trace->allsolid) && !exit_trace->startsolid)
return true;
}
else if (exit_trace->fraction >= 1.0 && !exit_trace->allsolid || exit_trace->startsolid)
{
if (enter_trace->entity && !hit_world_entity(enter_trace->entity) && IsBreakableEntity(enter_trace->entity))
{
*exit_trace = *enter_trace;
exit_trace->end = start_pos + enter_trace->end;
return true;
}
}
else
{
bool no_draw = enter_trace->surface.flags & SURF_NODRAW;
if (exit_trace->surface.flags >= 0)
goto LABEL_25;
if (IsBreakableEntity(exit_trace->entity) && IsBreakableEntity(enter_trace->entity))
return true;
if (no_draw)
{
LABEL_25:
if (exit_trace->plane.normal.dot(start_pos) <= 1.0)
return true;
}
}
}
return false;
}
Последнее редактирование: