Back to index

kdeartwork  4.3.2
Public Types | Public Member Functions | Protected Member Functions | Private Slots | Private Attributes | Friends
SWindsWidget Class Reference

#include <SolarWinds.h>

Collaboration diagram for SWindsWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  eDefault {
  Regular, CosmicStrings, ColdPricklies, SpaceFur,
  Jiggly, Undertow, DefaultModes
}

Public Member Functions

 SWindsWidget (QWidget *parent=0)
 ~SWindsWidget ()
void updateParameters ()
void setDefaults (int which)
 May be called at any time - makes no OpenGL calls.

Protected Member Functions

void paintGL ()
void resizeGL (int w, int h)
void initializeGL ()

Private Slots

void nextFrame ()

Private Attributes

wind_winds
unsigned char lightTexture [LIGHTSIZE][LIGHTSIZE]
int dWinds
int dEmitters
int dParticles
int dGeometry
float dSize
int dParticlespeed
int dEmitterspeed
int dWindspeed
int dBlur
QTimer * _timer
int _frameTime

Friends

class wind

Detailed Description

Definition at line 34 of file SolarWinds.h.


Member Enumeration Documentation

Enumerator:
Regular 
CosmicStrings 
ColdPricklies 
SpaceFur 
Jiggly 
Undertow 
DefaultModes 

Definition at line 40 of file SolarWinds.h.


Constructor & Destructor Documentation

SWindsWidget::SWindsWidget ( QWidget *  parent = 0)

Definition at line 308 of file SolarWinds.cpp.

                      : QGLWidget(parent), _winds(0)
{
    setDefaults( Regular );

    _frameTime = 1000 / 60;
    _timer = new QTimer( this );
    _timer->setSingleShot( true );
    connect( _timer, SIGNAL(timeout()), this, SLOT(nextFrame()) );
}

Here is the call graph for this function:

Definition at line 320 of file SolarWinds.cpp.

{
    // Free memory
    delete[] _winds;
}

Member Function Documentation

void SWindsWidget::initializeGL ( void  ) [protected]

Definition at line 388 of file SolarWinds.cpp.

Here is the call graph for this function:

void SWindsWidget::nextFrame ( ) [private, slot]

Definition at line 408 of file SolarWinds.cpp.

{
    updateGL();
    _timer->start( _frameTime );
}

Here is the caller graph for this function:

void SWindsWidget::paintGL ( void  ) [protected]

Definition at line 327 of file SolarWinds.cpp.

{
    glLoadIdentity();

    if( ! dBlur )
    {
        glClear(GL_COLOR_BUFFER_BIT);
    }
    else
    {
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glColor4f(0.0f, 0.0f, 0.0f, 0.5f - (float(dBlur) * 0.0049f));

        glBegin(GL_QUADS);
            glVertex3f(-40.0f, -17.0f, 0.0f);
            glVertex3f(40.0f, -17.0f, 0.0f);
            glVertex3f(40.0f, 17.0f, 0.0f);
            glVertex3f(-40.0f, 17.0f, 0.0f);
        glEnd();

        if(!dGeometry)
            glBlendFunc(GL_ONE, GL_ONE);
        else
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);  // Necessary for point and line smoothing (I don't know why)
                // Maybe it's just my video card...
    }

    // You should need to draw twice if using blur, once to each buffer.
    // But wglSwapLayerBuffers appears to copy the back to the
    // front instead of just switching the pointers to them.  It turns
    // out that both NVidia and 3dfx prefer to use PFD_SWAP_COPY instead
    // of PFD_SWAP_EXCHANGE in the PIXELFORMATDESCRIPTOR.  I don't know why...
    // So this may not work right on other platforms or all video cards.

    // Update surfaces
    if( _winds )
    {
        _ec = this;
        int i;
        for(i=0; i<dWinds; i++)
            _winds[i].update();
    }

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

Definition at line 374 of file SolarWinds.cpp.

{
    glViewport(0, 0, w, h );

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.0, (float) w / (float) h, 1.0, 10000);
    glTranslatef(0.0, 0.0, -15.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
void SWindsWidget::setDefaults ( int  which)

May be called at any time - makes no OpenGL calls.

Definition at line 501 of file SolarWinds.cpp.

{
    switch(which)
    {
    case CosmicStrings:
        dWinds = 1;
        dEmitters = 50;
        dParticles = 3000;
        dGeometry = 2;
        dSize = 20;
        dWindspeed = 10;
        dEmitterspeed = 10;
        dParticlespeed = 10;
        dBlur = 10;
        break;

    case ColdPricklies:
        dWinds = 1;
        dEmitters = 300;
        dParticles = 3000;
        dGeometry = 2;
        dSize = 5;
        dWindspeed = 20;
        dEmitterspeed = 100;
        dParticlespeed = 15;
        dBlur = 70;
        break;

    case SpaceFur:
        dWinds = 2;
        dEmitters = 400;
        dParticles = 1600;
        dGeometry = 2;
        dSize = 15;
        dWindspeed = 20;
        dEmitterspeed = 15;
        dParticlespeed = 10;
        dBlur = 0;
        break;

    case Jiggly:
        dWinds = 1;
        dEmitters = 40;
        dParticles = 1200;
        dGeometry = 1;
        dSize = 20;
        dWindspeed = 100;
        dEmitterspeed = 20;
        dParticlespeed = 4;
        dBlur = 50;
        break;

    case Undertow:
        dWinds = 1;
        dEmitters = 400;
        dParticles = 1200;
        dGeometry = 0;
        dSize = 40;
        dWindspeed = 20;
        dEmitterspeed = 1;
        dParticlespeed = 100;
        dBlur = 50;
        break;

    case Regular:
    default:
        dWinds = 1;
        dEmitters = 30;
        dParticles = 2000;
        dGeometry = 0;
        dSize = 50;
        dWindspeed = 20;
        dEmitterspeed = 15;
        dParticlespeed = 10;
        dBlur = 40;
        break;
    }
}

Here is the caller graph for this function:

Definition at line 415 of file SolarWinds.cpp.

{
    int i, j;
    float x, y, temp;

    srand((unsigned)time(NULL));
    rand(); rand(); rand(); rand(); rand();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    if(!dGeometry)
        glBlendFunc(GL_ONE, GL_ONE);
    else
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);  // Necessary for point and line smoothing (I don't know why)
    glEnable(GL_BLEND);

    if( ! dGeometry )
    {
        // Init lights
        for(i=0; i<LIGHTSIZE; i++)
        {
            for(j=0; j<LIGHTSIZE; j++)
            {
                x = float(i - LIGHTSIZE / 2) / float(LIGHTSIZE / 2);
                y = float(j - LIGHTSIZE / 2) / float(LIGHTSIZE / 2);
                temp = 1.0f - float(sqrt((x * x) + (y * y)));
                if(temp > 1.0f)
                    temp = 1.0f;
                if(temp < 0.0f)
                    temp = 0.0f;
                lightTexture[i][j] = (unsigned char) (255.0f * temp);
            }
        }

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 1);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, 1, LIGHTSIZE, LIGHTSIZE, 0,
                     GL_LUMINANCE, GL_UNSIGNED_BYTE, lightTexture);

        temp = 0.02f * dSize;
        glNewList(1, GL_COMPILE);
            glBindTexture(GL_TEXTURE_2D, 1);
            glBegin(GL_TRIANGLE_STRIP);
                glTexCoord2f(0.0f, 0.0f);
                glVertex3f(-temp, -temp, 0.0f);
                glTexCoord2f(1.0f, 0.0f);
                glVertex3f(temp, -temp, 0.0f);
                glTexCoord2f(0.0f, 1.0f);
                glVertex3f(-temp, temp, 0.0f);
                glTexCoord2f(1.0f, 1.0f);
                glVertex3f(temp, temp, 0.0f);
            glEnd();
        glEndList();
    }
    else if(dGeometry == 1)
    {
        // init point smoothing
        glEnable(GL_POINT_SMOOTH);
        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);

        glDisable(GL_TEXTURE_2D);
    }
    else if(dGeometry == 2)
    {
        // init line smoothing
        glEnable(GL_LINE_SMOOTH);
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

        glDisable(GL_TEXTURE_2D);
    }


    // Initialize surfaces
    _ec = this;
    delete[] _winds;
    _winds = new wind[dWinds];
}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class wind [friend]

Definition at line 93 of file SolarWinds.h.


Member Data Documentation

int SWindsWidget::_frameTime [private]

Definition at line 91 of file SolarWinds.h.

QTimer* SWindsWidget::_timer [private]

Definition at line 90 of file SolarWinds.h.

Definition at line 73 of file SolarWinds.h.

int SWindsWidget::dBlur [private]

Definition at line 84 of file SolarWinds.h.

int SWindsWidget::dEmitters [private]

Definition at line 77 of file SolarWinds.h.

Definition at line 82 of file SolarWinds.h.

int SWindsWidget::dGeometry [private]

Definition at line 79 of file SolarWinds.h.

int SWindsWidget::dParticles [private]

Definition at line 78 of file SolarWinds.h.

Definition at line 81 of file SolarWinds.h.

float SWindsWidget::dSize [private]

Definition at line 80 of file SolarWinds.h.

int SWindsWidget::dWinds [private]

Definition at line 76 of file SolarWinds.h.

int SWindsWidget::dWindspeed [private]

Definition at line 83 of file SolarWinds.h.

unsigned char SWindsWidget::lightTexture[LIGHTSIZE][LIGHTSIZE] [private]

Definition at line 74 of file SolarWinds.h.


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