Particle Engine questions...
OK, I''m a total IDIOT and I hate myself. I tried to do a particle system (a very simple one) several times and I couldn''t. Patetic.
I know C/C++, and I can use SDL/OpenGL.
My request is: Could one of you, smart people (at least smarter than me), tell me how to do a particle system in C/C++ 2D (I hate myself enough, I don''t need 3D right now!!), or guide me, or use some pseudo code, or point me some tutorial, or... something.
Oh, yes, I searched in Google, but I didn''t find anything for beginners/idiots like me. I even have several tutorials, but all 3D (Nehe''s included, but it''s a bit too much for me right now, I don''t need to go so far).
What i want to do is a simple Galaga/like game where you shoot a ship and it explodes with some explosion generated with the particle system. Oh, and I want to learn how to do one, also, just because I like to... Also I can use it for vapor trails, etc.
I don''t know what else, if I can think in something else, I''ll tell you.
Please, help me.
PS: I am not an english writing/talking person, if you didn''t notice, so sorry about my limited english. If I would know more words, I would refer about myself with worst words than idiot.
[Edited by - exepotes on August 10, 2004 4:00:38 AM]
-----------------------------------------------------------Web Comic
I haven''t made my own 2d particle system, but I''ll share my thoughts anyway.
Since I''m an OO-freak, I''d first make up a Particle class which holds information about color, position, velocity, active_flag and other needed information. Methods would be updatePosition( float time_delta ) , and a rendering method.
Then I''d use a class named ParticleEngine or something, which would contain an array of Particle s which would have methods like initExplosion( POINT position, int num_particles, color, intensitiy blah blah blah ), updateParticles(), render()
So, in code, it would look something like:
Oh well, hope you get the idea.
Since I''m an OO-freak, I''d first make up a Particle class which holds information about color, position, velocity, active_flag and other needed information. Methods would be updatePosition( float time_delta ) , and a rendering method.
Then I''d use a class named ParticleEngine or something, which would contain an array of Particle s which would have methods like initExplosion( POINT position, int num_particles, color, intensitiy blah blah blah ), updateParticles(), render()
So, in code, it would look something like:
ParticleEngine *pParticles;// ship explodedpParticles->initExplosion( pShip->getPosition(), ... ); // inits a bunch of particles// another explosionpParticles->initExplosion( SomePoint, ... );// in the game looppParticles->updateParticles( time_delta ); // updates all active particlespParticles->render(); // renders all active particles
Oh well, hope you get the idea.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
Here's one link I found:
Building an Advanced Particle System
Particle systems aren't a beginner subject. You might want to consider something easier until you get more experience.
[edited by - Machaira on February 14, 2003 9:35:12 AM]
Building an Advanced Particle System
Particle systems aren't a beginner subject. You might want to consider something easier until you get more experience.
[edited by - Machaira on February 14, 2003 9:35:12 AM]
Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development
February 14, 2003 08:37 AM
Particle systems are quite easy in 2D.
First there is really good coverage in Andre Lamothe''s Tricks of the Windows Game Programming Gurus. Even though the book uses DX and your using SDL, the discussion is still relevant.
Secondly, I agree with the previous post, defining a particle class would be the best way to go but here is a simple particle data structure:
struct Particle
{
int x; // x position of particle
int y; // y position of particle
int vx; // velocity of particle in x direction
int vy; // velocity of particle in y direction
int lifeTime; // lifetime or particle in frames or secs
int type; // Type of particle, fixed, fading, blinking
int color;
};
That basically the data structure you need. The lifeTime field governs how long your particle lives. The type field says what kind of particle it is ( all kinds of options here ). The color field will be dependent on your display mode. In 8 bits per pixel mode in will an index into a palette. In 16 bits per pixel mode it will actually be an unsigned short color encoded color in either R5G5B5 or R5G6B5 format.
You can use sine and cosine functions to create a series of particles in a circular pattern for explosions and shockwave explosions.
The possibilities are endless, but particle engines are cheap and with a little work and a little math you can create all kinds of effects.
The above data structure, some math calculations, and a little creativity have yielded the following effects in my engine:
. Explosions
. Shockwave explosions
. Engine vapor trails
. Starfields
. Smoke
. Water
Good Luck
First there is really good coverage in Andre Lamothe''s Tricks of the Windows Game Programming Gurus. Even though the book uses DX and your using SDL, the discussion is still relevant.
Secondly, I agree with the previous post, defining a particle class would be the best way to go but here is a simple particle data structure:
struct Particle
{
int x; // x position of particle
int y; // y position of particle
int vx; // velocity of particle in x direction
int vy; // velocity of particle in y direction
int lifeTime; // lifetime or particle in frames or secs
int type; // Type of particle, fixed, fading, blinking
int color;
};
That basically the data structure you need. The lifeTime field governs how long your particle lives. The type field says what kind of particle it is ( all kinds of options here ). The color field will be dependent on your display mode. In 8 bits per pixel mode in will an index into a palette. In 16 bits per pixel mode it will actually be an unsigned short color encoded color in either R5G5B5 or R5G6B5 format.
You can use sine and cosine functions to create a series of particles in a circular pattern for explosions and shockwave explosions.
The possibilities are endless, but particle engines are cheap and with a little work and a little math you can create all kinds of effects.
The above data structure, some math calculations, and a little creativity have yielded the following effects in my engine:
. Explosions
. Shockwave explosions
. Engine vapor trails
. Starfields
. Smoke
. Water
Good Luck
AP: If it''s not "secret", would I be able to get some source code for your engine? I''d be interested in seeing how you handled it. superpeon1@hotmail.com, if you''re willing.
Peon
OK, thanks to all of you. I''ll try with all the stuuf you''re proposing.
-----------------------------------------------------------Web Comic
February 15, 2003 01:09 PM
You might try to check my article, it''s in french but the source at the end could help you for the structures/classes and the computations. It''s 3D but everything works the same in 2D, just a matter of vectors (and rendering).
http://www.programmationworld.com/site/cours.asp?Action=cours&numero=278
http://www.programmationworld.com/site/cours.asp?Action=cours&numero=278
AP (from the 14th): I know this is a dumb question, but how does one make water using a particle system. I just started making my own using a similar OO approach in DX, and I never even though about using it for water. I''m just looking for the general idea.
Thanks
Thanks
I''ve got a complete source code to a particle system i wrote about a year ago or something.. I could send it to you.. The thing is that it''s written in Java, but it would be quite easy to convert to C++..
Anyway, it''s all 2D and I got the inspiration or what you might call it to write that thingie when I visited Nehe''s OpenGL site and I simply rewrote his particle routine using Java. Things tend to be easier when you only have to think in 2 dimensions
Anyway, it''s all 2D and I got the inspiration or what you might call it to write that thingie when I visited Nehe''s OpenGL site and I simply rewrote his particle routine using Java. Things tend to be easier when you only have to think in 2 dimensions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement