Back to index

kdeartwork  4.3.2
Public Member Functions | Public Attributes
wind Class Reference
Collaboration diagram for wind:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 wind ()
 ~wind ()
void update ()

Public Attributes

Emitteremitters
Particleparticles
int ** linelist
int * lastparticle
int whichparticle
int partCount
int emitCount
bool useLines
float c [NUMCONSTS]
float ct [NUMCONSTS]
float cv [NUMCONSTS]

Detailed Description

Definition at line 65 of file SolarWinds.cpp.


Constructor & Destructor Documentation

Definition at line 87 of file SolarWinds.cpp.

{
    int i;

    partCount = _ec->dParticles;
    emitCount = _ec->dEmitters;
    useLines  = (_ec->dGeometry == 2);

    emitters = new Emitter[emitCount];
    for(i=0; i<emitCount; i++)
    {
        emitters[i].x = myRandf(60.0f) - 30.0f;
        emitters[i].y = myRandf(60.0f) - 30.0f;
        emitters[i].z = myRandf(30.0f) - 15.0f;
    }

    particles = new Particle[partCount];
    for(i=0; i<partCount; i++)
    {
        particles[i].x = 0.0f;
        particles[i].y = 0.0f;
        particles[i].z = 100.0f;  // start particles behind viewer
    }

    whichparticle = 0;

    if( useLines )
    {
        linelist = new int*[partCount];
        for(i=0; i<partCount; i++)
        {
            linelist[i] = new int[2];
            linelist[i][0] = -1;
            linelist[i][1] = -1;
        }
        lastparticle = new int[emitCount];
        for(i=0; i<emitCount; i++)
            lastparticle[i] = i;
    }

    float windspeed = (float) (_ec->dWindspeed);
    for(i=0; i<NUMCONSTS; i++)
    {
        ct[i] = myRandf(PIx2);
        cv[i] = myRandf(0.00005f * windspeed * windspeed)
                + 0.00001f * windspeed * windspeed;
        //printf( "KR ct %g cv %g\n", ct[i], cv[i] );
    }
}

Here is the call graph for this function:

Definition at line 138 of file SolarWinds.cpp.

{
    delete[] emitters;
    delete[] particles;

    if( useLines )
    {
        int i;
        for(i=0; i<partCount; i++)
            delete[] linelist[i];
        delete[] linelist;
        delete[] lastparticle;
    }
}

Member Function Documentation

void wind::update ( )

Definition at line 154 of file SolarWinds.cpp.

{
    int i;
    float x, y, z;
    float temp;
    float particleSpeed = (float) _ec->dParticlespeed;

    float evel = float(_ec->dEmitterspeed) * 0.01f;
    float pvel = particleSpeed * 0.01f;
    float pointsize = 0.04f * _ec->dSize;
    float linesize = 0.005f * _ec->dSize;

    // update constants
    for(i=0; i<NUMCONSTS; i++)
    {
        ct[i] += cv[i];
        if(ct[i] > PIx2)
            ct[i] -= PIx2;
        c[i] = cos(ct[i]);
    }

    // calculate emissions
    for(i=0; i<emitCount; i++)
    {
        emitters[i].z += evel;  // emitter moves toward viewer
        if(emitters[i].z > 15.0f)
        {
            // reset emitter
            emitters[i].x = myRandf(60.0f) - 30.0f;
            emitters[i].y = myRandf(60.0f) - 30.0f;
            emitters[i].z = -15.0f;
        }

        particles[whichparticle].x = emitters[i].x;
        particles[whichparticle].y = emitters[i].y;
        particles[whichparticle].z = emitters[i].z;

        if( useLines )
        {
            // link particles to form lines
            if(linelist[whichparticle][0] >= 0)
                linelist[linelist[whichparticle][0]][1] = -1;
            linelist[whichparticle][0] = -1;
            if(emitters[i].z == -15.0f)
                linelist[whichparticle][1] = -1;
            else
                linelist[whichparticle][1] = lastparticle[i];
            linelist[lastparticle[i]][0] = whichparticle;
            lastparticle[i] = whichparticle;
        }

        whichparticle++;
        if(whichparticle >= partCount)
            whichparticle = 0;
    }

    // calculate particle positions and colors
    // first modify constants that affect colors
    c[6] *= 9.0f / particleSpeed;
    c[7] *= 9.0f / particleSpeed;
    c[8] *= 9.0f / particleSpeed;
    // then update each particle
    for(i=0; i<partCount; i++)
    {
        Particle* part = particles + i;

        // store old positions
        x = part->x;
        y = part->y;
        z = part->z;

        // make new positins
        part->x = x + (c[0] * y + c[1] * z) * pvel;
        part->y = y + (c[2] * z + c[3] * x) * pvel;
        part->z = z + (c[4] * x + c[5] * y) * pvel;

        // calculate colors
        part->r = fabs((part->x - x) * c[6]);
        part->g = fabs((part->y - y) * c[7]);
        part->b = fabs((part->z - z) * c[8]);

        // clamp colors
        if( part->r > 1.0f )
            part->r = 1.0f;
        if( part->g > 1.0f )
            part->g = 1.0f;
        if( part->b > 1.0f )
            part->b = 1.0f;
    }

    // draw particles
    switch(_ec->dGeometry)
    {
    case 0:  // lights
        for(i=0; i<partCount; i++)
        {
            glColor3fv(&particles[i].r);
            glPushMatrix();
                glTranslatef(particles[i].x, particles[i].y, particles[i].z);
                glCallList(1);
            glPopMatrix();
#if 0
            if( i == 0 )
                printf( "KR %d %g %g %g\n", i,
                    particles[i].x, particles[i].y, particles[i].z);
#endif
        }
        break;

    case 1:  // points
        for(i=0; i<partCount; i++)
        {
            temp = particles[i].z + 40.0f;
            if(temp < 0.01f)
                temp = 0.01f;
            glPointSize(pointsize * temp);

            glBegin(GL_POINTS);
                glColor3fv(&particles[i].r);
                glVertex3fv(&particles[i].x);
            glEnd();
        }
        break;

    case 2:  // lines
        for(i=0; i<partCount; i++)
        {
            temp = particles[i].z + 40.0f;
            if(temp < 0.01f)
                temp = 0.01f;
            glLineWidth(linesize * temp);

            glBegin(GL_LINES);
            if(linelist[i][1] >= 0)
            {
                glColor3fv(&particles[i].r);
                if(linelist[i][0] == -1)
                    glColor3f(0.0f, 0.0f, 0.0f);
                glVertex3fv(&particles[i].x);

                glColor3fv(&particles[linelist[i][1]].r);
                if(linelist[linelist[i][1]][1] == -1)
                    glColor3f(0.0f, 0.0f, 0.0f);
                glVertex3fv(&particles[linelist[i][1]].x);
            }
            glEnd();
        }
    }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 81 of file SolarWinds.cpp.

Definition at line 82 of file SolarWinds.cpp.

Definition at line 83 of file SolarWinds.cpp.

Definition at line 79 of file SolarWinds.cpp.

Definition at line 73 of file SolarWinds.cpp.

Definition at line 76 of file SolarWinds.cpp.

Definition at line 75 of file SolarWinds.cpp.

Definition at line 78 of file SolarWinds.cpp.

Definition at line 74 of file SolarWinds.cpp.

Definition at line 80 of file SolarWinds.cpp.

Definition at line 77 of file SolarWinds.cpp.


The documentation for this class was generated from the following file: