Back to index

kdeartwork  4.3.2
Public Member Functions | Private Attributes
particle Class Reference

List of all members.

Public Member Functions

 particle ()
 ~particle ()
float update (float *c)

Private Attributes

float ** vertices
short trails
short counter
float offset [3]

Detailed Description

Definition at line 117 of file Flux.cpp.


Constructor & Destructor Documentation

Definition at line 134 of file Flux.cpp.

{
    // Offsets are somewhat like default positions for the head of each
    // particle trail.  Offsets spread out the particle trails and keep
    // them from all overlapping.
    offset[0] = cos(PIx2 * float(whichparticle) / float(_fc->dParticles));
    offset[1] = float(whichparticle) / float(_fc->dParticles) - 0.5f;
    offset[2] = sin(PIx2 * float(whichparticle) / float(_fc->dParticles));
    whichparticle++;

    // Initialize memory and set initial positions out of view of the camera
    trails = _fc->dTrail;
    vertices = new float*[ trails ];

    int i;
    for(i=0; i<trails; i++)
    {
        vertices[i] = new float[5];  // 0,1,2 = position, 3 = hue, 4 = saturation
        vertices[i][0] = 0.0f;
        vertices[i][1] = 3.0f;
        vertices[i][2] = 0.0f;
        vertices[i][3] = 0.0f;
        vertices[i][4] = 0.0f;
    }

    counter = 0;
}

Definition at line 163 of file Flux.cpp.

{
    for(int i=0; i<trails; i++)
        delete[] vertices[i];
    delete[] vertices;
}

Member Function Documentation

float particle::update ( float *  c)

Definition at line 171 of file Flux.cpp.

{
    int i, p, growth;
    float rgb[3];
    float cx, cy, cz;  // Containment variables
    float luminosity;
    static float expander = 1.0f + 0.0005f * float(_fc->dExpansion);
    static float blower = 0.001f * float(_fc->dWind);
    //static float otherxyz[3];
    float depth = 0;

    // Record old position
    int oldc = counter;
    float oldpos[3];
    oldpos[0] = vertices[oldc][0];
    oldpos[1] = vertices[oldc][1];
    oldpos[2] = vertices[oldc][2];

    counter ++;
    if(counter >= _fc->dTrail)
        counter = 0;

    // Here's the iterative math for calculating new vertex positions
    // first calculate limiting terms which keep vertices from constantly
    // flying off to infinity
    cx = vertices[oldc][0] * (1.0f - 1.0f / (vertices[oldc][0] * vertices[oldc][0] + 1.0f));
    cy = vertices[oldc][1] * (1.0f - 1.0f / (vertices[oldc][1] * vertices[oldc][1] + 1.0f));
    cz = vertices[oldc][2] * (1.0f - 1.0f / (vertices[oldc][2] * vertices[oldc][2] + 1.0f));
    // then calculate new positions
    vertices[counter][0] = vertices[oldc][0] + c[6] * offset[0] - cx
        + c[2] * vertices[oldc][1]
        + c[5] * vertices[oldc][2];
    vertices[counter][1] = vertices[oldc][1] + c[6] * offset[1] - cy
        + c[1] * vertices[oldc][2]
        + c[4] * vertices[oldc][0];
    vertices[counter][2] = vertices[oldc][2] + c[6] * offset[2] - cz
        + c[0] * vertices[oldc][0]
        + c[3] * vertices[oldc][1];

    // Pick a hue
    vertices[counter][3] = cx * cx + cy * cy + cz * cz;
    if(vertices[counter][3] > 1.0f)
        vertices[counter][3] = 1.0f;
    vertices[counter][3] += c[7];
    // Limit the hue (0 - 1)
    if(vertices[counter][3] > 1.0f)
        vertices[counter][3] -= 1.0f;
    if(vertices[counter][3] < 0.0f)
        vertices[counter][3] += 1.0f;
    // Pick a saturation
    vertices[counter][4] = c[0] + vertices[counter][3];
    // Limit the saturation (0 - 1)
    if(vertices[counter][4] < 0.0f)
        vertices[counter][4] = -vertices[counter][4];
    vertices[counter][4] -= float(int(vertices[counter][4]));
    vertices[counter][4] = 1.0f - (vertices[counter][4] * vertices[counter][4]);

    // Bring particles back if they escape
    if(!counter){
        if((vertices[0][0] > 1000000000.0f) || (vertices[0][0] < -1000000000.0f)
            || (vertices[0][1] > 1000000000.0f) || (vertices[0][1] < -1000000000.0f)
            || (vertices[2][2] > 1000000000.0f) || (vertices[0][2] < -1000000000.0f)){
            vertices[0][0] = myRandf(2.0f) - 1.0f;
            vertices[0][1] = myRandf(2.0f) - 1.0f;
            vertices[0][2] = myRandf(2.0f) - 1.0f;
        }
    }

    // Draw every vertex in particle trail
    p = counter;
    growth = 0;
    luminosity = _fc->lumdiff;
    for(i=0; i<_fc->dTrail; i++){
        p ++;
        if(p >= _fc->dTrail)
            p = 0;
        growth++;

        // assign color to particle
        hsl2rgb(vertices[p][3], vertices[p][4], luminosity, rgb[0], rgb[1], rgb[2]);
        glColor3fv(rgb);

        glPushMatrix();
        if(_fc->dGeometry == 1)  // Spheres
            glTranslatef(vertices[p][0], vertices[p][1], vertices[p][2]);
        else{  // Points or lights
            depth = _fc->cosCameraAngle * vertices[p][2] - _fc->sinCameraAngle * vertices[p][0];
            glTranslatef(_fc->cosCameraAngle * vertices[p][0] + _fc->sinCameraAngle
                * vertices[p][2], vertices[p][1], depth);
        }
        if(_fc->dGeometry){  // Spheres or lights
            switch(_fc->dTrail - growth){
            case 0:
                glScalef(0.259f, 0.259f, 0.259f);
                break;
            case 1:
                glScalef(0.5f, 0.5f, 0.5f);
                break;
            case 2:
                glScalef(0.707f, 0.707f, 0.707f);
                break;
            case 3:
                glScalef(0.866f, 0.866f, 0.866f);
                break;
            case 4:
                glScalef(0.966f, 0.966f, 0.966f);
            }
        }
        switch(_fc->dGeometry){
        case 0:  // Points
            switch(_fc->dTrail - growth){
            case 0:
                glPointSize(float(_fc->dSize * (depth + 200.0f) * 0.001036f));
                break;
            case 1:
                glPointSize(float(_fc->dSize * (depth + 200.0f) * 0.002f));
                break;
            case 2:
                glPointSize(float(_fc->dSize * (depth + 200.0f) * 0.002828f));
                break;
            case 3:
                glPointSize(float(_fc->dSize * (depth + 200.0f) * 0.003464f));
                break;
            case 4:
                glPointSize(float(_fc->dSize * (depth + 200.0f) * 0.003864f));
                break;
            default:
                glPointSize(float(_fc->dSize * (depth + 200.0f) * 0.004f));
            }
            glBegin(GL_POINTS);
                glVertex3f(0.0f,0.0f,0.0f);
            glEnd();
            break;
        case 1:  // Spheres
        case 2:  // Lights
            glCallList(1);
        }
        glPopMatrix();
        vertices[p][0] *= expander;
        vertices[p][1] *= expander;
        vertices[p][2] *= expander;
        vertices[p][2] += blower;
        luminosity += _fc->lumdiff;
    }

    // Find distance between new position and old position and return it
    oldpos[0] -= vertices[counter][0];
    oldpos[1] -= vertices[counter][1];
    oldpos[2] -= vertices[counter][2];
    return(float(sqrt(oldpos[0] * oldpos[0] + oldpos[1] * oldpos[1] + oldpos[2] * oldpos[2])));
}

Here is the call graph for this function:


Member Data Documentation

short particle::counter [private]

Definition at line 129 of file Flux.cpp.

float particle::offset[3] [private]

Definition at line 130 of file Flux.cpp.

short particle::trails [private]

Definition at line 128 of file Flux.cpp.

float** particle::vertices [private]

Definition at line 127 of file Flux.cpp.


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