#include "cCloudParticle.h"

#include "cSplashParticle.h"

cCloudParticle::cCloudParticle(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 * 1000 + c;
    float r = a;
    float theta = b * 100;
    
    origin_ = cVector( r * cos(theta), b * .1, r*sin(theta) );
}

void cCloudParticle::update(float dt, vector<cTriangle*>& tlist)
{
    age_ += dt * .1; 
    position_ = ps_->cloudCenter_ + ps_->cloudRadius_ * origin_ + 
                    3 * cVector( cos(age_*4.213552 + uniqueness_ + sin(age_)), 
                                 cos(age_*2.24 + uniqueness_ + 512 + cos(age_+uniqueness_)), 
                                 cos(age_*3 + uniqueness_ + 252));
             
                                                                
    if(ps_->raindrops_.size() < 200 && rand()%50 == 1)
    {
        cRaindrop* r = ps_->addRaindrop();
        r->position_ = position_ + cVector(0,-3,0);
    }
}
    
void cCloudParticle::draw()
{	
    float xscale = 2 * cos(age_*4.52 + uniqueness_*2341) + 3;
    float yscale = 2 * sin(age_*3 + 532825 + uniqueness_*23) + 3;
    float zscale = 2 * cos(age_*2 + 65 + uniqueness_*324) * sin(age_ + uniqueness_ + cos(age_)) + 3;
    
    
    glColor4f(1,1,1, .4 + .2 * cos(age_ + uniqueness_) );
    
    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();
}
