3D Particle System for Windows Presentation Foundation
this is just a quick code dump. i needed a simple particle system for WPF 3D. i'd actually written a 2D particle system using GDI+ a couple years ago, so i recreated the basics for WPF 3D. the pic below shows a fountain effect with 3 models and a downward force. the models grow and rotate over time. the sliders rotate around the x,y,z axis to see it in 3D.
the code below shows how to use the particle system.
//create Model3Ds for the shapes of the particles above // ParticleSystemParameters psp = new ParticleSystemParameters(); //add particle shapes psp.ParticleShapes.Add(redCube); psp.ParticleShapes.Add(blueSphere); psp.ParticleShapes.Add(greenTea); //how shapes will be picked psp.ShapePickingOrder = ParticleResourceOrder.Loop; //how fast to emit particles psp.EmissionRate = 0.02f; psp.EmissionRateVariation = 100; //how long particles should live psp.Lifetime = 1500; psp.LifetimeVariation = 25; //direction to emit particles psp.EmitDirection = new Vector3D(0, 1, 0); psp.EmitDirectionVariation = new Vector3D(.5, .5, .5); //speed for emitting particles psp.EmitVelocity = 1.5f; psp.EmitVelocityVariation = 50; //external force applied against particles (e.g. gravity) psp.ForceDirection = new Vector3D(0, -1, 0); psp.ForceVelocity = .05f; //scale particles psp.ScaleIn = .1f; psp.ScaleOut = 1.5f; //rotate particles psp.RotateX = 720; psp.RotateY = 0; psp.RotateZ = 0; //create particle system using parameters above ps = new ParticleSystem(psp); //add particle system to Viewport3D this.mvPartSys.Children.Add(ps); ps.Start();
er, um ... so its a basic 3D particle system. took about a day to write.
C# source code
none planned, but the method used to translate particles needs to be changed to be more WPF-ish.
thinking about coding something for the XNA Artificial Intelligence contest