Back to index

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

#include <Flux.h>

Collaboration diagram for FluxWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  eDefault {
  Regular, Hypnotic, Insane, Sparklers,
  Paradigm, Galactic, DefaultModes
}

Public Member Functions

 FluxWidget (QWidget *parent=0)
 ~FluxWidget ()
void setDefaults (int which)
 May be called at any time - makes no OpenGL calls.
void updateParameters ()
 Called after dGeometry, dTrail, or dFluxes is changed (such as with setDefaults).

Protected Member Functions

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

Private Slots

void nextFrame ()

Private Attributes

float lumdiff
float cameraAngle
float cosCameraAngle
float sinCameraAngle
unsigned char lightTexture [LIGHTSIZE][LIGHTSIZE]
int dFluxes
int dParticles
int dTrail
int dGeometry
float dSize
int dComplexity
int dRandomize
int dExpansion
int dRotation
int dWind
float dInstability
int dBlur
int dSmart
int dPriority
flux_fluxes
QTimer * _timer
int _frameTime

Friends

class flux
class particle

Detailed Description

Definition at line 33 of file Flux.h.


Member Enumeration Documentation

Enumerator:
Regular 
Hypnotic 
Insane 
Sparklers 
Paradigm 
Galactic 
DefaultModes 

Definition at line 39 of file Flux.h.


Constructor & Destructor Documentation

FluxWidget::FluxWidget ( QWidget *  parent = 0)

Definition at line 428 of file Flux.cpp.

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

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

Here is the call graph for this function:

Definition at line 439 of file Flux.cpp.

{
    // Free memory
    delete[] _fluxes;
}

Member Function Documentation

void FluxWidget::initializeGL ( ) [protected]

Definition at line 532 of file Flux.cpp.

{
    //resizeGL( width(), height() );

    updateParameters();
    _timer->setSingleShot(true);
    _timer->start( _frameTime );
}

Here is the call graph for this function:

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

Definition at line 555 of file Flux.cpp.

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

Here is the caller graph for this function:

void FluxWidget::paintGL ( ) [protected]

Definition at line 446 of file Flux.cpp.

{
    // clear the screen
    glLoadIdentity();

    if(dBlur)   // partially
    {
        int viewport[4];
        glGetIntegerv(GL_VIEWPORT, viewport);
        float viewRatio = float(viewport[2]) / float(viewport[3]);

        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        glDisable(GL_DEPTH_TEST);
        glColor4f(0.0f, 0.0f, 0.0f, 0.5f - (float(sqrt(sqrt(double(dBlur)))) * 0.15495f));
        glBegin(GL_TRIANGLE_STRIP);
            glVertex3f(-3.0f * viewRatio, -3.0f, 0.0f);
            glVertex3f(3.0f * viewRatio, -3.0f, 0.0f);
            glVertex3f(-3.0f * viewRatio, 3.0f, 0.0f);
            glVertex3f(3.0f * viewRatio, 3.0f, 0.0f);
        glEnd();
    }
    else  // completely
    {
        glClear(GL_COLOR_BUFFER_BIT);
    }

    cameraAngle += 0.01f * float(dRotation);
    if(cameraAngle >= 360.0f)
        cameraAngle -= 360.0f;
    if(dGeometry == 1)  // Only rotate for spheres
        glRotatef(cameraAngle, 0.0f, 1.0f, 0.0f);
    else
    {
        cosCameraAngle = cos(cameraAngle * DEG2RAD);
        sinCameraAngle = sin(cameraAngle * DEG2RAD);
    }

    // set up blend modes for rendering particles
    switch(dGeometry)
    {
    case 0:  // Blending for points
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
        glEnable(GL_BLEND);
        glEnable(GL_POINT_SMOOTH);
        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
        break;

    case 1:  // No blending for spheres, but we need z-buffering
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glClear(GL_DEPTH_BUFFER_BIT);
        break;

    case 2:  // Blending for lights
        glBlendFunc(GL_ONE, GL_ONE);
        glEnable(GL_BLEND);
    }

    // Update particles
    if( _fluxes )
    {
        _fc = this;
        int i;
        for(i=0; i<dFluxes; i++)
            _fluxes[i].update();
    }

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

Definition at line 518 of file Flux.cpp.

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

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(100.0, (float) w / (float) h, 0.01, 200);
    glTranslatef(0.0, 0.0, -2.5);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
void FluxWidget::setDefaults ( int  which)

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

Definition at line 566 of file Flux.cpp.

{
    switch(which)
    {
    case Hypnotic:
        dFluxes = 2;
        dParticles = 10;
        dTrail = 40;
        dGeometry = 2;
        dSize = 15;
        dRandomize = 80;
        dExpansion = 20;
        dRotation = 0;
        dWind = 40;
        dInstability = 10;
        dBlur = 30;
        break;

    case Insane:
        dFluxes = 4;
        dParticles = 30;
        dTrail = 8;
        dGeometry = 2;
        dSize = 25;
        dRandomize = 0;
        dExpansion = 80;
        dRotation = 60;
        dWind = 40;
        dInstability = 100;
        dBlur = 10;
        break;

    case Sparklers:
        dFluxes = 3;
        dParticles = 20;
        dTrail = 6;
        dGeometry = 1;
        dSize = 20;
        dComplexity = 3;
        dRandomize = 85;
        dExpansion = 60;
        dRotation = 30;
        dWind = 20;
        dInstability = 30;
        dBlur = 0;
        break;

    case Paradigm:
        dFluxes = 1;
        dParticles = 40;
        dTrail = 40;
        dGeometry = 2;
        dSize = 5;
        dRandomize = 90;
        dExpansion = 30;
        dRotation = 20;
        dWind = 10;
        dInstability = 5;
        dBlur = 10;
        break;

    case Galactic:
        dFluxes = 1;
        dParticles = 2;
        dTrail = 1500;
        dGeometry = 2;
        dSize = 10;
        dRandomize = 0;
        dExpansion = 5;
        dRotation = 25;
        dWind = 0;
        dInstability = 5;
        dBlur = 0;
        break;

    case Regular:
    default:
        dFluxes = 1;
        dParticles = 20;
        dTrail = 40;
        dGeometry = 2;
        dSize = 15;
        dRandomize = 0;
        dExpansion = 40;
        dRotation = 30;
        dWind = 20;
        dInstability = 20;
        dBlur = 0;
        break;
    }
}

Here is the caller graph for this function:

Called after dGeometry, dTrail, or dFluxes is changed (such as with setDefaults).

Definition at line 663 of file Flux.cpp.

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

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

    cameraAngle = 0.0f;

    glFrontFace(GL_CCW);
    glEnable(GL_CULL_FACE);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if(dGeometry == 0)
    {
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
        glDisable(GL_TEXTURE_2D);

        glEnable(GL_POINT_SMOOTH);
        //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    }
    else if(dGeometry == 1)      // Spheres and their lighting
    {
        glNewList(1, GL_COMPILE);
        GLUquadricObj* qobj = gluNewQuadric();
        gluSphere(qobj, 0.005f * dSize, dComplexity + 2, dComplexity + 1);
        gluDeleteQuadric(qobj);
        glEndList();

        glDisable(GL_TEXTURE_2D);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);

        float ambient[4] = {0.0f, 0.0f, 0.0f, 0.0f};
        float diffuse[4] = {1.0f, 1.0f, 1.0f, 0.0f};
        float specular[4] = {1.0f, 1.0f, 1.0f, 0.0f};
        float position[4] = {500.0f, 500.0f, 500.0f, 0.0f};

        glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
        glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
        glLightfv(GL_LIGHT0, GL_POSITION, position);
        glEnable(GL_COLOR_MATERIAL);
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    }
    else if(dGeometry == 2)      // 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 * temp);
            }
        }

        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);

        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 = float(dSize) * 0.005f;
        glNewList(1, GL_COMPILE);
            glBindTexture(GL_TEXTURE_2D, 1);
            glBegin(GL_TRIANGLES);
                glTexCoord2f(0.0f, 0.0f);
                glVertex3f(-temp, -temp, 0.0f);
                glTexCoord2f(1.0f, 0.0f);
                glVertex3f(temp, -temp, 0.0f);
                glTexCoord2f(1.0f, 1.0f);
                glVertex3f(temp, temp, 0.0f);
                glTexCoord2f(0.0f, 0.0f);
                glVertex3f(-temp, -temp, 0.0f);
                glTexCoord2f(1.0f, 1.0f);
                glVertex3f(temp, temp, 0.0f);
                glTexCoord2f(0.0f, 1.0f);
                glVertex3f(-temp, temp, 0.0f);
            glEnd();
        glEndList();
    }

    // Initialize luminosity difference
    lumdiff = 1.0f / float(dTrail);

    _fc = this;
    delete[] _fluxes;
    _fluxes = new flux[dFluxes];
}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class flux [friend]

Definition at line 99 of file Flux.h.

friend class particle [friend]

Definition at line 100 of file Flux.h.


Member Data Documentation

Definition at line 91 of file Flux.h.

int FluxWidget::_frameTime [private]

Definition at line 97 of file Flux.h.

QTimer* FluxWidget::_timer [private]

Definition at line 96 of file Flux.h.

float FluxWidget::cameraAngle [private]

Definition at line 72 of file Flux.h.

float FluxWidget::cosCameraAngle [private]

Definition at line 73 of file Flux.h.

int FluxWidget::dBlur [private]

Definition at line 87 of file Flux.h.

int FluxWidget::dComplexity [private]

Definition at line 81 of file Flux.h.

int FluxWidget::dExpansion [private]

Definition at line 83 of file Flux.h.

int FluxWidget::dFluxes [private]

Definition at line 76 of file Flux.h.

int FluxWidget::dGeometry [private]

Definition at line 79 of file Flux.h.

float FluxWidget::dInstability [private]

Definition at line 86 of file Flux.h.

int FluxWidget::dParticles [private]

Definition at line 77 of file Flux.h.

int FluxWidget::dPriority [private]

Definition at line 89 of file Flux.h.

int FluxWidget::dRandomize [private]

Definition at line 82 of file Flux.h.

int FluxWidget::dRotation [private]

Definition at line 84 of file Flux.h.

float FluxWidget::dSize [private]

Definition at line 80 of file Flux.h.

int FluxWidget::dSmart [private]

Definition at line 88 of file Flux.h.

int FluxWidget::dTrail [private]

Definition at line 78 of file Flux.h.

int FluxWidget::dWind [private]

Definition at line 85 of file Flux.h.

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

Definition at line 74 of file Flux.h.

float FluxWidget::lumdiff [private]

Definition at line 71 of file Flux.h.

float FluxWidget::sinCameraAngle [private]

Definition at line 73 of file Flux.h.


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