Jump to content
  • Advertisement
Sign in to follow this  
fitfool

Particle system

This topic is 4090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, ive been wanting to add more realism to my newly-made rocket launcher and couldnt think of anything better than a particle engine. Ive searched all over the place and cant seem to find a good tutorial for beginners. Any suggestions? thanks, FitFool

Share this post


Link to post
Share on other sites
Advertisement
Does this help?

There are a ton of tutorials out there on particle systems. The first link that came up for me is codesampler, which seems pretty decent to me.

It really depends on how crazy you want to get with things. Since you are looking for something more basic, I am guessing that you are going to want to use something involving DirectX PointSprites.

Share this post


Link to post
Share on other sites
Yeah, i saw both of the tutorials on code sampler, but it didnt really help me. Im looking for more of a tutorial that goes over different types of particle systems, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by fitfool
Yeah, i saw both of the tutorials on code sampler, but it didnt really help me. Im looking for more of a tutorial that goes over different types of particle systems, etc.

Different types of particle systems? You mean ones that can handle a variety of things, from rain to smoke, to full 3D objects as particles? What got me obsessed with particle systems was a combination of the original Half-Life, and this article (free registration required, but its worth the hassle).

From my experience, all particle systems have a few things in common - they are all a bunch of small objects that need to be updated and rendered. What makes the difference between, say, rain and smoke, is how the update and the rendering is handled. For rain, you want to stretch the particle between it's current and previous position. For smoke, you want to have the particles start at a small size with a high alpha value, then make them grow in size and fade them out. That's where half the fun is with particle systems - seeing what you can do by using different textures and different values for color, size, and movement.

As for 3D particles (like having a variety of 3D models for different particles - like the Half-Life gibs (meat chunks) that are displayed when someone explodes - it is reasonably similar to a regular billboarded particle system, except rather than having a small billboarded particle, you need to handle your update for a 3D particle (collision detection and the like).

EDIT: this might be a good place to start.

EDIT2: The first link I posed is a bit dated, and it depends a bit on your implementation. I just found that the article gave me a good idea of what a good particle system is capable of doing. Either that, or look at pretty much any recent AAA commercial game (such as Half-Life, Oblivion, etc).

Share this post


Link to post
Share on other sites
I figured after reading a couple articles i'd try one myself but am having a couple problems, heres the source for were im making my particle, loading them and displaying them.



#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include <string>

#include "c_base_object.h"
#include "c_custom_vertex.h"
#include "c_custom_matrix.h"

class Smoke_Particle
{
private:
D3DXVECTOR3 Position;
D3DXVECTOR3 Velocity;

int Age;

bool FirstFrame;

D3D_CUSTOMMATRIX WorldMatrix;
public:
CUSTOMVERTEX Quad[4];

Smoke_Particle( void );

void Update( IDirect3DDevice9 *D3DDevice, D3DXVECTOR3 Origin );
void Init( void );
};




#pragma once
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <iostream>

#include "c_particle_system.h"

Smoke_Particle::Smoke_Particle( void )
{
FirstFrame = true;

Age = rand() % 40;

return;
}

void Smoke_Particle::Init( void )
{
D3DVECTOR NoNormal;

NoNormal.x = 0.0f;
NoNormal.y = 0.0f;
NoNormal.z = 0.0f;

CUSTOMVERTEX TempQuad[] =
{
{ 0.0f, 1.0f, 0.0f, NoNormal, 0, 1 },
{ 1.0f, 1.0f, 0.0f, NoNormal, 1, 1 },
{ 0.0f, 0.0f, 0.0f, NoNormal, 0, 0 },
{ 1.0f, 0.0f, 0.0f, NoNormal, 1, 0 },
};

Quad[0] = TempQuad[0];
Quad[1] = TempQuad[1];
Quad[2] = TempQuad[2];
Quad[3] = TempQuad[3];

return;
}

void Smoke_Particle::Update( IDirect3DDevice9 *D3DDevice, D3DXVECTOR3 Origin )
{
static int Random;

if( FirstFrame )
{
Position = Origin;
FirstFrame = false;
}

if( Age > 0 )
{
Random = rand() % 5;
Position.x += 0.000003f;//(float)(0.0 + (float)Random / 1000);
//Position.y += 0.01;//rand() / 4;
//Position.z += 0.01;//rand() / 2;

Age--;
}
else
{
Position.x = Origin.x;
Position.y = Origin.y;
Position.z = Origin.z;

Age = rand() / 30;
}

WorldMatrix.SetTranslate( Position.x, Position.y, Position.z );
WorldMatrix.SetFinal();
D3DDevice->SetTransform( D3DTS_WORLD, &WorldMatrix.Total );

return;
}







void Rocket_Launcher::InitParticles( IDirect3DDevice9 *D3DDevice )
{
int Count = 0;

srand( (int)time( NULL ) );

for( int X = 0; X < NUM_PARTICLES; X++ )
{
SmokeParticle[X].Init();
}

D3DDevice->CreateVertexBuffer( (NUM_PARTICLES * 4) * sizeof(CUSTOMVERTEX),
0,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED,
&SmokeParticleBuffer,
NULL );

CUSTOMVERTEX *MemPointer;

SmokeParticleBuffer->Lock( 0, sizeof(SmokeParticle[0]) * NUM_PARTICLES, (void**)&MemPointer, 0 );

for( int X = 0; X < NUM_PARTICLES; X += 4 )
{
memcpy( MemPointer + X, SmokeParticle[Count].Quad, sizeof(SmokeParticle[Count].Quad) );

Count++;
}

SmokeParticleBuffer->Unlock();

return;
}

void Rocket_Launcher::DrawParticles( IDirect3DDevice9 *D3DDevice )
{
D3DDevice->SetStreamSource( 0, SmokeParticleBuffer, 0, sizeof(CUSTOMVERTEX) );

for( int X = 0; X < NUM_PARTICLES; X += 4 )
{
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, X, 2 );
}

return;
}

void Rocket_Launcher::UpdateParticles( IDirect3DDevice9 *D3DDevice, D3DXVECTOR3 Origin )
{
for( int X = 0; X < NUM_PARTICLES; X++ )
{
SmokeParticle[X].Update( D3DDevice, Origin );
}

return;
}




For some reason, i am only see 1 particle, i think its because of how im loading all the particles into there vertex buffer.

Any suggestions?

thanks a-lot, FitFool

Share this post


Link to post
Share on other sites
SOLVED, it turned out that all my particles were being draw, but with the way i was translating them, they were all at the same exact position

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!