예제 #1
0
        /// <summary>
        /// Updates the particle emitter bounds
        /// </summary>
        /// <param name="systemParams">System parameters</param>
        public void UpdateBounds(ParticleSystemParams systemParams)
        {
            var bbox = SampleBBox(this, systemParams, 0.33f);

            bbox = BoundingBox.Merge(bbox, SampleBBox(this, systemParams, 0.66f));
            bbox = BoundingBox.Merge(bbox, SampleBBox(this, systemParams, 1f));

            this.SetBoundingBox(bbox);
        }
예제 #2
0
        /// <summary>
        /// Updates the internal bounding box
        /// </summary>
        protected virtual void UpdateBoundingBox()
        {
            var tmp = mergedBoundingBox;

            mergedBoundingBox = new BoundingBox(
                this.boundingBox.Minimum + this.Position,
                this.boundingBox.Maximum + this.Position);

            if (tmp != null)
            {
                mergedBoundingBox = BoundingBox.Merge(tmp.Value, mergedBoundingBox.Value);
            }
        }
예제 #3
0
        /// <summary>
        /// Samples a bounding box for the current emitter at the specified time
        /// </summary>
        /// <param name="emitter">Emitter</param>
        /// <param name="systemParams">Particle system parameters</param>
        /// <param name="time">Time</param>
        /// <returns>Returns the sampled bounding box</returns>
        private static BoundingBox SampleBBox(ParticleEmitter emitter, ParticleSystemParams systemParams, float time)
        {
            //Initial position
            Vector3 initialPos         = Vector3.Zero;
            Vector3 velocity           = emitter.Velocity * systemParams.EmitterVelocitySensitivity;
            float   horizontalVelocity = Math.Max(systemParams.HorizontalVelocity.X, systemParams.HorizontalVelocity.Y);

            //Max v velocity
            Vector3 vVelocity = velocity;

            vVelocity.Y *= Math.Max(systemParams.VerticalVelocity.X, systemParams.VerticalVelocity.Y);

            //Max h velocity
            Vector3 hVelocity1 = velocity;

            hVelocity1.X *= horizontalVelocity * (float)Math.Cos(0);
            hVelocity1.Z *= horizontalVelocity * (float)Math.Sin(0);

            Vector3 hVelocity2 = velocity;

            hVelocity2.X *= horizontalVelocity * (float)Math.Cos(1);
            hVelocity2.Z *= horizontalVelocity * (float)Math.Sin(1);

            //Final positions
            Vector3 finalPosV = ComputeParticlePosition(
                initialPos,
                vVelocity,
                systemParams.EndVelocity,
                systemParams.MaxDuration * time,
                time,
                systemParams.Gravity);

            Vector3 finalPosH1 = ComputeParticlePosition(
                initialPos,
                hVelocity1,
                systemParams.EndVelocity,
                systemParams.MaxDuration * time,
                time,
                systemParams.Gravity);

            Vector3 finalPosH2 = ComputeParticlePosition(
                initialPos,
                hVelocity2,
                systemParams.EndVelocity,
                systemParams.MaxDuration * time,
                time,
                systemParams.Gravity);

            float startSize = systemParams.MaxStartSize * 0.5f;

            BoundingSphere initial = new BoundingSphere(initialPos + new Vector3(0, startSize, 0), startSize * 0.5f);

            float endSize = systemParams.MaxEndSize * 0.5f;

            BoundingSphere finalV  = new BoundingSphere(finalPosV + new Vector3(0, endSize, 0), endSize * 0.5f);
            BoundingSphere finalH1 = new BoundingSphere(finalPosH1 + new Vector3(0, endSize, 0), endSize * 0.5f);
            BoundingSphere finalH2 = new BoundingSphere(finalPosH2 + new Vector3(0, endSize, 0), endSize * 0.5f);

            var bbox = BoundingBox.FromSphere(initial);

            bbox = BoundingBox.Merge(bbox, BoundingBox.FromSphere(finalV));
            bbox = BoundingBox.Merge(bbox, BoundingBox.FromSphere(finalH1));
            bbox = BoundingBox.Merge(bbox, BoundingBox.FromSphere(finalH2));

            return(bbox);
        }