#include "cSmokeRingParticle.h"

cSmokeRingParticle::cSmokeRingParticle(cParticleSystem* ps) : cParticle(ps) 
{
    uniqueness_ = rand()%1000;
}

void cSmokeRingParticle::update(float dt)
{
    
    age_ += dt;
    if(age_ > maxAge_) {dead_ = true; return; }
    position_ += velocity_;
    
    velocity_ *= .99;
    
    float a = ((float)(rand()%100))/100.0f;
    float b = ((float)(rand()%100))/100.0f;
    float c = ((float)(rand()%100))/100.0f;
    velocity_ += .01 * (age_/maxAge_) * (age_/maxAge_) * cVector(a-.5, b-.4, c-.5);
}

    
void cSmokeRingParticle::draw()
{	
    float scale = size_ - size_ *  age_/maxAge_;

    glColor4f(r_,g_,b_, .2 -.2 *  age_/maxAge_  );

    // billboard
    float matrix[16];
    glPushMatrix();
    glTranslatef(position_.x_, position_.y_, position_.z_);
    glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
    matrix[0]=1.0; matrix[1] = 0.0; matrix[2] = 0.0;
    matrix[4]=0.0; matrix[5] = 1.0; matrix[6] = 0.0;
    matrix[8]=0.0; matrix[9] = 0.0; matrix[10] = 1.0;
    glLoadMatrixf(matrix);
    
    glBegin(GL_TRIANGLE_STRIP);						// Build Quad From A Triangle Strip
        glTexCoord2d(1,1); glVertex3f(scale, scale, 0); // Top Right
        glTexCoord2d(0,1); glVertex3f(-scale, scale, 0); // Top Left
        glTexCoord2d(1,0); glVertex3f(scale, -scale, 0); // Bottom Right
        glTexCoord2d(0,0); glVertex3f(-scale, -scale, 0); // Bottom Left
    glEnd();
    
    glPopMatrix();

    

}


