#include "cSmokeRingParticle.h"

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

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

    
void cSmokeRingParticle::draw()
{	
    float xscale = .2 - .2 *  age_/10;
    float yscale = .2 - .2 *  age_/10;
    float zscale = .2 - .2 *  age_/10;
    
    
    glColor4f(1,1,1, .2 -.1 *  age_/10  );
    
    glBegin(GL_TRIANGLE_STRIP);						// Build Quad From A Triangle Strip
        glTexCoord2d(1,1); glVertex3f(position_.x_+xscale, position_.y_+yscale, position_.z_); // Top Right
        glTexCoord2d(0,1); glVertex3f(position_.x_-xscale, position_.y_+yscale, position_.z_); // Top Left
        glTexCoord2d(1,0); glVertex3f(position_.x_+xscale, position_.y_-yscale, position_.z_); // Bottom Right
        glTexCoord2d(0,0); glVertex3f(position_.x_-xscale, position_.y_-yscale, position_.z_); // Bottom Left
    glEnd();
    
    glBegin(GL_TRIANGLE_STRIP);						// Build Quad From A Triangle Strip
        glTexCoord2d(1,1); glVertex3f(position_.x_, position_.y_+yscale, position_.z_+zscale); // Top Right
        glTexCoord2d(0,1); glVertex3f(position_.x_, position_.y_+yscale, position_.z_-zscale); // Top Left
        glTexCoord2d(1,0); glVertex3f(position_.x_, position_.y_-yscale, position_.z_+zscale); // Bottom Right
        glTexCoord2d(0,0); glVertex3f(position_.x_, position_.y_-yscale, position_.z_-zscale); // Bottom Left
    glEnd();
    
    glPopMatrix();
}


