Back to index

kdeartwork  4.3.2
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
Fountain Class Reference

#include <fountain.h>

Collaboration diagram for Fountain:
Collaboration graph
[legend]

List of all members.

Classes

class  particles

Public Member Functions

 Fountain (QWidget *parent=0)
 ~Fountain ()
void setSize (float newSize)
void setStars (bool doStars)

Protected Member Functions

void paintGL ()
 paint the GL view
void resizeGL (int w, int h)
 resize the gl view
void initializeGL ()
 setup the GL environment

Private Member Functions

bool loadParticle ()
 load the partical file

Private Attributes

particles particle [MAX_PARTICLES]
bool rainbow
bool sp
bool rp
float slowdown
float xspeed
float yspeed
float zoom
float size
float stars
GLuint loop
GLuint col
GLuint delay
GLuint texture [1]
QImage tex
float index
float transIndex
GLfloat scale
GLUquadricObj * obj

Detailed Description

Definition at line 37 of file fountain.h.


Class Documentation

class Fountain::particles

Definition at line 40 of file fountain.h.

Class Members
bool active
float b
float fade
float g
float life
float r
float size
float x
float xg
float xi
float y
float yg
float yi
float z
float zg
float zi

Constructor & Destructor Documentation

Fountain::Fountain ( QWidget *  parent = 0)

Definition at line 203 of file fountain.cpp.

                                     : QGLWidget (parent)
{
       rainbow=true;
       slowdown=2.0f;
       zoom=-40.0f;
       index=0;
       size = 0.75f;
       obj = gluNewQuadric();

// This has to be here because you can't update the fountain until 'fountain' is created!
       KConfig _config("kssfountainrc", KConfig::NoGlobals);
       KConfigGroup config(&_config, "Settings" );
       bool boolval = config.readEntry( "Stars", false );
        setStars(boolval);

       int starammount = config.readEntry("StarSize", 75);
       float passvalue = (starammount / 100.0);
       setSize(passvalue);

}

Here is the call graph for this function:

Definition at line 224 of file fountain.cpp.

{
       glDeleteTextures( 1, &texture[0] );
       gluDeleteQuadric(obj);
}

Member Function Documentation

void Fountain::initializeGL ( ) [protected]

setup the GL environment

Definition at line 268 of file fountain.cpp.

{

       kDebug() << "InitGL";
       GLfloat colors[12][3]=
       {{1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f},
       {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f},
       {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}};

       if (loadParticle())                                     // Jump To Texture Loading Routine
       {
    /* Enable smooth shading */
    glShadeModel( GL_SMOOTH );

    /* Set the background black */
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

    /* Depth buffer setup */
    glClearDepth( 1.0f );

    /* Enables Depth Testing */
    glDisable( GL_DEPTH_TEST );

    /* Enable Blending */
    glEnable( GL_BLEND );
    /* Type Of Blending To Perform */
    glBlendFunc( GL_SRC_ALPHA, GL_ONE );


    /* Really Nice Perspective Calculations */
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
    /* Really Nice Point Smoothing */
    glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );

    /* Enable Texture Mapping */
    glEnable( GL_TEXTURE_2D );
    /* Select Our Texture */
    glBindTexture( GL_TEXTURE_2D, texture[0] );

              for (loop=0;loop<MAX_PARTICLES;loop++)                         // Initials All The Textures
              {
                     particle[loop].active=true;                      // Make All The Particles Active
                     particle[loop].life=1.0f;                        // Give All The Particles Full Life
                     particle[loop].fade=float(KRandom::random()%100)/1000.0f+0.003f;      // Random Fade Speed
                     int color_index = (loop+1)/(MAX_PARTICLES/12);
                     color_index = qMin(11, color_index);
                     particle[loop].r=colors[color_index][0];  // Select Red Rainbow Color
                     particle[loop].g=colors[color_index][1];  // Select Green Rainbow Color
                     particle[loop].b=colors[color_index][2];  // Select Blue Rainbow Color
                     particle[loop].xi=float((KRandom::random()%50)-26.0f)*10.0f;   // Random Speed On X Axis
                     particle[loop].yi=float((KRandom::random()%50)-25.0f)*10.0f;   // Random Speed On Y Axis
                     particle[loop].zi=float((KRandom::random()%50)-25.0f)*10.0f;   // Random Speed On Z Axis
                     particle[loop].xg=0.0f;                                 // Set Horizontal Pull To Zero
                     particle[loop].yg=-0.8f;                         // Set Vertical Pull Downward
                     particle[loop].zg=0.0f;                                 // Set Pull On Z Axis To Zero
                     particle[loop].size=size;                        // Set particle size.
              }
       }
       else
              exit(0);
}

Here is the call graph for this function:

bool Fountain::loadParticle ( ) [private]

load the partical file

load the particle file

Definition at line 231 of file fountain.cpp.

{
    /* Status indicator */
    bool Status = true;
    QImage buf;

    kDebug() << "Loading: " << KStandardDirs::locate("data", "kscreensaver/particle.png");

    if (buf.load( KStandardDirs::locate("data", "kscreensaver/particle.png") ) )
    {
        tex = convertToGLFormat(buf);  // flipped 32bit RGBA
        kDebug() << "Texture loaded: " << tex.numBytes ();
    }
    else
    {
        QImage dummy( 32, 32, QImage::Format_RGB32 );
        dummy.fill( Qt::white );
        buf = dummy;
        tex = convertToGLFormat( buf );
    }

    /* Set the status to true */
    //Status = true;
    glGenTextures(1, &texture[0]);   /* create three textures */
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    /* use linear filtering */
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    /* actually generate the texture */
    glTexImage2D(GL_TEXTURE_2D, 0, 4, tex.width(), tex.height(), 0,
    GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());



    return Status;
}

Here is the caller graph for this function:

void Fountain::paintGL ( ) [protected]

paint the GL view

Definition at line 350 of file fountain.cpp.

{
       //kDebug() << "PaintGL";

       GLfloat colors[12][3]=
       {{1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f},
       {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f},
       {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}};
       col = ( ++col ) % 12;
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);            // Clear Screen And Depth Buffer

       glLoadIdentity();
                                          // Reset The ModelView Matrix
       transIndex++;
       glTranslatef( GLfloat(5.0*sin(4*3.14*transIndex/360)), GLfloat(4.0*cos(2*3.14*transIndex/360)), 0.0 );
       xspeed = GLfloat(100.0*cos(3*3.14*transIndex/360)+100);
       yspeed = GLfloat(100.0*sin(3*3.14*transIndex/360)+100);
       //slowdown = GLfloat(4.0*sin(2*3.14*transIndex/360)+4.01);

       for (loop=0;loop<MAX_PARTICLES;loop++)                         // Loop Through All The Particles
       {
              if (particle[loop].active)                       // If The Particle Is Active
              {
                     float x=particle[loop].x;                 // Grab Our Particle X Position
                     float y=particle[loop].y;                 // Grab Our Particle Y Position
                     float z=particle[loop].z+zoom;                   // Particle Z Pos + Zoom
    /* Select Our Texture */

                    /* Draw The Particle Using Our RGB Values,
                     * Fade The Particle Based On It's Life
                     */

                    glColor4f( particle[loop].r,
                               particle[loop].g,
                               particle[loop].b,
                               particle[loop].life );

                    /* Build Quad From A Triangle Strip */
                if( !stars )
                  glBegin( GL_TRIANGLE_STRIP );
                else
                  glBegin( GL_TRIANGLE_FAN );
                      /* Top Right */
                      glTexCoord2d( 1, 1 );
                      glVertex3f( x + particle[loop].size, y + particle[loop].size, z );
                      /* Top Left */
                      glTexCoord2d( 0, 1 );
                      glVertex3f( x - particle[loop].size, y + particle[loop].size, z );
                      /* Bottom Right */
                      glTexCoord2d( 1, 0 );
                      glVertex3f( x + particle[loop].size, y - particle[loop].size, z );
                      /* Bottom Left */
                      glTexCoord2d( 0, 0 );
                      glVertex3f( x - particle[loop].size, y - particle[loop].size, z );
                    glEnd( );

                     particle[loop].x+=particle[loop].xi/(slowdown*1000);// Move On The X Axis By X Speed
                     particle[loop].y+=particle[loop].yi/(slowdown*1000);// Move On The Y Axis By Y Speed
                     particle[loop].z+=particle[loop].zi/(slowdown*1000);// Move On The Z Axis By Z Speed

                     particle[loop].xi+=particle[loop].xg;                   // Take Pull On X Axis Into Account
                     particle[loop].yi+=particle[loop].yg;                   // Take Pull On Y Axis Into Account
                     particle[loop].zi+=particle[loop].zg;                   // Take Pull On Z Axis Into Account
                     particle[loop].life-=particle[loop].fade;        // Reduce Particles Life By 'Fade'

                     if (particle[loop].life<0.0f)                                  // If Particle Is Burned Out
                     {
                            particle[loop].life=2.0f;                        // Give It New Life
                            particle[loop].fade=float(KRandom::random()%100)/1000.0f+0.003f;      // Random Fade Value
                            particle[loop].x=0.0f;                                  // Center On X Axis
                            particle[loop].y=0.0f;                                  // Center On Y Axis
                            particle[loop].z=0.0f;                                  // Center On Z Axis
                            particle[loop].xi=xspeed+float((KRandom::random()%60)-32.0f);  // X Axis Speed And Direction
                            particle[loop].yi=yspeed+float((KRandom::random()%60)-30.0f);  // Y Axis Speed And Direction
                            particle[loop].zi=float((KRandom::random()%60)-30.0f);         // Z Axis Speed And Direction
                            particle[loop].r=colors[col][0];                 // Select Red From Color Table
                            particle[loop].g=colors[col][1];                 // Select Green From Color Table
                            particle[loop].b=colors[col][2];                 // Select Blue From Color Table
                            particle[loop].size=size;
                            if ((1+(random()%20)) == 10)
                            {
                            // Explode
                                   particle[loop].active=true;                      // Make All The Particles Active
                                   particle[loop].life=1.0f;                        // Give All The Particles Full Life
                                   particle[loop].fade=float(KRandom::random()%100)/1000.0f+0.003f;      // Random Fade Speed
                                   int color_index = (loop+1)/(MAX_PARTICLES/12);
                                   color_index = qMin(11, color_index);
                                   particle[loop].r=colors[color_index][0];        // Select Red Rainbow Color
                                   particle[loop].g=colors[color_index][1];        // Select Green Rainbow Color
                                   particle[loop].b=colors[color_index][2];  // Select Blue Rainbow Color
                                   particle[loop].xi=float((KRandom::random()%50)-26.0f)*10.0f;   // Random Speed On X Axis
                                   particle[loop].yi=float((KRandom::random()%50)-25.0f)*10.0f;   // Random Speed On Y Axis
                                   particle[loop].zi=float((KRandom::random()%50)-25.0f)*10.0f;   // Random Speed On Z Axis
                                   particle[loop].xg=0.0f;                                 // Set Horizontal Pull To Zero
                                   particle[loop].yg=-0.8f;                         // Set Vertical Pull Downward
                                   particle[loop].zg=0.0f;                                 // Set Pull On Z Axis To Zero
                                   particle[loop].size=size;                        // Set particle size.
                            }
                     }
                     // Lets stir some things up
                     index += 0.001;
                     particle[loop].yg =2.0*sin(2*3.14*transIndex/360);
                     particle[loop].xg =2.0*cos(2*3.14*transIndex/360);
                     particle[loop].zg =4.0+(4.0*cos(2*3.14*transIndex/360));

              }
       }

       glFlush();
}
void Fountain::resizeGL ( int  w,
int  h 
) [protected]

resize the gl view

Definition at line 330 of file fountain.cpp.

{
       kDebug() << "ResizeGL " << width << "," <<height;
       if (height==0)                                                 // Prevent A Divide By Zero By
       {
              height=1;                                        // Making Height Equal One
       }

       glViewport(0,0,width,height);                                  // Reset The Current Viewport

       glMatrixMode(GL_PROJECTION);                                   // Select The Projection Matrix
       glLoadIdentity();                                       // Reset The Projection Matrix

       // Calculate The Aspect Ratio Of The Window
       gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,200.0f);

       glMatrixMode(GL_MODELVIEW);                             // Select The Modelview Matrix
       glLoadIdentity();
}
void Fountain::setSize ( float  newSize)

Definition at line 460 of file fountain.cpp.

{
       size = newSize;
}

Here is the caller graph for this function:

void Fountain::setStars ( bool  doStars)

Definition at line 464 of file fountain.cpp.

{
       stars = doStars;
}

Here is the caller graph for this function:


Member Data Documentation

GLuint Fountain::col [private]

Definition at line 93 of file fountain.h.

GLuint Fountain::delay [private]

Definition at line 94 of file fountain.h.

float Fountain::index [private]

Definition at line 97 of file fountain.h.

GLuint Fountain::loop [private]

Definition at line 92 of file fountain.h.

GLUquadricObj* Fountain::obj [private]

Definition at line 100 of file fountain.h.

Definition at line 79 of file fountain.h.

bool Fountain::rainbow [private]

Definition at line 82 of file fountain.h.

bool Fountain::rp [private]

Definition at line 84 of file fountain.h.

GLfloat Fountain::scale [private]

Definition at line 99 of file fountain.h.

float Fountain::size [private]

Definition at line 90 of file fountain.h.

float Fountain::slowdown [private]

Definition at line 86 of file fountain.h.

bool Fountain::sp [private]

Definition at line 83 of file fountain.h.

float Fountain::stars [private]

Definition at line 91 of file fountain.h.

QImage Fountain::tex [private]

Definition at line 96 of file fountain.h.

GLuint Fountain::texture[1] [private]

Definition at line 95 of file fountain.h.

float Fountain::transIndex [private]

Definition at line 98 of file fountain.h.

float Fountain::xspeed [private]

Definition at line 87 of file fountain.h.

float Fountain::yspeed [private]

Definition at line 88 of file fountain.h.

float Fountain::zoom [private]

Definition at line 89 of file fountain.h.


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