Back to index

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

#include <gravity.h>

Collaboration diagram for Gravity:
Collaboration graph
[legend]

List of all members.

Classes

class  particles

Public Member Functions

 Gravity (QWidget *parent=0)
 ~Gravity ()
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
void buildParticle (int loop)

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 gravity.h.


Class Documentation

class Gravity::particles

Definition at line 40 of file gravity.h.

Class Members
bool active
float b
float fade
float g
float index
float indexo
float life
float r
float size
float x
float xo
float y
float yo
float z
float zo

Constructor & Destructor Documentation

Gravity::Gravity ( QWidget *  parent = 0)

Definition at line 192 of file gravity.cpp.

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

// This has to be here because you can't update the gravity until 'gravity' is created!
       KConfig _config("kssgravityrc", 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 212 of file gravity.cpp.

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

Member Function Documentation

void Gravity::buildParticle ( int  loop) [protected]

Definition at line 405 of file gravity.cpp.

{
       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;
       particle[loop].active=true;
       particle[loop].index=KRandom::random()%100;
       particle[loop].indexo=particle[loop].index;
       particle[loop].fade=float(KRandom::random()%100)/1000.0f+0.003f;      // Random Fade Value
       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;
       particle[loop].x = float(KRandom::random()%100-50)*4.0;
       particle[loop].y = float(KRandom::random()%20-10)*4.0;
       particle[loop].z = float(KRandom::random()%100-50)*4.0;
       particle[loop].xo = particle[loop].x;
       if ((1+(KRandom::random() % 10) > 5))
              particle[loop].yo = particle[loop].y;
       else
              particle[loop].yo = 0.0;
       particle[loop].zo = particle[loop].z;

}

Here is the caller graph for this function:

void Gravity::initializeGL ( ) [protected]

setup the GL environment

Definition at line 256 of file gravity.cpp.

{

       kDebug() << "InitGL";

       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
               {
                     buildParticle(loop);
              }
       }
       else
              exit(0);
}

Here is the call graph for this function:

bool Gravity::loadParticle ( ) [private]

load the partical file

load the particle file

Definition at line 219 of file gravity.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 Gravity::paintGL ( ) [protected]

paint the GL view

Definition at line 320 of file gravity.cpp.

{
       //kDebug() << "PaintGL";
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);            // Clear Screen And Depth Buffer
       glLoadIdentity();
                                          // Reset The ModelView Matrix
       transIndex++;
       //glRotatef(transIndex, 1,0,0);
       //glRotatef(transIndex, 0,1,0);
       //glRotatef(transIndex, 0,0,1);
       float xmax = 5.0;
       float ymax = 5.0;
       glTranslatef( GLfloat(xmax*sin(3.14*transIndex/360)-xmax),
                     GLfloat(ymax*cos(3.14*transIndex/360)-ymax),
                     0.0 );
       //glRotatef(transIndex, 0,GLfloat(zmax*cos(3.14*transIndex/360000)), GLfloat(zmax*cos(3.14*transIndex/360000)));

       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
                     */
                     particle[loop].life=(particle[loop].index/particle[loop].indexo)*2.0f;
                    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].xo*sin(particle[loop].index))*pow((double) particle[loop].index/particle[loop].indexo,(double) 8.0);
                     particle[loop].y=(particle[loop].yo*sin(particle[loop].index))*pow((double) particle[loop].index/particle[loop].indexo,(double) 8.0);
                     particle[loop].z=(particle[loop].zo*sin(particle[loop].index))*pow((double) particle[loop].index/particle[loop].indexo,(double) 8.0);
                     particle[loop].index-=0.05;
                     if (particle[loop].index<0.0f )                  // If Particle Is Burned Out
                     {
                            buildParticle(loop);
                     }
                     // Lets stir some things up
              }
       }

       glFlush();
}

Here is the call graph for this function:

void Gravity::resizeGL ( int  w,
int  h 
) [protected]

resize the gl view

Definition at line 300 of file gravity.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,100.0f);

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

Definition at line 387 of file gravity.cpp.

{
       size = newSize;
}

Here is the caller graph for this function:

void Gravity::setStars ( bool  doStars)

Definition at line 391 of file gravity.cpp.

{
       stars = doStars;
}

Here is the caller graph for this function:


Member Data Documentation

GLuint Gravity::col [private]

Definition at line 91 of file gravity.h.

GLuint Gravity::delay [private]

Definition at line 92 of file gravity.h.

float Gravity::index [private]

Definition at line 95 of file gravity.h.

GLuint Gravity::loop [private]

Definition at line 90 of file gravity.h.

GLUquadricObj* Gravity::obj [private]

Definition at line 98 of file gravity.h.

Definition at line 78 of file gravity.h.

bool Gravity::rainbow [private]

Definition at line 81 of file gravity.h.

bool Gravity::rp [private]

Definition at line 83 of file gravity.h.

GLfloat Gravity::scale [private]

Definition at line 97 of file gravity.h.

float Gravity::size [private]

Definition at line 88 of file gravity.h.

float Gravity::slowdown [private]

Definition at line 84 of file gravity.h.

bool Gravity::sp [private]

Definition at line 82 of file gravity.h.

float Gravity::stars [private]

Definition at line 89 of file gravity.h.

QImage Gravity::tex [private]

Definition at line 94 of file gravity.h.

GLuint Gravity::texture[1] [private]

Definition at line 93 of file gravity.h.

float Gravity::transIndex [private]

Definition at line 96 of file gravity.h.

float Gravity::xspeed [private]

Definition at line 85 of file gravity.h.

float Gravity::yspeed [private]

Definition at line 86 of file gravity.h.

float Gravity::zoom [private]

Definition at line 87 of file gravity.h.


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