-
Автор темы
- #1
Код:
bool HitboxIntersection(C_BasePlayer* pPlayer, matrix3x4_t* Matrix, int HitBox, const Vector& vecStart, const Vector& vecEnd, float* Safe)
{
auto GetModel = pPlayer->GetModel();
auto StudioModel = g_Globals.m_Interfaces.m_ModelInfo->GetStudiomodel(GetModel);
auto StudioSet = StudioModel->GetHitboxSet(pPlayer->m_nHitboxSet());
auto StudioHitbox = StudioSet->GetHitbox(HitBox);
trace_t trace;
Ray_t ray;
Vector Min;
Vector Max;
if (!GetModel || !StudioModel || !StudioSet || !StudioHitbox)
return false;
ray.Init(vecStart, vecEnd);
auto Intersected = clip_ray_to_hitbox(ray, StudioHitbox, Matrix[StudioHitbox->m_nBone], trace) >= 0;
if (!Safe)
return Intersected;
Math::VectorTransform(StudioHitbox->m_vecBBMin, Matrix[StudioHitbox->m_nBone], Min);
Math::VectorTransform(StudioHitbox->m_vecBBMax, Matrix[StudioHitbox->m_nBone], Max);
auto Center = (Min + Max) * 0.5f;
auto Distance = Center.DistTo(vecEnd);
if (Distance > *Safe)
*Safe = Distance;
return Intersected;
}