/// <summary>
        /// Check if aim ray intersects any hitbox of entity.
        /// </summary>
        /// <returns>
        /// Returns id of intersected hitbox, otherwise -1.
        /// </returns>
        public static int IntersectsHitBox(Line3D aimRayWorld, Entity entity)
        {
            for (var hitBoxId = 0; hitBoxId < entity.StudioHitBoxSet.numhitboxes; hitBoxId++)
            {
                var hitBox = entity.StudioHitBoxes[hitBoxId];
                var boneId = hitBox.bone;
                if (boneId < 0 || boneId > Offsets.MAXSTUDIOBONES || hitBox.radius <= 0)
                {
                    continue;
                }

                // intersect capsule
                var matrixBoneModelToWorld = entity.BonesMatrices[boneId];
                var boneStartWorld         = matrixBoneModelToWorld.Transform(hitBox.bbmin);
                var boneEndWorld           = matrixBoneModelToWorld.Transform(hitBox.bbmax);
                var boneWorld = new Line3D(boneStartWorld, boneEndWorld);
                var(p0, p1) = aimRayWorld.ClosestPointsBetween(boneWorld, true);
                var distance = (p1 - p0).Length();
                if (distance < hitBox.radius * 0.9f /* trigger a little bit inside */)
                {
                    // intersects
                    return(hitBoxId);
                }
            }

            return(-1);
        }
示例#2
0
 // Token: 0x060000C7 RID: 199 RVA: 0x00007888 File Offset: 0x00005A88
 public static int IntersectsHitBox(Line3D aimRayWorld, Entity entity)
 {
     for (int i = 0; i < entity.StudioHitBoxSet.numhitboxes; i++)
     {
         mstudiobbox_t mstudiobbox_t = entity.StudioHitBoxes[i];
         int           bone          = mstudiobbox_t.bone;
         if (bone >= 0 && bone <= Helper.MaxStudioBones && mstudiobbox_t.radius > 0f)
         {
             float num;
             if (entity.Team == DoYouEvenAimBro.PlayerTeam)
             {
                 num = 0.9f;
             }
             else
             {
                 num = 1f;
             }
             Matrix  matrix     = entity.BonesMatrices[bone];
             Vector3 startPoint = matrix.Transform(mstudiobbox_t.bbmin);
             Vector3 endPoint   = matrix.Transform(mstudiobbox_t.bbmax);
             Line3D  other      = new Line3D(startPoint, endPoint);
             ValueTuple <Vector3, Vector3> valueTuple = aimRayWorld.ClosestPointsBetween(other, true);
             Vector3 item = valueTuple.Item1;
             if ((valueTuple.Item2 - item).Length() < mstudiobbox_t.radius * num)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }