#include "cSplashParticle.h"


cSplashParticle::cSplashParticle(cParticleSystem* ps) : cParticle(ps) { }


void cSplashParticle::update(float dt)
{
    age_ += dt;
    if(age_ > 5) {dead_ = true; return; }
    
    cVector g(0, -30, 0);
    position_ += velocity_ * dt;
    velocity_ += g * dt;
}
    
void cSplashParticle::draw()
{	
    float scale = 2 - 2 * (age_/5);
    
    glColor4f(1, .2, .2, .1 );
    
    // 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();

}
