protected virtual void CloneCore(ParticleSystem source) { Name = source.Name; Enabled = source.Enabled; MaxNumberOfParticles = source.MaxNumberOfParticles; InitialDelay = source.InitialDelay; PreloadDuration = source.PreloadDuration; PreloadDeltaTime = source.PreloadDeltaTime; TimeScaling = source.TimeScaling; EnableMultithreading = source.EnableMultithreading; ReferenceFrame = source.ReferenceFrame; // Cloning the particle parameter collection is tricky because the parameters are generics. // We use an internal method of the parameter to do the job. foreach (var parameter in source.Parameters) ((IParticleParameterInternal)parameter).AddCopyToCollection(Parameters); foreach (var effector in source.Effectors) Effectors.Add(effector.Clone()); if (source.Children != null) { Children = new ParticleSystemCollection(); foreach (var particleSystem in source.Children) Children.Add(particleSystem.Clone()); } Pose = source.Pose; Shape = source.Shape.Clone(); }
public void Test() { var m = new ParticleSystemManager(); var parent = new ParticleSystem() { Service = m }; var a = new ParticleSystem(); var b = new ParticleSystem(); var c = new ParticleSystem(); var psc = new ParticleSystemCollection(); parent.Children = psc; psc.Add(a); Assert.AreEqual(parent, a.Parent); Assert.AreEqual(m, a.Service); psc[0] = b; Assert.AreEqual(null, a.Parent); Assert.AreEqual(null, a.Service); Assert.AreEqual(parent, b.Parent); Assert.AreEqual(m, b.Service); psc.Add(a); psc.Remove(b); Assert.AreEqual(null, b.Parent); Assert.AreEqual(null, b.Service); psc.Clear(); Assert.AreEqual(null, a.Parent); Assert.AreEqual(null, a.Service); }
public BrownOut(ContentManager contentManager) { Pose = new Pose(Matrix33F.CreateRotationX(-ConstantsF.PiOver2)); // Smoke on a ring. var outerRingSmoke = CreateSmoke(contentManager); outerRingSmoke.Effectors.Add(new StreamEmitter { DefaultEmissionRate = 30 }); outerRingSmoke.Effectors.Add(new StartPositionEffector { Distribution = new CircleDistribution { OuterRadius = 5, InnerRadius = 4 } }); // Smoke in the area inside the ring. var innerCircleSmoke = CreateSmoke(contentManager); innerCircleSmoke.Effectors.Add(new StreamEmitter { DefaultEmissionRate = 10 }); innerCircleSmoke.Effectors.Add(new StartPositionEffector { Distribution = new CircleDistribution { OuterRadius = 4, InnerRadius = 0 } }); // Uniform particle parameter that are the same for all child particle systems. Parameters.AddUniform<float>(ParticleParameterNames.Lifetime).DefaultValue = 5; _isDepthSortedParameter = Parameters.AddUniform<bool>(ParticleParameterNames.IsDepthSorted); _isDepthSortedParameter.DefaultValue = true; Children = new ParticleSystemCollection { outerRingSmoke, innerCircleSmoke }; }
public static int CountNumberOfParticles(ParticleSystemCollection particleSystems) { int count = 0; foreach (var particleSystem in particleSystems) { count += particleSystem.NumberOfLivingParticles; if (particleSystem.Children != null) count += CountNumberOfParticles(particleSystem.Children); } return count; }
public Rockets() { Name = "Rockets"; MaxNumberOfParticles = 10; // The RocketEffector will add child particle systems. Children = new ParticleSystemCollection(); Parameters.AddUniform <float>(ParticleParameterNames.Lifetime).DefaultValue = 2; Effectors.Add(new StreamEmitter { DefaultEmissionRate = 2, }); Parameters.AddVarying <Vector3>(ParticleParameterNames.Position); Effectors.Add(new StartPositionEffector { Parameter = ParticleParameterNames.Position, Distribution = new BoxDistribution { MinValue = new Vector3(-5, 0, -5), MaxValue = new Vector3(5, 0, 0) }, }); Parameters.AddVarying <Vector3>(ParticleParameterNames.Direction); Effectors.Add(new StartDirectionEffector { Parameter = ParticleParameterNames.Direction, Distribution = new DirectionDistribution { Deviation = 0.5f, Direction = Vector3.UnitY }, }); Parameters.AddVarying <float>(ParticleParameterNames.LinearSpeed); Effectors.Add(new StartValueEffector <float> { Parameter = ParticleParameterNames.LinearSpeed, Distribution = new UniformDistributionF(2, 6), }); Effectors.Add(new LinearVelocityEffector()); Parameters.AddUniform <Vector3>(ParticleParameterNames.LinearAcceleration).DefaultValue = new Vector3(0, -2f, 0); Effectors.Add(new LinearAccelerationEffector()); Parameters.AddUniform <float>(ParticleParameterNames.Alpha).DefaultValue = 0; // The RocketEffector creates and controls nested particle systems for the rocket trails // and explosions. Effectors.Add(new RocketEffector()); ParticleSystemValidator.Validate(this); }
public Rockets() { Name = "Rockets"; MaxNumberOfParticles = 10; // The RocketEffector will add child particle systems. Children = new ParticleSystemCollection(); Parameters.AddUniform<float>(ParticleParameterNames.Lifetime).DefaultValue = 2; Effectors.Add(new StreamEmitter { DefaultEmissionRate = 2, }); Parameters.AddVarying<Vector3F>(ParticleParameterNames.Position); Effectors.Add(new StartPositionEffector { Parameter = ParticleParameterNames.Position, Distribution = new BoxDistribution { MinValue = new Vector3F(-5, 0, -5), MaxValue = new Vector3F(5, 0, 0) }, }); Parameters.AddVarying<Vector3F>(ParticleParameterNames.Direction); Effectors.Add(new StartDirectionEffector { Parameter = ParticleParameterNames.Direction, Distribution = new DirectionDistribution { Deviation = 0.5f, Direction = Vector3F.UnitY }, }); Parameters.AddVarying<float>(ParticleParameterNames.LinearSpeed); Effectors.Add(new StartValueEffector<float> { Parameter = ParticleParameterNames.LinearSpeed, Distribution = new UniformDistributionF(2, 6), }); Effectors.Add(new LinearVelocityEffector()); Parameters.AddUniform<Vector3F>(ParticleParameterNames.LinearAcceleration).DefaultValue = new Vector3F(0, -2f, 0); Effectors.Add(new LinearAccelerationEffector()); Parameters.AddUniform<float>(ParticleParameterNames.Alpha).DefaultValue = 0; // The RocketEffector creates and controls nested particle systems for the rocket trails // and explosions. Effectors.Add(new RocketEffector()); ParticleSystemValidator.Validate(this); }
public static int CountNumberOfParticles(ParticleSystemCollection particleSystems) { int count = 0; foreach (var particleSystem in particleSystems) { count += particleSystem.NumberOfLivingParticles; if (particleSystem.Children != null) { count += CountNumberOfParticles(particleSystem.Children); } } return(count); }
public Explosion(ContentManager contentManager) { // The explosion particle systems owns 3 child particle systems. // (The parent particle system does not have any particles.) Children = new ParticleSystemCollection { CreateFlash(contentManager), CreateHotCore(contentManager), CreateSmoke(contentManager), }; ParticleSystemValidator.Validate(Children[0]); ParticleSystemValidator.Validate(Children[1]); ParticleSystemValidator.Validate(Children[2]); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ParticleSystemManager"/> class. /// </summary> public ParticleSystemManager() { _updateParticleSystem = UpdateParticleSystem; #if WP7 || UNITY // Cannot access Environment.ProcessorCount in phone app. (Security issue.) EnableMultithreading = false; #else // Enable multithreading by default if the current system has multiple processors. EnableMultithreading = Environment.ProcessorCount > 1; // Multithreading works but Parallel.For of Xamarin.Android/iOS is very inefficient. if (GlobalSettings.PlatformID == PlatformID.Android || GlobalSettings.PlatformID == PlatformID.iOS) EnableMultithreading = false; #endif ParticleSystems = new ParticleSystemCollection(); ParticleSystems.CollectionChanged += OnParticleSystemsChanged; }
private RocketExplosion(ContentManager contentManager) { Children = new ParticleSystemCollection { new RocketExplosionSmoke(contentManager), new RocketExplosionCore(contentManager), }; // This EmitterVelocity parameter can be used by all child particle systems. Parameters.AddUniform<Vector3F>(ParticleParameterNames.EmitterVelocity); // The ParticleSystemRecycler recycles this instance into the resource pool when all // particles are dead. Effectors.Add(new ParticleSystemRecycler { ResourcePool = Pool, }); ParticleSystemValidator.Validate(this); ParticleSystemValidator.Validate(Children[0]); ParticleSystemValidator.Validate(Children[1]); }
public BrownOut(ContentManager contentManager) { Pose = new Pose(Matrix33F.CreateRotationX(-ConstantsF.PiOver2)); // Smoke on a ring. var outerRingSmoke = CreateSmoke(contentManager); outerRingSmoke.Effectors.Add(new StreamEmitter { DefaultEmissionRate = 30 }); outerRingSmoke.Effectors.Add(new StartPositionEffector { Distribution = new CircleDistribution { OuterRadius = 5, InnerRadius = 4 } }); // Smoke in the area inside the ring. var innerCircleSmoke = CreateSmoke(contentManager); innerCircleSmoke.Effectors.Add(new StreamEmitter { DefaultEmissionRate = 10 }); innerCircleSmoke.Effectors.Add(new StartPositionEffector { Distribution = new CircleDistribution { OuterRadius = 4, InnerRadius = 0 } }); // Uniform particle parameter that are the same for all child particle systems. Parameters.AddUniform <float>(ParticleParameterNames.Lifetime).DefaultValue = 5; _isDepthSortedParameter = Parameters.AddUniform <bool>(ParticleParameterNames.IsDepthSorted); _isDepthSortedParameter.DefaultValue = true; Children = new ParticleSystemCollection { outerRingSmoke, innerCircleSmoke }; }
private RocketExplosion(ContentManager contentManager) { Children = new ParticleSystemCollection { new RocketExplosionSmoke(contentManager), new RocketExplosionCore(contentManager), }; // This EmitterVelocity parameter can be used by all child particle systems. Parameters.AddUniform <Vector3F>(ParticleParameterNames.EmitterVelocity); // The ParticleSystemRecycler recycles this instance into the resource pool when all // particles are dead. Effectors.Add(new ParticleSystemRecycler { ResourcePool = Pool, }); ParticleSystemValidator.Validate(this); ParticleSystemValidator.Validate(Children[0]); ParticleSystemValidator.Validate(Children[1]); }
public SceneManager(Settings settings, GraphicsDevice graphicsDevice) { if (settings == null) { throw new ArgumentNullException("settings"); } if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.settings = settings; GraphicsDevice = graphicsDevice; spriteBatch = new SpriteBatch(GraphicsDevice); Cameras = new CameraCollection(InitialCameraCapacity); DirectionalLights = new DirectionalLightCollection(InitialDirectionalLightCapacity); ParticleSystems = new ParticleSystemCollection(InitialParticleSystemCapacity); PostProcessors = new PostProcessorCollection(InitialPostProcessorCapacity); opaqueObjects = new List <SceneObject>(InitialSceneObjectCapacity); translucentObjects = new List <SceneObject>(InitialSceneObjectCapacity); shadowCasters = new List <ShadowCaster>(InitialShadowCasterCapacity); collectObjectsAction = new Action <Octree>(CollectObjects); //---------------------------------------------------------------- // シーン描画のためのレンダ ターゲット var pp = GraphicsDevice.PresentationParameters; var width = pp.BackBufferWidth; var height = pp.BackBufferHeight; var format = pp.BackBufferFormat; var depthFormat = pp.DepthStencilFormat; var multiSampleCount = pp.MultiSampleCount; RenderTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format, depthFormat, multiSampleCount, RenderTargetUsage.PreserveContents); //---------------------------------------------------------------- // ポストプロセッサ コンテキスト postProcessorContext = new PostProcessorContext(this); //---------------------------------------------------------------- // ポスト プロセスのためのレンダ ターゲット postProcessRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format, depthFormat, multiSampleCount, RenderTargetUsage.PreserveContents); // TODO octreeManager = new OctreeManager(new Vector3(256), 3); // TODO RootNode = new SceneNode(this, "Root"); #if DEBUG || TRACE debugBoxEffect = new BasicEffect(GraphicsDevice); debugBoxEffect.AmbientLightColor = Vector3.One; debugBoxEffect.VertexColorEnabled = true; debugBoxDrawer = new BoundingBoxDrawer(GraphicsDevice); #endif }