Back to index

kdeartwork  4.3.2
Public Member Functions | Public Attributes
wisp Class Reference

List of all members.

Public Member Functions

 wisp ()
 ~wisp ()
void update ()
void draw ()
void drawAsBackground ()

Public Attributes

int density
float *** vertices
float c [NUMCONSTS]
float cr [NUMCONSTS]
float cv [NUMCONSTS]
float hsl [3]
float rgb [3]
float hueSpeed
float saturationSpeed

Detailed Description

Definition at line 210 of file Euphoria.cpp.


Constructor & Destructor Documentation

Definition at line 233 of file Euphoria.cpp.

{
       int i, j;
       float recHalfDens = 1.0f / (float(_ec->dDensity) * 0.5f);

    density = _ec->dDensity;
       vertices = new float**[density+1];
       for(i=0; i<=density; i++)
    {
              vertices[i] = new float*[density+1];
              for(j=0; j<=density; j++)
        {
                     vertices[i][j] = new float[7];
                     vertices[i][j][3] = float(i) * recHalfDens - 1.0f;  // x position on grid
                     vertices[i][j][4] = float(j) * recHalfDens - 1.0f;  // y position on grid
                     // distance squared from the center
                     vertices[i][j][5] = vertices[i][j][3] * vertices[i][j][3]
                            + vertices[i][j][4] * vertices[i][j][4];
                     vertices[i][j][6] = 0.0f;  // intensity
              }
       }

       // initialize constants
       for(i=0; i<NUMCONSTS; i++)
    {
              c[i] = myRandf(2.0f) - 1.0f;
              cr[i] = myRandf(PIx2);
              cv[i] = myRandf(_ec->dSpeed * 0.03f) + (_ec->dSpeed * 0.001f);
       }

       // pick color
       hsl[0] = myRandf(1.0f);
       hsl[1] = 0.1f + myRandf(0.9f);
       hsl[2] = 1.0f;
       hueSpeed = myRandf(0.1f) - 0.05f;
       saturationSpeed = myRandf(0.04f) + 0.001f;
}

Here is the call graph for this function:

Definition at line 272 of file Euphoria.cpp.

{
       int i, j;

       for(i=0; i<=density; i++)
    {
              for(j=0; j<=density; j++)
        {
                     delete[] vertices[i][j];
              }
              delete[] vertices[i];
       }
       delete[] vertices;
}

Member Function Documentation

void wisp::draw ( )

Definition at line 359 of file Euphoria.cpp.

{
       int i, j;

       glPushMatrix();

       if(_ec->dWireframe)
    {
              for(i=1; i<density; i++){
                     glBegin(GL_LINE_STRIP);
                     for(j=0; j<=density; j++){
                            glColor3f(rgb[0] + vertices[i][j][6] - 1.0f, rgb[1] + vertices[i][j][6] - 1.0f, rgb[2] + vertices[i][j][6] - 1.0f);
                            glTexCoord2d(vertices[i][j][3] - vertices[i][j][0], vertices[i][j][4] - vertices[i][j][1]);
                            glVertex3fv(vertices[i][j]);
                     }
                     glEnd();
              }
              for(j=1; j<density; j++){
                     glBegin(GL_LINE_STRIP);
                     for(i=0; i<=density; i++){
                            glColor3f(rgb[0] + vertices[i][j][6] - 1.0f, rgb[1] + vertices[i][j][6] - 1.0f, rgb[2] + vertices[i][j][6] - 1.0f);
                            glTexCoord2d(vertices[i][j][3] - vertices[i][j][0], vertices[i][j][4] - vertices[i][j][1]);
                            glVertex3fv(vertices[i][j]);
                     }
                     glEnd();
              }
       }
       else
    {
              for(i=0; i<density; i++){
                     glBegin(GL_TRIANGLE_STRIP);
                            for(j=0; j<=density; j++){
                                   glColor3f(rgb[0] + vertices[i+1][j][6] - 1.0f, rgb[1] + vertices[i+1][j][6] - 1.0f, rgb[2] + vertices[i+1][j][6] - 1.0f);
                                   glTexCoord2d(vertices[i+1][j][3] - vertices[i+1][j][0], vertices[i+1][j][4] - vertices[i+1][j][1]);
                                   glVertex3fv(vertices[i+1][j]);
                                   glColor3f(rgb[0] + vertices[i][j][6] - 1.0f, rgb[1] + vertices[i][j][6] - 1.0f, rgb[2] + vertices[i][j][6] - 1.0f);
                                   glTexCoord2d(vertices[i][j][3] - vertices[i][j][0], vertices[i][j][4] - vertices[i][j][1]);
                                   glVertex3fv(vertices[i][j]);
                            }
                     glEnd();
              }
       }

       glPopMatrix();
}

Definition at line 406 of file Euphoria.cpp.

{
       int i, j;

       glPushMatrix();
       glTranslatef(c[0] * 0.2f, c[1] * 0.2f, 1.6f);

       if(_ec->dWireframe)
    {
              for(i=1; i<density; i++){
                     glBegin(GL_LINE_STRIP);
                     for(j=0; j<=density; j++){
                            glColor3f(rgb[0] + vertices[i][j][6] - 1.0f, rgb[1] + vertices[i][j][6] - 1.0f, rgb[2] + vertices[i][j][6] - 1.0f);
                            glTexCoord2d(vertices[i][j][3] - vertices[i][j][0], vertices[i][j][4] - vertices[i][j][1]);
                            glVertex3f(vertices[i][j][3], vertices[i][j][4], vertices[i][j][6]);
                     }
                     glEnd();
              }
              for(j=1; j<density; j++){
                     glBegin(GL_LINE_STRIP);
                     for(i=0; i<=density; i++){
                            glColor3f(rgb[0] + vertices[i][j][6] - 1.0f, rgb[1] + vertices[i][j][6] - 1.0f, rgb[2] + vertices[i][j][6] - 1.0f);
                            glTexCoord2d(vertices[i][j][3] - vertices[i][j][0], vertices[i][j][4] - vertices[i][j][1]);
                            glVertex3f(vertices[i][j][3], vertices[i][j][4], vertices[i][j][6]);
                     }
                     glEnd();
              }
       }
       else
    {
              for(i=0; i<density; i++){
                     glBegin(GL_TRIANGLE_STRIP);
                            for(j=0; j<=density; j++){
                                   glColor3f(rgb[0] + vertices[i+1][j][6] - 1.0f, rgb[1] + vertices[i+1][j][6] - 1.0f, rgb[2] + vertices[i+1][j][6] - 1.0f);
                                   glTexCoord2d(vertices[i+1][j][3] - vertices[i+1][j][0], vertices[i+1][j][4] - vertices[i+1][j][1]);
                                   glVertex3f(vertices[i+1][j][3], vertices[i+1][j][4], vertices[i+1][j][6]);
                                   glColor3f(rgb[0] + vertices[i][j][6] - 1.0f, rgb[1] + vertices[i][j][6] - 1.0f, rgb[2] + vertices[i][j][6] - 1.0f);
                                   glTexCoord2d(vertices[i][j][3] - vertices[i][j][0], vertices[i][j][4] - vertices[i][j][1]);
                                   glVertex3f(vertices[i][j][3], vertices[i][j][4], vertices[i][j][6]);
                            }
                     glEnd();
              }
       }

       glPopMatrix();
}
void wisp::update ( )

Definition at line 288 of file Euphoria.cpp.

{
       int i, j;
       rsVec up, right, crossvec;
       // visibility constants
       static float viscon1 = float(_ec->dVisibility) * 0.01f;
       static float viscon2 = 1.0f / viscon1;

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

       // update vertex positions
       for(i=0; i<=density; i++){
              for(j=0; j<=density; j++){
                     vertices[i][j][0] = vertices[i][j][3] * vertices[i][j][3] * vertices[i][j][4] * c[0]
                            + vertices[i][j][5] * c[1] + 0.5f * c[2];
                     vertices[i][j][1] = vertices[i][j][4] * vertices[i][j][4] * vertices[i][j][5] * c[3]
                            + vertices[i][j][3] * c[4] + 0.5f * c[5];
                     vertices[i][j][2] = vertices[i][j][5] * vertices[i][j][5] * vertices[i][j][3] * c[6]
                            + vertices[i][j][4] * c[7] + c[8];
              }
       }

       // update vertex normals for most of mesh
       for(i=1; i<density; i++){
              for(j=1; j<density; j++){
                     up.set(vertices[i][j+1][0] - vertices[i][j-1][0],
                            vertices[i][j+1][1] - vertices[i][j-1][1],
                            vertices[i][j+1][2] - vertices[i][j-1][2]);
                     right.set(vertices[i+1][j][0] - vertices[i-1][j][0],
                            vertices[i+1][j][1] - vertices[i-1][j][1],
                            vertices[i+1][j][2] - vertices[i-1][j][2]);
                     up.normalize();
                     right.normalize();
                     crossvec.cross(right, up);
                     // Use depth component of normal to compute intensity
                     // This way only edges of wisp are bright
                     if(crossvec[2] < 0.0f)
                            crossvec[2] *= -1.0f;
                     vertices[i][j][6] = viscon2 * (viscon1 - crossvec[2]);
                     if(vertices[i][j][6] > 1.0f)
                            vertices[i][j][6] = 1.0f;
                     if(vertices[i][j][6] < 0.0f)
                            vertices[i][j][6] = 0.0f;
              }
       }

       // update color
       hsl[0] += hueSpeed * _ec->elapsedTime;
       if(hsl[0] < 0.0f)
              hsl[0] += 1.0f;
       if(hsl[0] > 1.0f)
              hsl[0] -= 1.0f;
       hsl[1] += saturationSpeed * _ec->elapsedTime;
       if(hsl[1] <= 0.1f){
              hsl[1] = 0.1f;
              saturationSpeed = -saturationSpeed;
       }
       if(hsl[1] >= 1.0f){
              hsl[1] = 1.0f;
              saturationSpeed = -saturationSpeed;
       }
       hsl2rgb(hsl[0], hsl[1], hsl[2], rgb[0], rgb[1], rgb[2]);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 223 of file Euphoria.cpp.

Definition at line 224 of file Euphoria.cpp.

Definition at line 225 of file Euphoria.cpp.

Definition at line 221 of file Euphoria.cpp.

float wisp::hsl[3]

Definition at line 226 of file Euphoria.cpp.

Definition at line 228 of file Euphoria.cpp.

float wisp::rgb[3]

Definition at line 227 of file Euphoria.cpp.

Definition at line 229 of file Euphoria.cpp.

float*** wisp::vertices

Definition at line 222 of file Euphoria.cpp.


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