#include "cSnowParticle.h"

cSnowParticle::cSnowParticle(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;
	position_ = cVector( (a-.5) * 450, 200, (b-.5)* 450);
	velocity_ = cVector(0,-.1,0);
	size_ = .5 + b;
    uniqueness_ = rand()%1000;
}

void cSnowParticle::update(float dt)
{
    
    age_ += dt;
	if(position_.y_ < -50) { dead_ = true; return; }
    position_ += dt * velocity_;
    
    velocity_ *= .99;
    
    velocity_ += .2 * cVector(cos(age_ + uniqueness_ + sin(age_*3 + uniqueness_)), cos(age_*1.231 + uniqueness_*3), cos(age_*1.231 + uniqueness_*3)*cos(age_*12.231 + uniqueness_*5)) + cVector(0,-.1,0);
}

    
void cSnowParticle::draw()
{	
    float scale = size_;

    glColor4f(1,1,1, .8  );

    // 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();
}


