#include "cFireflyParticle.h"

#include "cCloudParticle.h"

#include "cSplashParticle.h"

cFireflyParticle::cFireflyParticle(cParticleSystem* ps) : cParticle(ps)
{
    float a = ((float)(rand()%100))/100.0f;
    float b = ((float)(rand()%100))/100.0f;
    float c = ((float)(rand()%100))/100.0f;
    uniqueness_ = b * 585 + c*52 + a *34;
    
    if(a > .5) dir_ = 1; else dir_ = -.8;
    origin_ = cVector((a-.5)*5, (b-.5)*5, (c-.5)*5) + cVector(0,0,-20);
}

void cFireflyParticle::update(float dt, vector<cTriangle*>& tlist)
{
    age_ += dt * .1 * dir_; 
    position_ =   cVector( 50 * cos(age_*4.213552 + uniqueness_ + sin(age_*2.42 +uniqueness_)) +  20 *sin(age_*2.657 + uniqueness_*3 + 52), 
                  25 + 5 *sin(age_*3 + uniqueness_ + 252) + 3 * cos(age_ + uniqueness_ * 7 + 4), 
                  50 *  cos(age_*2.24 + uniqueness_ + 512 + cos(age_+uniqueness_)) )
                  
                  + 
                  
                  3 * cVector( cos(age_*4.213552 + uniqueness_ + sin(age_)), 
                                 cos(age_*2.24 + uniqueness_ + 512 + cos(age_+uniqueness_)) + 5, 
                                 cos(age_*3 + uniqueness_ + 252))
                
                    + origin_;
                 
                  
             
}

    
void cFireflyParticle::draw()
{	
    float xscale = 1;
    float yscale = 1;
    float zscale = 1;
    
    
    glColor4f(0,1,0, .5 + .5 * cos(age_*15 + cos(age_*10 + uniqueness_ + 252) + uniqueness_*234) );
    
    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();
}

