Thread: OpenGL Particle Engine Demo

  1. #1

    OpenGL Particle Engine Demo

    My first extremely basic demo! It just shows a brief particle engine. It shows 52 red particles move positively on the x and z axes, and then fade out when they get close to the screen. It is completely crappy, but I just hacked it together in like a half hour. No, I won't release source, because, as I said, it was a hack and I'd be embarrassed to show this crap.

    edit: If you're browser gets confused and thinks the filename is particle and not particle engine.zip, open it with a zip file thing-a-ma-bob

    PS: You need GLUT to get this to work.
    Last edited by frenchfry164; 11-24-2003 at 09:05 PM.

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Not really too much you can say about it WITHOUT the code...umm maybe good job ?
    Do not make direct eye contact with me.

  3. #3
    Code:
    #include <cstdlib>
    #include <ctime>
    #include "particle.h"
    #include <gl/gl.h>
    inline float FloatRand(float MaxVal)
    {
        return float(rand()%100)/((100/MaxVal)+0.1);
    }
    
    ParticleEffect::ParticleEffect(int no, float x, float y, float z, float size,
                                   float speedx, float speedy, float speedz, float life,
                                   float fade, float r, float g, float b, float a, float perm,
                                   bool forever)
    {
        srand(time(0));
        particles = new Particle[no];
        for (int i=0;i<no;i++)
        {
            particles[i].x = (x-(0.5*size))+FloatRand(size);
            particles[i].y = (y-(0.5*size))+FloatRand(size);
            particles[i].z = (z-(0.5*size))+FloatRand(size);
            particles[i].life = (life-(0.5*fade))+FloatRand(fade);
            particles[i].r = r;
            particles[i].g = g;
            particles[i].b = b;
            particles[i].a = a;
            particles[i].speedx = (speedx-(0.25*speedx))+FloatRand(0.25*speedx);
            particles[i].speedy = (speedy-(0.25*speedy))+FloatRand(0.25*speedy);
            particles[i].speedz = (speedz-(0.25*speedz))+FloatRand(0.25*speedz);
            particles[i].fade = (fade-(0.15*fade))+FloatRand(fade*0.15);
            particles[i].perimeter = perm;
        }
        count = no;
        endless = forever;
        this->x=x;
        this->y=y;
        this->z=z;
        this->life=life;
        this->fade=fade;
        this->size=size;
        this->r=r;
        this->g=g;
        this->b=b;
        this->a=a;
        this->speedx = speedx;
        this->speedy = speedy;
        this->speedz = speedz;
        this->perimeter = perimeter;
    }
    
    void ParticleEffect::Render()
    {
        for (int i=0;i<count;i++)
        {
            if (particles[i].life <= 0)
            {
                particles[i].x = (x-(0.5*size))+FloatRand(size);
                particles[i].y = (y-(0.5*size))+FloatRand(size);
                particles[i].z = (z-(0.5*size))+FloatRand(size);
            particles[i].life = (life-(0.5*fade))+FloatRand(fade);
            particles[i].r = r;
            particles[i].g = g;
            particles[i].b = b;
            particles[i].a = a;
            particles[i].speedx = (speedx-(0.5*speedx))+FloatRand(0.5*speedx);
            particles[i].speedy = (speedy-(0.5*speedy))+FloatRand(0.5*speedy);
            particles[i].speedz = (speedz-(0.5*speedz))+FloatRand(0.5*speedz);
            particles[i].fade = (fade-(fade))+FloatRand(fade);
            particles[i].perimeter = perimeter;
            }
            glBegin(GL_QUADS);  
                glColor4f(particles[i].r, particles[i].g, particles[i].b, particles[i].a + (particles[i].life/2));
                glVertex3f(particles[i].x - (particles[i].perimeter*0.5),
                           particles[i].y + (particles[i].perimeter*0.5), particles[i].z);
                glVertex3f(particles[i].x + (particles[i].perimeter*0.5),
                           particles[i].y + (particles[i].perimeter*0.5), particles[i].z);
                glVertex3f(particles[i].x + (particles[i].perimeter*0.5),
                           particles[i].y - (particles[i].perimeter*0.5), particles[i].z);
                glVertex3f(particles[i].x - (particles[i].perimeter*0.5),
                           particles[i].y - (particles[i].perimeter*0.5), particles[i].z);         
            glEnd();
            
            particles[i].life -= particles[i].fade;
            particles[i].x += particles[i].speedx;
            particles[i].y += particles[i].speedy;
            particles[i].z += particles[i].speedz;
        }
    }
    As you can see, it's a hack. It's extremely ugly. It makes me want to puke just seeing it.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> PS: You need GLUT to get this to work.


    Next time, include it with the package.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL terrain demo (EDITOR)
    By Jeremy G in forum Game Programming
    Replies: 2
    Last Post: 03-30-2003, 08:11 PM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  5. SkyLock graphics engine demo
    By jdinger in forum Game Programming
    Replies: 18
    Last Post: 06-26-2002, 07:58 AM