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;
}
}

View file

@ -32,13 +32,21 @@ namespace RayTracePlugin::RayTrace
std::optional<TraceResult> TraceShape(
const Vector& origin,
const QAngle& viewangles,
CBaseEntity* ignorePlayer = nullptr,
CBaseEntity* ignoreEntity = nullptr,
const TraceOptions* opts = nullptr);
std::optional<TraceResult> TraceEndShape(
const Vector& origin,
const Vector& endOrigin,
CBaseEntity* ignorePlayer = nullptr,
CBaseEntity* ignoreEntity = nullptr,
const TraceOptions* opts = nullptr);
std::optional<TraceResult> TraceHullShape(
const Vector& vecStart,
const Vector& vecEnd,
const Vector& hullMins,
const Vector& hullMaxs,
CBaseEntity* ignoreEntity = nullptr,
const TraceOptions* opts = nullptr);
std::optional<TraceResult> TraceShapeEx(
@ -53,11 +61,11 @@ namespace RayTracePlugin::RayTrace
bool TraceShape(
const Vector* origin,
const QAngle* viewangles,
CBaseEntity* ignorePlayer,
CBaseEntity* ignoreEntity,
const TraceOptions* opts,
TraceResult* outResult) override
{
auto result = RayTrace::TraceShape(*origin, *viewangles, ignorePlayer, opts);
auto result = RayTrace::TraceShape(*origin, *viewangles, ignoreEntity, opts);
if (!result.has_value())
return false;
@ -68,11 +76,28 @@ namespace RayTracePlugin::RayTrace
bool TraceEndShape(
const Vector* origin,
const Vector* endOrigin,
CBaseEntity* ignorePlayer,
CBaseEntity* ignoreEntity,
const TraceOptions* opts,
TraceResult* outResult) override
{
auto result = RayTrace::TraceEndShape(*origin, *endOrigin, ignorePlayer, opts);
auto result = RayTrace::TraceEndShape(*origin, *endOrigin, ignoreEntity, opts);
if (!result.has_value())
return false;
*outResult = result.value();
return true;
}
bool TraceHullShape(
const Vector* vecStart,
const Vector* vecEnd,
const Vector* hullMins,
const Vector* hullMaxs,
CBaseEntity* ignoreEntity,
const TraceOptions* opts,
TraceResult* outResult) override
{
auto result = RayTrace::TraceHullShape(*vecStart, *vecEnd, *hullMins, *hullMaxs, ignoreEntity, opts);
if (!result.has_value())
return false;