Back to index

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

#include <Euphoria.h>

Collaboration diagram for EuphoriaWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  eDefault {
  Regular, Grid, Cubism, BadMath,
  MTheory, UHFTEM, Nowhere, Echo,
  Kaleidoscope, DefaultModes
}

Public Member Functions

 EuphoriaWidget (QWidget *parent=0)
 ~EuphoriaWidget ()
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

GLuint texName
wisp_wisps
wisp_backwisps
unsigned char * feedbackmap
float aspectRatio
int viewport [4]
double elapsedTime
unsigned int feedbacktex
int feedbacktexsize
float fr [4]
float fv [4]
float f [4]
float lr [3]
float lv [3]
float l [3]
int dWisps
int dBackground
int dDensity
int dVisibility
float dSpeed
int dFeedback
int dFeedbackspeed
int dFeedbacksize
int dWireframe
int dTexture
int dPriority
QTimer * _timer
int _frameTime

Friends

class wisp

Detailed Description

Definition at line 32 of file Euphoria.h.


Member Enumeration Documentation

Enumerator:
Regular 
Grid 
Cubism 
BadMath 
MTheory 
UHFTEM 
Nowhere 
Echo 
Kaleidoscope 
DefaultModes 

Definition at line 38 of file Euphoria.h.

    {
        Regular,
        Grid,
        Cubism,
        BadMath,
        MTheory,
        UHFTEM,   // ultra high frequency tunneling electron microscope
        Nowhere,
        Echo,
        Kaleidoscope,
        DefaultModes
    };

Constructor & Destructor Documentation

EuphoriaWidget::EuphoriaWidget ( QWidget *  parent = 0)

Definition at line 457 of file Euphoria.cpp.

              : QGLWidget(parent), texName(0), _wisps(0), _backwisps(0),
             feedbackmap(0), feedbacktex(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 470 of file Euphoria.cpp.

{
       // Free memory
       if ( texName )
              glDeleteTextures( 1, &texName );
       if ( feedbacktex )
              glDeleteTextures( 1, &feedbacktex );
       delete[] _wisps;
       delete[] _backwisps;
}

Member Function Documentation

void EuphoriaWidget::initializeGL ( ) [protected]

Definition at line 624 of file Euphoria.cpp.

{
    // Need to call this to setup viewport[] parameters used in
    // the next updateParameters() call
    resizeGL( width(), height() );

    updateParameters();

    _timer->start( _frameTime );
}

Here is the call graph for this function:

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

Definition at line 652 of file Euphoria.cpp.

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

Here is the caller graph for this function:

void EuphoriaWidget::paintGL ( ) [protected]

Definition at line 482 of file Euphoria.cpp.

{
       int i;
       static double lastTime = timeGetTime();

       // update time
       elapsedTime = timeGetTime() - lastTime;
       lastTime += elapsedTime;

    _ec = this;

       // Update wisps
       for(i=0; i<dWisps; i++)
              _wisps[i].update();
       for(i=0; i<dBackground; i++)
              _backwisps[i].update();


       if(dFeedback)
    {
              float feedbackIntensity = float(dFeedback) / 101.0f;

              // update feedback variables
              for(i=0; i<4; i++)
        {
                     fr[i] += elapsedTime * fv[i];
                     if(fr[i] > PIx2)
                            fr[i] -= PIx2;
              }
              f[0] = 30.0f * cos(fr[0]);
              f[1] = 0.2f * cos(fr[1]);
              f[2] = 0.2f * cos(fr[2]);
              f[3] = 0.8f * cos(fr[3]);
              for(i=0; i<3; i++)
        {
                     lr[i] += elapsedTime * lv[i];
                     if(lr[i] > PIx2)
                            lr[i] -= PIx2;
                     l[i] = cos(lr[i]);
                     l[i] = l[i] * l[i];
              }

              // Create drawing area for feedback texture
              glViewport(0, 0, feedbacktexsize, feedbacktexsize);
              glMatrixMode(GL_PROJECTION);
              glLoadIdentity();
              gluPerspective(30.0, aspectRatio, 0.01f, 20.0f);
              glMatrixMode(GL_MODELVIEW);

              // Draw
              glClear(GL_COLOR_BUFFER_BIT);
              glColor3f(feedbackIntensity, feedbackIntensity, feedbackIntensity);
              glBindTexture(GL_TEXTURE_2D, feedbacktex);
              glPushMatrix();
              glTranslatef(f[1] * l[1], f[2] * l[1], f[3] * l[2]);
              glRotatef(f[0] * l[0], 0, 0, 1);
              glBegin(GL_TRIANGLE_STRIP);
                     glTexCoord2f(-0.5f, -0.5f);
                     glVertex3f(-aspectRatio*2.0f, -2.0f, 1.25f);
                     glTexCoord2f(1.5f, -0.5f);
                     glVertex3f(aspectRatio*2.0f, -2.0f, 1.25f);
                     glTexCoord2f(-0.5f, 1.5f);
                     glVertex3f(-aspectRatio*2.0f, 2.0f, 1.25f);
                     glTexCoord2f(1.5f, 1.5f);
                     glVertex3f(aspectRatio*2.0f, 2.0f, 1.25f);
              glEnd();
              glPopMatrix();
              glBindTexture(GL_TEXTURE_2D, texName);
              for(i=0; i<dBackground; i++)
                     _backwisps[i].drawAsBackground();
              for(i=0; i<dWisps; i++)
                     _wisps[i].draw();

              // readback feedback texture
              glReadBuffer(GL_BACK);
              glPixelStorei(GL_UNPACK_ROW_LENGTH, feedbacktexsize);
              glBindTexture(GL_TEXTURE_2D, feedbacktex);
              glReadPixels(0, 0, feedbacktexsize, feedbacktexsize, GL_RGB, GL_UNSIGNED_BYTE, feedbackmap);
              glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, feedbacktexsize, feedbacktexsize, GL_RGB, GL_UNSIGNED_BYTE, feedbackmap);

              // create regular drawing area
              glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
              glMatrixMode(GL_PROJECTION);
              glLoadIdentity();
              gluPerspective(20.0, aspectRatio, 0.01f, 20.0f);
              glMatrixMode(GL_MODELVIEW);

              // Draw again
              glClear(GL_COLOR_BUFFER_BIT);
              glColor3f(feedbackIntensity, feedbackIntensity, feedbackIntensity);
              glPushMatrix();
              glTranslatef(f[1] * l[1], f[2] * l[1], f[3] * l[2]);
              glRotatef(f[0] * l[0], 0, 0, 1);
              glBegin(GL_TRIANGLE_STRIP);
                     glTexCoord2f(-0.5f, -0.5f);
                     glVertex3f(-aspectRatio*2.0f, -2.0f, 1.25f);
                     glTexCoord2f(1.5f, -0.5f);
                     glVertex3f(aspectRatio*2.0f, -2.0f, 1.25f);
                     glTexCoord2f(-0.5f, 1.5f);
                     glVertex3f(-aspectRatio*2.0f, 2.0f, 1.25f);
                     glTexCoord2f(1.5f, 1.5f);
                     glVertex3f(aspectRatio*2.0f, 2.0f, 1.25f);
              glEnd();
              glPopMatrix();

              glBindTexture(GL_TEXTURE_2D, texName);
       }
       else
              glClear(GL_COLOR_BUFFER_BIT);

       //
       for(i=0; i<dBackground; i++)
              _backwisps[i].drawAsBackground();
       for(i=0; i<dWisps; i++)
              _wisps[i].draw();

       glFlush();
}

Here is the call graph for this function:

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

Definition at line 602 of file Euphoria.cpp.

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

       viewport[0] = 0;
       viewport[1] = 0;
       viewport[2] = w;
       viewport[3] = h;

       aspectRatio = (float) w / (float) h;

       // setup regular drawing area just in case feedback isn't used
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
    gluPerspective(20.0, aspectRatio, 0.01, 20);
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
       glTranslatef(0.0, 0.0, -5.0);
}

Here is the caller graph for this function:

void EuphoriaWidget::setDefaults ( int  which)

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

Definition at line 760 of file Euphoria.cpp.

{
       switch(which)
    {
       case Grid:
              dWisps = 4;
              dBackground = 1;
              dDensity = 25;
              dVisibility = 70;
              dSpeed = 15;
              dFeedback = 0;
              dFeedbackspeed = 1;
              dFeedbacksize = 8;
              dWireframe = 1;
              dTexture = 0;
              break;

    case Cubism:
              dWisps = 15;
              dBackground = 0;
              dDensity = 4;
              dVisibility = 15;
              dSpeed = 10;
              dFeedback = 0;
              dFeedbackspeed = 1;
              dFeedbacksize = 8;
              dWireframe = 0;
              dTexture = 0;
              break;

    case BadMath:
              dWisps = 2;
              dBackground = 2;
              dDensity = 20;
              dVisibility = 40;
              dSpeed = 30;
              dFeedback = 40;
              dFeedbackspeed = 5;
              dFeedbacksize = 8;
              dWireframe = 1;
              dTexture = 2;
              break;

    case MTheory:
              dWisps = 3;
              dBackground = 0;
              dDensity = 25;
              dVisibility = 15;
              dSpeed = 20;
              dFeedback = 40;
              dFeedbackspeed = 20;
              dFeedbacksize = 8;
              dWireframe = 0;
              dTexture = 0;
              break;

       case UHFTEM:
              dWisps = 0;
              dBackground = 3;
              dDensity = 35;
              dVisibility = 5;
              dSpeed = 50;
              dFeedback = 0;
              dFeedbackspeed = 1;
              dFeedbacksize = 8;
              dWireframe = 0;
              dTexture = 0;
              break;

    case Nowhere:
              dWisps = 0;
              dBackground = 3;
              dDensity = 30;
              dVisibility = 40;
              dSpeed = 20;
              dFeedback = 80;
              dFeedbackspeed = 10;
              dFeedbacksize = 8;
              dWireframe = 1;
              dTexture = 3;
              break;

    case Echo:
              dWisps = 3;
              dBackground = 0;
              dDensity = 25;
              dVisibility = 30;
              dSpeed = 20;
              dFeedback = 85;
              dFeedbackspeed = 30;
              dFeedbacksize = 8;
              dWireframe = 0;
              dTexture = 1;
              break;

    case Kaleidoscope:
              dWisps = 3;
              dBackground = 0;
              dDensity = 25;
              dVisibility = 40;
              dSpeed = 15;
              dFeedback = 90;
              dFeedbackspeed = 3;
              dFeedbacksize = 8;
              dWireframe = 0;
              dTexture = 0;
              break;

    case Regular:
    default:
              dWisps = 5;
              dBackground = 0;
              dDensity = 25;
              dVisibility = 35;
              dSpeed = 15;
              dFeedback = 0;
              dFeedbackspeed = 1;
              dFeedbacksize = 8;
              dWireframe = 0;
              dTexture = 2;
              break;
       }
}

Here is the caller graph for this function:

Definition at line 659 of file Euphoria.cpp.

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

    elapsedTime = 0.0f;

    fr[0] = 0.0f;
    fr[1] = 0.0f;
    fr[2] = 0.0f;
    fr[3] = 0.0f;

    lr[0] = 0.0f;
    lr[1] = 0.0f;
    lr[2] = 0.0f;

       glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
       glClear(GL_COLOR_BUFFER_BIT);
       glEnable(GL_BLEND);
       glBlendFunc(GL_ONE, GL_ONE);
       glLineWidth(2.0f);

       // Commented out because smooth lines and textures don't mix on my TNT.
       // It's like it rendering in software mode
       glEnable(GL_LINE_SMOOTH);
       //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

       if(dTexture)
    {
              int whichtex = dTexture;
              if(whichtex == 4)  // random texture
                     whichtex = myRandi(3) + 1;
              glEnable(GL_TEXTURE_2D);
              glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
              // Initialize texture
              glGenTextures(1, &texName);
              glBindTexture(GL_TEXTURE_2D, texName);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
              switch(whichtex){
              case 1:
                     gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TEXSIZE, TEXSIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, plasmamap);
                     break;
              case 2:
                     gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TEXSIZE, TEXSIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, stringymap);
                     break;
              case 3:
                     gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TEXSIZE, TEXSIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, linesmap);
              }
       } else if ( texName ) {
              glDeleteTextures( 1, &texName );
              texName = 0;
       }

       if(dFeedback)
    {
              feedbacktexsize = int(pow(2.0, dFeedbacksize));
              while(feedbacktexsize > viewport[2] || feedbacktexsize > viewport[3]){
                     dFeedbacksize -= 1;
                     feedbacktexsize = int(pow(2.0, dFeedbacksize));
              }

              // feedback texture setup
              glEnable(GL_TEXTURE_2D);
              delete [] feedbackmap;
              feedbackmap = new unsigned char[feedbacktexsize*feedbacktexsize*3];
              glGenTextures(1, &feedbacktex);
              glBindTexture(GL_TEXTURE_2D, feedbacktex);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
              glTexImage2D(GL_TEXTURE_2D, 0, 3, feedbacktexsize, feedbacktexsize, 0, GL_RGB, GL_UNSIGNED_BYTE, feedbackmap);

              // feedback velocity variable setup
              fv[0] = float(dFeedbackspeed) * (myRandf(0.025f) + 0.025f);
              fv[1] = float(dFeedbackspeed) * (myRandf(0.05f) + 0.05f);
              fv[2] = float(dFeedbackspeed) * (myRandf(0.05f) + 0.05f);
              fv[3] = float(dFeedbackspeed) * (myRandf(0.1f) + 0.1f);
              lv[0] = float(dFeedbackspeed) * (myRandf(0.0025f) + 0.0025f);
              lv[1] = float(dFeedbackspeed) * (myRandf(0.0025f) + 0.0025f);
              lv[2] = float(dFeedbackspeed) * (myRandf(0.0025f) + 0.0025f);
       } else if ( feedbacktex ) {
              glDeleteTextures( 1, &feedbacktex );
              feedbacktex = 0;
       }

       // Initialize wisps
    _ec = this;
    delete[] _wisps;
    delete[] _backwisps;
       _wisps     = new wisp[dWisps];
       _backwisps = new wisp[dBackground];
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class wisp [friend]

Definition at line 114 of file Euphoria.h.


Member Data Documentation

Definition at line 75 of file Euphoria.h.

Definition at line 112 of file Euphoria.h.

QTimer* EuphoriaWidget::_timer [private]

Definition at line 111 of file Euphoria.h.

Definition at line 74 of file Euphoria.h.

float EuphoriaWidget::aspectRatio [private]

Definition at line 77 of file Euphoria.h.

Definition at line 96 of file Euphoria.h.

int EuphoriaWidget::dDensity [private]

Definition at line 97 of file Euphoria.h.

Definition at line 100 of file Euphoria.h.

Definition at line 102 of file Euphoria.h.

Definition at line 101 of file Euphoria.h.

Definition at line 105 of file Euphoria.h.

float EuphoriaWidget::dSpeed [private]

Definition at line 99 of file Euphoria.h.

int EuphoriaWidget::dTexture [private]

Definition at line 104 of file Euphoria.h.

Definition at line 98 of file Euphoria.h.

Definition at line 103 of file Euphoria.h.

int EuphoriaWidget::dWisps [private]

Definition at line 95 of file Euphoria.h.

double EuphoriaWidget::elapsedTime [private]

Definition at line 79 of file Euphoria.h.

float EuphoriaWidget::f[4] [private]

Definition at line 87 of file Euphoria.h.

unsigned char* EuphoriaWidget::feedbackmap [private]

Definition at line 76 of file Euphoria.h.

unsigned int EuphoriaWidget::feedbacktex [private]

Definition at line 82 of file Euphoria.h.

Definition at line 83 of file Euphoria.h.

float EuphoriaWidget::fr[4] [private]

Definition at line 85 of file Euphoria.h.

float EuphoriaWidget::fv[4] [private]

Definition at line 86 of file Euphoria.h.

float EuphoriaWidget::l[3] [private]

Definition at line 91 of file Euphoria.h.

float EuphoriaWidget::lr[3] [private]

Definition at line 89 of file Euphoria.h.

float EuphoriaWidget::lv[3] [private]

Definition at line 90 of file Euphoria.h.

GLuint EuphoriaWidget::texName [private]

Definition at line 73 of file Euphoria.h.

int EuphoriaWidget::viewport[4] [private]

Definition at line 78 of file Euphoria.h.


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