Computer Science Canada Particle Engine |
Author: | ericfourfour [ Wed Nov 01, 2006 11:44 am ] |
Post subject: | Particle Engine |
This is one of my best particle engines yet. Their are two systems already. The MouseOrbitalSystem where the particles orbit the mouse, and the TrailingMouseOrbitalSystem where the particles do the same as the first but they have trail. A bit about the mechanics: Every particle has an attribute called data. It is a pointer to the PhysData class. The PhysData class contains the position, velocity, and acceleration (mostly it is the velocity that is changed). If you want to update the data (add acceleration and velocity) simply call the update procedure. Each particle also has a list of pointers to the PhysicalEffect class and the list can be modified externally. The PhysicalEffects have one procedure called effect that is called with the data as the parameter. When it is called it performs effects on the position, velocity, and acceleration. For example, gravity affects the velocity. When you want a new physical effect you have to extend a class with new effect functions. When the particle is thinking. It cycles through every effect and then updates the data. When this is done the particle gets rendered. The Particle class is the parent class to all other particles. It contains all of the position data, the colour data, the size data, the life data, etc. It also has many procedures to initialize all of this data. The life data is not used if the set_life procedure is not called. Many other things in work this way throughout the engine. The TrailingParticle class inherits the Particle class. It allows particles to leave a trail. The programmer can set the length by calling the set_length procedure. It uses a flexible array for the positions (or nodes). I think that I will switch to a linked list since I only have to change around two to four pointers to push back instead of pushing every single element back. The ParticleSystem class has a list of particles. It has a procedure called set_particles which allows the programmer to set up how many particles there are. This class simply does nothing with the particles since it is the parent class of all other particle systems. The MouseOrbitalSystem class inherits the ParticleSystem class. It also has information for the mouse and a pointer to an effect that keeps the particle data orbiting the mouse coordinate based on strength (gravity), minimum, and maximum distance. The TrailingMouseOrbitalSystem class inherits the MouseOrbitalSystem. It however allows for trailing particles and the programmer can set the length of them by calling the set_lengths procedure. There are many other things you should know if you want to make your own custom particle systems and that will be shown when I release documentation. Edit: haha! I can't believe I forgot to post the source. Edit: newer version added |
Author: | Silent Avenger [ Wed Nov 01, 2006 4:31 pm ] |
Post subject: | |
umm ericfourfour, I don't see any source code. |
Author: | ericfourfour [ Sun Nov 05, 2006 12:55 am ] |
Post subject: | |
I've updated the engine and added a rain system. Here is the rain system source. |
Author: | Windsurfer [ Sun Nov 05, 2006 9:18 am ] |
Post subject: | |
Nice system, good job! One thing about the rain system you might want to know: the rain drops do not follow linear perspective. They are slower near the edges, and faster near the center. Linear persepctive dictates the opposite. |
Author: | ericfourfour [ Sun Nov 05, 2006 4:41 pm ] |
Post subject: | |
I'll add that in. It shouldn't be that hard. I just need to create a new effect. |
Author: | JakeP [ Sun Dec 17, 2006 3:52 pm ] |
Post subject: | |
Hey I had some issues with using TrailingMouseOrbitalSystem. Replacing the two or three lines in the rain test boilerplate code to use it would cause an array out-of-bound error on trails (it works for every system but this one) I fixed it by changing one of the inherits of one of the systems (i forget which, sorry) It's really cool though, it is a really easy to use api, good work! |