Sign in to follow this  
robococ

particle system - fire

Recommended Posts

robococ    100
Based on nehe tutorial: [url="http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19"]http://nehe.gamedev....n.asp?lesson=19[/url]
I would like to make fire - observer CAN ROTATE fire - If I use nehe coordinates to create square with texture:
[code]
glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z);
glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z);
glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z);
glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z);
[/code]

Fire looks horrible when I rotate square about 90 degrees - it looks flat:
[url="http://img573.imageshack.us/i/33884504.jpg/"]http://img573.images...i/33884504.jpg/[/url]

When I change coordinates square with texture to mine:
[code]
glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z);
glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z);
glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z);
glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z);
[/code]

Fire looks also bad:
[url="http://img69.imageshack.us/i/62229027.jpg/"]http://img69.imagesh...i/62229027.jpg/[/url]

Do you have an idea what I can do ?

This is mine code:
[code]
#define MAX_PARTICLES 1000 // Number Of Particles To Create

float slowdown=2.0f; // Slow Down Particles
float xspeed; // Base X Speed (To Allow Keyboard Direction Of Tail)
float yspeed; // Base Y Speed (To Allow Keyboard Direction Of Tail)
float zoom=-40.0f; // Used To Zoom Out

typedef struct // Create A Structure For Particle
{
bool active; // Active (Yes/No)
float life; // Particle Life
float fade; // Fade Speed
float r; // Red Value
float g; // Green Value
float b; // Blue Value
float x; // X Position
float y; // Y Position
float z; // Z Position
float xi; // X Direction
float yi; // Y Direction
float zi; // Z Direction
float xg; // X Gravity
float yg; // Y Gravity
float zg; // Z Gravity
}
particles; // Particles Structure

particles particle[MAX_PARTICLES]; // Particle Array (Room For Particle Info)

static GLfloat colors[12][3]= // Rainbow Of Colors
{
{1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f},
{1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f},
{1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f}, {1.0f,0.2f,0.0f},
};


//INICIALIZATION:
Init(void)
{
slowdown = 2; // Slow Down Particles
xspeed = 0; // Base X Speed (To Allow Keyboard Direction Of Tail)
yspeed = 200; // Base Y Speed (To Allow Keyboard Direction Of Tail)
zoom = -40; // Used To Zoom Out

for (int loop=0; loop<MAX_PARTICLES; loop++) // Initials All The Textures
{
particle[loop].active = true; // Make All The Particles Active
particle[loop].life = 1.0f; // Particles Life
particle[loop].fade = float(rand()%100)/1000.0f+0.003f; // Random Fade Speed
particle[loop].x = 0.0f; // Center On X Axis
particle[loop].y = 0.0f; // Center On Y Axis
particle[loop].z = 0.0f; // Center On Z Axis
particle[loop].r = colors[loop*(12/MAX_PARTICLES)][0]; // Select Rainbow Color
particle[loop].g = colors[loop*(12/MAX_PARTICLES)][1]; // Select Rainbow Color
particle[loop].b = colors[loop*(12/MAX_PARTICLES)][2]; // Select Rainbow Color
particle[loop].xi = xspeed+float((rand()%60)-32.0f); // X Axis Speed And Direction
particle[loop].yi = yspeed+float((rand()%60)-30.0f); // Y Axis Speed And Direction
particle[loop].zi = float((rand()%60)-30.0f); // Z Axis Speed And Direction
particle[loop].xg = 0.0f; // Set Horizontal Pull To Zero
particle[loop].yg = -0.8f; // Set Vertical Pull Downward
particle[loop].zg = 0.0f; // Set Pull On Z Axis To Zero
}
}


//FIRE:
void Scene::DrawFire()
{
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);


for (int loop=0; loop<MAX_PARTICLES; loop++) // Loop Through All The Particles
{
if (particle[loop].active) // If The Particle Is Active
{
float x = particle[loop].x; // Grab Our Particle X Position
float y = particle[loop].y; // Grab Our Particle Y Position
float z = particle[loop].z + zoom; // Particle Z Pos + Zoom

// Draw The Particle Using Our RGB Values, Fade The Particle Based On It's Life
glColor4f(particle[loop].r, particle[loop].g, particle[loop].b, particle[loop].life);

glPushMatrix();
glBegin(GL_TRIANGLE_STRIP);
//MINE COORDINATES:
glTexCoord2d(1,1); glVertex3f(x+5, y, z+5);
glTexCoord2d(0,1); glVertex3f(x-5, y, z+5);
glTexCoord2d(0,0); glVertex3f(x+5, y, z-5);
glTexCoord2d(1,0); glVertex3f(x-5, y, z-5);
/*
//nehe COORDINATES:
glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z);
glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z);
glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z);
glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z);
*/
glEnd();
glPopMatrix();

particle[loop].x += particle[loop].xi/(slowdown*1000); // Move On The X Axis By X Speed
particle[loop].y += particle[loop].yi/(slowdown*1000); // Move On The Y Axis By Y Speed
particle[loop].z += particle[loop].zi/(slowdown*1000); // Move On The Z Axis By Z Speed

particle[loop].xi += particle[loop].xg; // Take Pull On X Axis Into Account
particle[loop].yi += particle[loop].yg; // Take Pull On Y Axis Into Account
particle[loop].zi += particle[loop].zg; // Take Pull On Z Axis Into Account
particle[loop].life -= particle[loop].fade; // Reduce Particles Life By 'Fade'

if (particle[loop].life<0.0f) // If Particle Is Burned Out
{
int column = rand()%12;

particle[loop].life = 1.0f; // Give It New Life
particle[loop].fade = float(rand()%100)/1000.0f+0.003f; // Random Fade Value
particle[loop].x = 0.0f; // Center On X Axis
particle[loop].y = 0.0f; // Center On Y Axis
particle[loop].z = 0.0f; // Center On Z Axis
particle[loop].xi = xspeed+float((rand()%60)-32.0f); // X Axis Speed And Direction
particle[loop].yi = yspeed+float((rand()%60)-30.0f); // Y Axis Speed And Direction
particle[loop].zi = float((rand()%60)-30.0f); // Z Axis Speed And Direction
particle[loop].r = colors[column][0]; // Select Red From Color Table
particle[loop].g = colors[column][1]; // Select Green From Color Table
particle[loop].b = colors[column][2]; // Select Blue From Color Table
}
}
}

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
[/code]

This is texture: [url="http://img13.imageshack.us/i/particle.png/"]http://img13.imagesh...i/particle.png/[/url]

Share this post


Link to post
Share on other sites
SuperVGA    1132
You need to direct the quads to have their normal pointing towards the eye, so that the surface is always orthogonal to the view vector.
These are billboards; they should act like classic sprites.

You can rotate them in a vertex shader, or rotate a local model matrix of one, repeated quad.
Also, pick a different texture, and apply rotation to it over time, -that should help!

Share this post


Link to post
Share on other sites
robococ    100
So I should do something like that:

[code]
glPushMatrix();

// HERE ROTATION ??????

glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z);
glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z);
glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z);
glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z);
glEnd();
glPopMatrix();
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this