Update: add TraceHullShape

This commit is contained in:
SlynxCZ 2026-02-06 21:56:25 +04:00
parent 29e9201c0b
commit a8418ceabc
5 changed files with 140 additions and 25 deletions

View file

@ -82,7 +82,7 @@ namespace RayTracePlugin::RayTrace
std::optional<TraceResult> TraceShape(
const Vector& origin,
const QAngle& viewangles,
CBaseEntity* ignorePlayer,
CBaseEntity* ignoreEntity,
const TraceOptions* opts)
{
Vector forward;
@ -93,14 +93,18 @@ namespace RayTracePlugin::RayTrace
origin.z + forward.z * 8192.f
};
CTraceFilterEx filter = ignorePlayer ? CTraceFilterEx(ignorePlayer) : CTraceFilterEx();
CTraceFilterEx filter = ignoreEntity ? CTraceFilterEx(ignoreEntity) : CTraceFilterEx();
filter.m_nInteractsAs = 0;
filter.m_nInteractsWith = static_cast<uint64_t>(MASK_SHOT_PHYSICS);
filter.m_nInteractsExclude = 0;
if (opts)
{
if (opts->InteractsWith != 0)
if (opts->InteractsAs != 0)
filter.m_nInteractsAs = opts->InteractsAs;
if (opts->InteractsWith != static_cast<uint64_t>(MASK_SHOT_PHYSICS))
filter.m_nInteractsWith = opts->InteractsWith;
if (opts->InteractsExclude != 0)
@ -122,17 +126,21 @@ namespace RayTracePlugin::RayTrace
std::optional<TraceResult> TraceEndShape(
const Vector& origin,
const Vector& endOrigin,
CBaseEntity* ignorePlayer,
CBaseEntity* ignoreEntity,
const TraceOptions* opts)
{
CTraceFilterEx filter = ignorePlayer ? CTraceFilterEx(ignorePlayer) : CTraceFilterEx();
CTraceFilterEx filter = ignoreEntity ? CTraceFilterEx(ignoreEntity) : CTraceFilterEx();
filter.m_nInteractsAs = 0;
filter.m_nInteractsWith = static_cast<uint64_t>(MASK_SHOT_PHYSICS);
filter.m_nInteractsExclude = 0;
if (opts)
{
if (opts->InteractsWith != 0)
if (opts->InteractsAs != 0)
filter.m_nInteractsAs = opts->InteractsAs;
if (opts->InteractsWith != static_cast<uint64_t>(MASK_SHOT_PHYSICS))
filter.m_nInteractsWith = opts->InteractsWith;
if (opts->InteractsExclude != 0)
@ -150,4 +158,37 @@ namespace RayTracePlugin::RayTrace
return res;
}
std::optional<TraceResult> TraceHullShape(const Vector &vecStart, const Vector &vecEnd, const Vector &hullMins,
const Vector &hullMaxs, CBaseEntity *ignoreEntity, const TraceOptions *opts) {
CTraceFilterEx filter = ignoreEntity ? CTraceFilterEx(ignoreEntity) : CTraceFilterEx();
filter.m_nInteractsAs = 0;
filter.m_nInteractsWith = static_cast<uint64_t>(MASK_SHOT_PHYSICS);
filter.m_nInteractsExclude = 0;
if (opts)
{
if (opts->InteractsAs != 0)
filter.m_nInteractsAs = opts->InteractsAs;
if (opts->InteractsWith != static_cast<uint64_t>(MASK_SHOT_PHYSICS))
filter.m_nInteractsWith = opts->InteractsWith;
if (opts->InteractsExclude != 0)
filter.m_nInteractsExclude = opts->InteractsExclude;
}
Ray_t ray;
ray.Init(hullMins, hullMaxs);
auto res = TraceShapeEx(vecStart, vecEnd, filter, ray);
if (opts && opts->DrawBeam)
{
Color col = res.has_value() ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
DrawBeam(vecStart, res ? res->EndPos : vecEnd, col);
}
return res;
}
}