Cool Particle Explosion
This is my first time with particles, and ive ran into a wall. When i finally finished coding my project, it ran, and nothing displayed on the screen. Then i wanted to see if my loop to display particles was the problem, so i drew a Triangle_strip to see if it would show up...it didn''t. Could someone help, ive been trying to fix this for 3 days. You can download it at my website.
My site(under construction but still viewable)
http://www.geocities.com/habitat14222/home.html
My site(under construction but still viewable)http://www.geocities.com/habitat14222/home.html
I got it working.
There were several mistakes.
First of all, if you didn''t see your triangle strip test that was because you have to set a color before drawing it, something like : glColor3f(1.f, 1.f, 1.f);
Then you have some difficulties with managing particles.
The biggest error you''ve done is declaring :
in the InitializeOpenGL function !!!!!
That is, the Explosion variable is local, thus when you leave the function all particle initialization is lost.
The solutiuon is very simple : remove the declaration in the InitializeOpenGL function, and keep the declaration in Particle.h and main.cpp .
As far as I''ve seen, all the GL-related code is correct, in theory... in practice there is a problem while calling glColor : the colours that you store are (255, 50, 0) but you call glColor4f !!! If your color values range between 0 and 255, you should call glColor4ub, but then there''s a problem with the alpha channel because the alpha channel is life which is a floating value that ranges between 0 and 1. So I consider you to store clamped floating values for your colors and then keep glColor4f :
The only other GL-related problem is due to ordering vertexes/vertices in the GL_TRIANGLE_STRIP begin-end pair.
Your triangles are crossed. You should either switch the 3rd and 4th coordinates of each strip OR you should replace the token GL_TRIANGLE_STRIP by GL_QUADS since there are only 2 triangles in each strip.
The last I have to say is that you should tweak your particle parameters.
With current parameters your particles will be too small and will move too fast. The result is that you won''t see alot of things, and you will only see it for a few tenths of a second !
From where the camera is, the particles are too small so you should either move the camera a bit closer, or you should set a bigger size for your particles.
And the particles move too fast and disappear too quickly. You should not set Explosion[j].yg greater than 0.5 (I recommend 0.2), you should not set Explosion[j].destroy greater than 0.01 and not lower than 0.00001 (I recommend ((rand() % 100)/10000.0f) + .001f) and you should allow negatives speeds, for instance :
hope this helps !
There were several mistakes.
First of all, if you didn''t see your triangle strip test that was because you have to set a color before drawing it, something like : glColor3f(1.f, 1.f, 1.f);
Then you have some difficulties with managing particles.
The biggest error you''ve done is declaring :
Particle Explosion[MAX_PARTICLES];
in the InitializeOpenGL function !!!!!
That is, the Explosion variable is local, thus when you leave the function all particle initialization is lost.
The solutiuon is very simple : remove the declaration in the InitializeOpenGL function, and keep the declaration in Particle.h and main.cpp .
As far as I''ve seen, all the GL-related code is correct, in theory... in practice there is a problem while calling glColor : the colours that you store are (255, 50, 0) but you call glColor4f !!! If your color values range between 0 and 255, you should call glColor4ub, but then there''s a problem with the alpha channel because the alpha channel is life which is a floating value that ranges between 0 and 1. So I consider you to store clamped floating values for your colors and then keep glColor4f :
// In InitializeOpenGL : Explosion[j].r = 255 / 255.f; Explosion[j].g = 50 / 255.f; Explosion[j].b = 0 / 255.f;
The only other GL-related problem is due to ordering vertexes/vertices in the GL_TRIANGLE_STRIP begin-end pair.
Your triangles are crossed. You should either switch the 3rd and 4th coordinates of each strip OR you should replace the token GL_TRIANGLE_STRIP by GL_QUADS since there are only 2 triangles in each strip.
The last I have to say is that you should tweak your particle parameters.
With current parameters your particles will be too small and will move too fast. The result is that you won''t see alot of things, and you will only see it for a few tenths of a second !
From where the camera is, the particles are too small so you should either move the camera a bit closer, or you should set a bigger size for your particles.
And the particles move too fast and disappear too quickly. You should not set Explosion[j].yg greater than 0.5 (I recommend 0.2), you should not set Explosion[j].destroy greater than 0.01 and not lower than 0.00001 (I recommend ((rand() % 100)/10000.0f) + .001f) and you should allow negatives speeds, for instance :
Explosion[j].xv = ((rand() % 15-7)/10.0f); Explosion[j].yv = ((rand() % 15-1)/10.0f); Explosion[j].zv = ((rand() % 15-7)/10.0f);
hope this helps !
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement