Пример #1
0
 /// <summary>
 /// Do the single check from camera to the fixed position.
 /// Hit actors put in _scratchActors.
 /// </summary>
 /// <param name="cameraPos"></param>
 /// <param name="targetPos"></param>
 /// <param name="radius"></param>
 private void CheckLOSToTarget(Vector3 cameraPos, Vector3 targetPos, float radius)
 {
     Debug.Assert(_scratchLOS.Count == 0);
     if (CollSys.TestAll(
             cameraPos,
             targetPos,
             radius,
             _scratchLOS))
     {
         ActorsFromHitInfo(_scratchLOS, _scratchActors);
     }
     _scratchLOS.Clear();
 }
Пример #2
0
        /// <summary>
        /// Just see what's intersecting the sphere around the camera.
        /// </summary>
        /// <param name="camera"></param>
        private void CheckCameraSphere(Camera camera)
        {
            Debug.Assert(_scratchLOS.Count == 0);
            Debug.Assert(_scratchActors.Count == 0);
            Vector3 camPos    = camera.ActualFrom;
            float   camRadius = camera.NearClip * 5.0f;

            if (CollSys.TestAll(
                    camPos,
                    camPos,
                    camRadius,
                    _scratchLOS))
            {
                ActorsFromHitInfo(_scratchLOS, _scratchActors);
            }
            _scratchLOS.Clear();
        }
Пример #3
0
        /// <summary>
        /// Test to see if a bleep hit anything, object or terrain.
        /// </summary>
        /// <param name="shooter"></param>
        /// <param name="bleeps"></param>
        /// <param name="particle"></param>
        /// <returns></returns>
        private bool HitSomething(GameActor shooter, Bleep bleep)
        {
            Vector3 start = bleep.Position;
            Vector3 end   = start + bleep.Velocity * Time.GameTimeFrameSeconds;

            Vector3 terrainHit = end;
            bool    hitTerrain = bleep.Life - bleep.TTL >= bleep.TTTerraHit;

            if (hitTerrain)
            {
                /// terrain hit is current position
                /// - what we've travelled already (vel * (life - ttl))
                /// + time from beginning to terrain hit (vel * ttTerraHit)
                /// We use end as current position because we've already updated TTL
                /// but haven't yet advanced .Position. When we do advance .Position,
                /// it will be to "end".
                terrainHit = end + bleep.Velocity * (bleep.TTTerraHit - (bleep.Life - bleep.TTL));
            }

            const float kBleepRadius = 0.25f;
            GameActor   hitThing     = null;
            Vector3     hitPoint     = terrainHit;

            if (CollSys.TestAll(
                    start,
                    end,
                    kBleepRadius,
                    _scratchHitInfo))
            {
                for (int i = 0; i < _scratchHitInfo.Count; ++i)
                {
                    GameActor other = _scratchHitInfo[i].Other;
                    if (!ExcludedHitThing(shooter, other))
                    {
                        hitThing = other;
                        hitPoint = _scratchHitInfo[i].Contact;
                        break;
                    }
                }
                _scratchHitInfo.Clear();
            }

            if (hitTerrain && (hitThing != null))
            {
                if (Vector3.DistanceSquared(start, terrainHit) < Vector3.DistanceSquared(start, hitPoint))
                {
                    hitThing = null;
                    hitPoint = terrainHit;
                }
            }

            if (hitThing != null)
            {
                OnHit(shooter, hitThing, hitPoint, bleep);
            }
            else if (hitTerrain)
            {
                OnHit(shooter, null, hitPoint, bleep);
                ExplosionManager.CreateSpark(hitPoint, 3, 0.4f, 1.0f);
            }

            return(hitTerrain || (hitThing != null));;
        }