//missile hit debris.
        public void AddMissleHitDebris(Vector3 position, Vector3 moveDir)
        {
            int amount = FrameworkCore.r.Next(3, 6);

            for (int i = 0; i < amount; i++)
            {
                int index = -1;
                if (!GetFreeIndex(out index))
                {
                    return;
                }

                DebrisItem item = debrisItems[index];
                item.debrisModel = getRandomDebris();
                moveDir.Normalize();
                item.moveDir  = moveDir;
                item.position = position;
                item.lifeTime = FrameworkCore.r.Next(1000, 3000);

                item.moveSpeed       = Helpers.randFloat(4, 8);
                item.angularVelocity = new Vector3(Helpers.randFloat(-1, 1), Helpers.randFloat(-3, 3), 0);

                item.isActive = true;
            }
        }
        //hulk trail.
        public void AddHulkTrail(Vector3 position, Vector3 moveDir)
        {
            int amount = FrameworkCore.r.Next(2, 6);

            for (int i = 0; i < amount; i++)
            {
                int index = -1;
                if (!GetFreeIndex(out index))
                {
                    return;
                }

                DebrisItem item = debrisItems[index];
                item.debrisModel = getRandomDebris();
                moveDir.Normalize();
                item.moveDir  = moveDir;
                item.position = position;

                item.position.X += Helpers.randFloat(-1.5f, 1.5f);
                item.position.Y += Helpers.randFloat(-1.5f, 1.5f);

                item.lifeTime = FrameworkCore.r.Next(1500, 3000);

                item.moveSpeed       = Helpers.randFloat(0.5f, 1.5f);
                item.angularVelocity = new Vector3(Helpers.randFloat(-2, 2), Helpers.randFloat(-4, 4), 0);

                item.isActive = true;
            }
        }
 public DebrisManager()
 {
     debrisItems = new DebrisItem[MAXDEBRISITEMS];
     for (int i = 0; i < debrisItems.Length; i++)
     {
         debrisItems[i] = new DebrisItem();
     }
 }
        /// <summary>
        /// debris that shoots out when hulk is destroyed. shoots out in random directions.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="moveDir"></param>
        public void AddHulkDebris(Vector3 position, bool isAsteroid)
        {
            int amount = FrameworkCore.r.Next(16, 24);

            for (int i = 0; i < amount; i++)
            {
                int index = -1;
                if (!GetFreeIndex(out index))
                {
                    return;
                }

                DebrisItem item = debrisItems[index];

                if (!isAsteroid)
                {
                    item.debrisModel = getRandomDebris();
                }
                else
                {
                    item.debrisModel = ModelType.asteroidchunk;
                }


                //give position a random offset.
                Vector3 itemPosition = position +
                                       new Vector3(
                    Helpers.randFloat(-5, 5),
                    Helpers.randFloat(-5, 5),
                    Helpers.randFloat(-5, 5));

                item.position = itemPosition;
                item.lifeTime = FrameworkCore.r.Next(500, 2000);


                Vector3 moveDir = item.position - position;
                moveDir.Normalize();


                item.moveDir = moveDir;

                item.moveSpeed       = Helpers.randFloat(12, 48);
                item.angularVelocity = new Vector3(Helpers.randFloat(-3, 3), Helpers.randFloat(-6, 6), 0);

                item.isActive = true;
            }
        }
        public void Update(GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            for (int i = 0; i < debrisItems.Length; i++)
            {
                if (!debrisItems[i].isActive)
                {
                    continue;
                }

                DebrisItem item = debrisItems[i];
                item.position += (item.moveSpeed * item.moveDir) * dt;

                if (Math.Abs(item.angularVelocity.X) > 0)
                {
                    item.angles.X += item.angularVelocity.X * dt;
                }

                if (Math.Abs(item.angularVelocity.Y) > 0)
                {
                    item.angles.Y += item.angularVelocity.Y * dt;
                }

                if (Math.Abs(item.angularVelocity.Z) > 0)
                {
                    item.angles.Z += item.angularVelocity.Z * dt;
                }

                item.rotation = Quaternion.CreateFromYawPitchRoll(item.angles.X, item.angles.Y, item.angles.Z);


                item.lifeTime -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (item.emitter != null)
                {
                    item.emitter.Update(gameTime, item.position);
                }


                if (item.lifeTime <= 0)
                {
                    item.isActive = false;
                }
            }
        }
        //destruction debris
        public void AddDebris(ModelType model, Vector3 position, Vector3 moveDir)
        {
            int index = -1;

            if (!GetFreeIndex(out index))
            {
                return;
            }

            DebrisItem item = debrisItems[index];

            item.debrisModel = model;
            moveDir.Normalize();
            item.moveDir  = moveDir;
            item.position = position;
            item.lifeTime = FrameworkCore.r.Next(5000, 10000);

            item.moveSpeed       = Helpers.randFloat(8, 16);
            item.angularVelocity = new Vector3(Helpers.randFloat(-1, 1), Helpers.randFloat(-3, 3), 0);

            item.isActive = true;
        }
        //when a rocket bounces off an armored ship.
        public void AddRocketDeflect(ModelType model, Vector3 position, Vector3 moveDir)
        {
            int index = -1;

            if (!GetFreeIndex(out index))
            {
                return;
            }

            DebrisItem item = debrisItems[index];

            item.debrisModel = model;
            moveDir.Normalize();
            item.moveDir         = moveDir;
            item.position        = position;
            item.lifeTime        = 5000;
            item.debrisColor     = new Color(192, 192, 192);
            item.moveSpeed       = MathHelper.Lerp(4, 6, (float)FrameworkCore.r.NextDouble());
            item.angularVelocity = new Vector3(0, MathHelper.Lerp(-3, 3, (float)FrameworkCore.r.NextDouble()), 0);
            item.emitter         = FrameworkCore.Particles.CreateDeflectEmitter(item.position);

            item.isActive = true;
        }