ParticleSystem.cs :  » Game » SDL » SdlDotNet » Particles » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SDL 
SDL » SdlDotNet » Particles » ParticleSystem.cs
#region LICENSE
/*
 * Copyright (C) 2005 Rob Loach (http://www.robloach.net)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#endregion LICENSE

using System;
using System.Diagnostics.CodeAnalysis;

using SdlDotNet.Graphics;
using SdlDotNet.Particles;
using SdlDotNet.Particles.Manipulators;
using SdlDotNet.Particles.Emitters;

namespace SdlDotNet.Particles{
    /// <summary>
    /// A collection of particles manipulated by a number of common manipulators.
    /// </summary>
    /// <example>
    /// The following example creates a particle system with an pixel emitter and a vortex manipulator.
    /// <code>
    /// ParticleSystem system = new ParticleSystem();
    /// system.Add(new ParticleVortex(0.3f));
    /// system.Add(new ParticlePixelEmitter(Color.Black, Color.White));
    /// </code>
    /// </example>
    /// <remarks>Every tick you should call the Update method.  Every time you paint, you should call the Render function.</remarks>
    [SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Justification = "Not flags")]
    public class ParticleSystem
    {
        private ParticleManipulatorCollection m_Manipulators;
        private ParticleCollection m_Particles;

        /// <summary>
        /// Gets the collection of manipulators to manipulate the particles in the system.
        /// </summary>
        public ParticleManipulatorCollection Manipulators
        {
            get
            {
                return m_Manipulators;
            }
        }


        /// <summary>
        /// Gets the particles contained in the system.
        /// </summary>
        public ParticleCollection Particles
        {
            get
            {
                return m_Particles;
            }
        }

        /// <summary>
        /// Creates an empty particle system with no manipulators.
        /// </summary>
        public ParticleSystem()
        {
            m_Manipulators = new ParticleManipulatorCollection();
            m_Particles = new ParticleCollection();
        }

        /// <summary>
        /// Creates a particle system with a collection of particles already in it.
        /// </summary>
        /// <param name="particles">The particles to use with this system.</param>
        public ParticleSystem(ParticleCollection particles)
        {
            m_Manipulators = new ParticleManipulatorCollection();
            m_Particles = new ParticleCollection();
            m_Particles.Add(particles);
        }

        /// <summary>
        /// Copy Constructor.
        /// </summary>
        /// <param name="system">The particle system to copy.</param>
        public ParticleSystem(ParticleSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }
            m_Manipulators = new ParticleManipulatorCollection(system.Manipulators);
            m_Particles = new ParticleCollection();
            m_Particles.Add(system);
        }

        /// <summary>
        /// Creates a particle system with an already created manipulators and particles.
        /// </summary>
        /// <param name="manipulators">The manipulators to associate with this particle system.</param>
        /// <param name="particles">The particles to add to this particle system.</param>
        public ParticleSystem(ParticleManipulatorCollection manipulators, ParticleCollection particles)
        {
            m_Manipulators = manipulators;
            m_Particles = new ParticleCollection();
            m_Particles.Add(particles);
        }

        /// <summary>
        /// Creates an empty particle system with the desired paritcle manipulators.
        /// </summary>
        /// <param name="manipulators">The manipulators to use with the contained particles.</param>
        public ParticleSystem(ParticleManipulatorCollection manipulators)
        {
            m_Manipulators = manipulators;
            m_Particles = new ParticleCollection();
        }

        /// <summary>
        /// Creates an empty particle system with one particle manipulator.
        /// </summary>
        /// <param name="manipulator">The manipulator to use with this particle system.</param>
        public ParticleSystem(IParticleManipulator manipulator)
        {
            m_Manipulators = new ParticleManipulatorCollection();
            m_Manipulators.Add(manipulator);
            m_Particles = new ParticleCollection();
        }

        /// <summary>
        /// Updates all particles within this system using the given gravity.
        /// </summary>
        /// <returns>True if the system contains particles.</returns>
        public bool Update()
        {
            m_Manipulators.Manipulate(m_Particles);
            return m_Particles.Update();
        }

        /// <summary>
        /// Adds a particle to the system.
        /// </summary>
        /// <param name="particle"></param>
        public void Add(BaseParticle particle)
        {
            m_Particles.Add(particle);
        }

        /// <summary>
        /// Add a particle emitter to the particles.
        /// </summary>
        /// <param name="emitter">The emitter to add.</param>
        public void Add(ParticleEmitter emitter)
        {
            Add(emitter, true);
        }

        /// <summary>
        /// Adds a particle emitter to the particles.
        /// </summary>
        /// <param name="emitter">The emitter to add.</param>
        /// <param name="changeEmitterTarget">Flag to change the emitters target to the particles of this system. Defaults to true.</param>
        public void Add(ParticleEmitter emitter, bool changeEmitterTarget)
        {
            if (emitter == null)
            {
                throw new ArgumentNullException("emitter");
            }
            if (changeEmitterTarget)
            {
                emitter.Target.Clear();
                foreach (BaseParticle b in m_Particles)
                {
                    emitter.Target.Add(b);
                }
            }
            m_Particles.Add(emitter);
        }

        /// <summary>
        /// Renders all particles on the surface destination.
        /// </summary>
        /// <param name="destination">The destination surface.</param>
        public void Render(Surface destination)
        {
            foreach (BaseParticle particle in m_Particles)
            {
                particle.Render(destination);
            }
        }

        /// <summary>
        /// Adds a particle manipulator to the system.
        /// </summary>
        /// <param name="manipulator"></param>
        public void Add(IParticleManipulator manipulator)
        {
            m_Manipulators.Add(manipulator);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.