Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6787 in orxonox.OLD for branches/network/src/lib/graphics/effects


Ignore:
Timestamp:
Jan 27, 2006, 11:11:25 AM (19 years ago)
Author:
patrick
Message:

newtork: the lenseflare algorithm should be finished

Location:
branches/network/src/lib/graphics/effects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/graphics/effects/lense_flare.cc

    r6786 r6787  
    2626
    2727#include "light.h"
     28#include "state.h"
    2829
    2930#include "render2D/billboard.h"
     
    4344  if (root != NULL)
    4445    this->loadParams(root);
     46
     47  this->flareMatrix = new float[14];
     48  /*          length                      image scale */
     49  this->flareMatrix[0] = 1.0f; this->flareMatrix[1] = 1.0f;
     50  this->flareMatrix[2] = 0.5f; this->flareMatrix[3] = 0.5f;
     51  this->flareMatrix[4] = 0.33f; this->flareMatrix[5] = 0.25f;
     52  this->flareMatrix[6] = 0.125f; this->flareMatrix[7] = 1.0f;
     53  this->flareMatrix[8] = -0.5f; this->flareMatrix[9] = 0.5f;
     54  this->flareMatrix[10] = -0.25f; this->flareMatrix[11] = 0.25f;
     55  this->flareMatrix[12] = 1.82f; this->flareMatrix[13] = 0.25f;
    4556}
    4657
     
    116127void LenseFlare::addFlare(const char* textureName)
    117128{
     129  if( this->flares.size() < LF_MAX_FLARES)
     130  {
     131    PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
     132    return;
     133  }
     134
    118135  Billboard* bb = new Billboard(NULL);
    119136  bb->setTexture(textureName);
    120137  this->flares.push_back(bb);
     138  PRINTF(0)("Added a Lenseflare Billboard with texture %s\n", textureName);
    121139
    122140  // the first flare belongs to the light source
     
    134152void LenseFlare::tick(float dt)
    135153{
     154  if( unlikely(!this->bActivated || this->flares.size() == 0))
     155    return;
     156  // always update the screen center, it could be, that the window is resized
     157  this->screenCenter = Vector(State::getResX()/2.0f, State::getResY()/2.0f, 0.0f);
     158  // flare vector is the direction from the center to the light source
     159  this->flareVector = this->flares[0]->getAbsCoor2D();
     160  this->distance = this->flareVector.len();
     161  this->flareVector.normalize();
    136162
     163  // now calculate the new coordinates of the billboards
     164  std::vector<Billboard*>::iterator it;
     165  int i;
     166  for( it = flares.begin(), i = 0; it != flares.end(); it++, i++)
     167  {
     168    // set the new position
     169    (*it)->setAbsCoor2D(this->flareVector * this->flareMatrix[i * 2]);
     170    PRINTF(0)("Drawing flare %i @ (%f, %f)\n", i, (this->flareVector * this->flareMatrix[i * 2]).x, (this->flareVector * this->flareMatrix[i * 2]).y);
     171    // tick them
     172    (*it)->tick(dt);
     173  }
    137174}
    138175
  • branches/network/src/lib/graphics/effects/lense_flare.h

    r6786 r6787  
    1212
    1313#include "vector.h"
     14
     15
     16#define LF_MAX_FLARES 7
     17
    1418
    1519class TiXmlElement;
     
    4650
    4751    Vector                   flareVector;        //!< the axis to draw the flares on
     52    float                    distance;           //!< distance from center to source
    4853    Vector                   screenCenter;       //!< the vector marking the center of the screen
     54
     55    float*                   flareMatrix;
    4956};
    5057
Note: See TracChangeset for help on using the changeset viewer.