Silverlight Game Design Tutorial
| < previous page | next page > |
This tutorial is about creating 3d particles effect using Spectrum 3D particles engine.
It might look difficult at first, but creating particles effects in Silverlight takes only 10 lines of codes using the Spectrum particles system.
By the end of this tutorial you will have created a project that looks like this:
Setup
1. To use Spectrum particles 3D engine, first download the assembly (Spectrum.dll file).
2. Next open up your Silverlight project, click Project -> Add Reference.
3. Click "Browse" tab, then find the .dll file to add into the reference.
Now you can use the functions in Spectrum class.
Code
1. First we have to instantiate a camera and a normal particle generator.
Spectrum.Camera3D camera = new Spectrum.Camera3D();
Spectrum.ParticleGeneratorNormal pgNormal;
2. Next we initialize the camera and the particle generator
camera.setView(new Vec3(0,0,0), 1000, new Vec3(0,1,0), new Vec3(1,0,0), new Vec3(0,0,1)); pgNormal = new Spectrum.ParticleGeneratorNormal(camera, null, Spectrum.Globals.ParticleShape.smoke);
Camera.setView has the following arguments:
-focus is where your camera is looking at
-dist is the distance from your view point to the focus
-down is the down vector of your view point
-right is the right vector of your view point
-front is the front vector of your view point
ParticleGeneratorNormal has the following arguments:
-the camera
-a XML file name for particles effect. null for no effect
-particle shape. Only 2 choices available: Star or Smoke
3. Add particles.
for (int i = -3; i <= 3; i++) for (int j = -3; j <= 3; j++) for (int k = -3; k <= 3; k++) pgNormal.createAndAdd(new Spectrum.Vec3(i * 50, j * 50, k * 50), new Spectrum.Vec3(0, 0, 0), new Spectrum.Vec3(0, 0, 0));
3 nested loops to create a 3D array of particles. The arguments for createAndAdd are:
-position of particle, in 3D coordinates.
-velocity of the particle. Here we just use 0,0,0.
-acceleration of the particle. Here we just use 0,0,0.
4. Finally, run the update method inside your game loop.
pgNormal.update(new Spectrum.Vec3(0, 0, 0));
camera.update();That is all. You will be able to see particles in 3D space. Other functions like moving the camera and zooming in and out are demonstrated in this project available for download with full source code.
| < previous page | next page > |
Comments:
2011-07-15 11:05:06 Patience wrote:
Super jzazed about getting that know-how. |
2009-07-07 02:00:42 Byron wrote:
Tutorial with more features available soon |


