Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 15, 2006, 9:50:56 PM (19 years ago)
Author:
bensch
Message:

merged the branche atmos back. no conflicts

File:
1 edited

Legend:

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

    r8362 r8495  
    2222#include "util/loading/factory.h"
    2323
     24#include "glincl.h"
    2425#include "texture.h"
    2526
     
    4344 * @param root The XML-element to load the LenseFlare from
    4445 */
    45  LenseFlare::LenseFlare(const TiXmlElement* root)
    46 {
    47   this->setClassID(CL_LENSE_FLARE, "LenseFlare");
    48 
    49   this->flareMatrix = new float[14];
    50   /*          length                      image scale */
    51   this->flareMatrix[0] = 1.0f; this->flareMatrix[1] = 1.0f;
    52   this->flareMatrix[2] = 0.5f; this->flareMatrix[3] = 0.5f;
    53   this->flareMatrix[4] = 0.33f; this->flareMatrix[5] = 0.25f;
    54   this->flareMatrix[6] = 0.125f; this->flareMatrix[7] = 1.0f;
    55   this->flareMatrix[8] = -0.5f; this->flareMatrix[9] = 0.5f;
    56   this->flareMatrix[10] = -0.25f; this->flareMatrix[11] = 0.15f;
    57   this->flareMatrix[12] = -1.82f; this->flareMatrix[13] = 0.25f;
    58 
    59   this->lightSource = (LightManager::getInstance())->getLight(0);
    60   PRINTF(0)("light is: %p\n", this->lightSource);
    61 
    62   if (root != NULL)
    63   {
    64     this->loadParams(root);
    65     this->activate();
    66   }
    67 
    68   this->bVisible = true;
    69   this->setSourceVisibility(false);
     46LenseFlare::LenseFlare(const TiXmlElement* root) {
     47    this->setClassID(CL_LENSE_FLARE, "LenseFlare");
     48
     49    this->flareMatrix = new float[14];
     50    /*          length                      image scale */
     51    this->flareMatrix[0] = 1.0f;
     52    this->flareMatrix[1] = 1.0f;
     53    this->flareMatrix[2] = 0.5f;
     54    this->flareMatrix[3] = 0.5f;
     55    this->flareMatrix[4] = 0.33f;
     56    this->flareMatrix[5] = 0.25f;
     57    this->flareMatrix[6] = 0.125f;
     58    this->flareMatrix[7] = 1.0f;
     59    this->flareMatrix[8] = -0.5f;
     60    this->flareMatrix[9] = 0.5f;
     61    this->flareMatrix[10] = -0.25f;
     62    this->flareMatrix[11] = 0.15f;
     63    this->flareMatrix[12] = -1.82f;
     64    this->flareMatrix[13] = 0.25f;
     65
     66    this->lightSource = (LightManager::getInstance())->getLight(0);
     67    PRINTF(0)("light is: %p\n", this->lightSource);
     68
     69    if (root != NULL) {
     70        this->loadParams(root);
     71        this->activate();
     72    }
     73
     74    this->bVisible = true;
     75    this->setSourceVisibility(false);
    7076
    7177}
     
    7581 *  destroys a LenseFlare
    7682 */
    77 LenseFlare::~LenseFlare()
    78 {
    79   std::vector<ImagePlane*>::iterator it;
    80   for( it = flares.begin(); it != flares.end(); it++)
    81     delete (*it);
     83LenseFlare::~LenseFlare() {
     84    std::vector<ImagePlane*>::iterator it;
     85    for( it = flares.begin(); it != flares.end(); it++)
     86        delete (*it);
    8287}
    8388
     
    8691 * @param root The XML-element to load the LenseFlare from
    8792 */
    88 void LenseFlare::loadParams(const TiXmlElement* root)
    89 {
    90   GraphicsEffect::loadParams(root);
    91 
    92   LOAD_PARAM_START_CYCLE(root, element);
    93   {
    94     LoadParam_CYCLE(element, "add-flare-texture", this, LenseFlare, addFlare)
     93void LenseFlare::loadParams(const TiXmlElement* root) {
     94    GraphicsEffect::loadParams(root);
     95
     96    LOAD_PARAM_START_CYCLE(root, element);
     97    {
     98        LoadParam_CYCLE(element, "add-flare-texture", this, LenseFlare, addFlare)
    9599        .describe("adds a lensflare texture to the engine");
    96   }
    97   LOAD_PARAM_END_CYCLE(element);
     100    }
     101    LOAD_PARAM_END_CYCLE(element);
    98102}
    99103
     
    102106 * initializes the fog effect
    103107 */
    104 bool LenseFlare::init()
    105 {
    106   return true;
    107 }
     108void LenseFlare::init() {}
    108109
    109110
     
    111112 * activates the fog effect
    112113 */
    113 bool LenseFlare::activate()
    114 {
    115   this->bActivated = true;
    116 
    117   return true;
     114void LenseFlare::activate() {
     115    this->bActivated = true;
    118116}
    119117
     
    122120 * deactivates the fog effect
    123121 */
    124 bool LenseFlare::deactivate()
    125 {
    126   this->bActivated = false;
    127 
    128   return true;
     122void LenseFlare::deactivate() {
     123    this->bActivated = false;
    129124}
    130125
     
    134129 * @param mode the mode character
    135130 */
    136 GLint LenseFlare::stringToFogMode(const std::string& mode)
    137 {
    138   PRINTF(1)("NOT IMPLEMENTED");
    139   return 0;
     131GLint LenseFlare::stringToFogMode(const std::string& mode) {
     132    return 0;
    140133}
    141134
     
    153146 *  7th: Texture of the third burst
    154147 */
    155 void LenseFlare::addFlare(const std::string& textureName)
    156 {
    157   if( this->flares.size() > LF_MAX_FLARES)
    158   {
    159     PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
    160     return;
    161   }
    162 
    163   ImagePlane* bb = new ImagePlane(NULL);
    164   if (this->flares.empty())
    165     bb->setLayer(E2D_LAYER_BELOW_ALL);
    166   bb->setTexture(textureName);
    167   bb->setSize(50, 50);
    168   this->flares.push_back(bb);
    169   bb->setVisibility(true);
    170 
    171   PRINTF(4)("Added a Lenseflare ImagePlane with texture %s\n", textureName.c_str());
    172 
    173   // the first flare belongs to the light source
    174   if( this->flares.size() == 1 && this->lightSource != NULL)
    175   {
    176     bb->setBindNode(static_cast<PNode*>(this->lightSource));
    177   }
    178 
    179   PRINTF(4)("Finished adding\n");
    180 }
    181 
    182 
    183 void LenseFlare::setSourceVisibility(bool visibility)
    184 {
    185    if (this->bVisible == visibility)
    186      return;
    187 
    188   std::vector<ImagePlane*>::const_iterator it;
     148void LenseFlare::addFlare(const std::string& textureName) {
     149    if( this->flares.size() > LF_MAX_FLARES) {
     150        PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
     151        return;
     152    }
     153
     154    ImagePlane* bb = new ImagePlane(NULL);
     155    if (this->flares.empty())
     156        bb->setLayer(E2D_LAYER_BELOW_ALL);
     157    bb->setTexture(textureName);
     158    bb->setSize(50, 50);
     159    this->flares.push_back(bb);
     160    bb->setVisibility(true);
     161
     162    PRINTF(4)("Added a Lenseflare ImagePlane with texture %s\n", textureName.c_str());
     163
     164    // the first flare belongs to the light source
     165    if( this->flares.size() == 1 && this->lightSource != NULL) {
     166        bb->setBindNode(static_cast<PNode*>(this->lightSource));
     167    }
     168
     169    PRINTF(4)("Finished adding\n");
     170}
     171
     172
     173void LenseFlare::setSourceVisibility(bool visibility) {
     174    if (this->bVisible == visibility)
     175        return;
     176
     177    std::vector<ImagePlane*>::const_iterator it;
    189178    for(it = ++flares.begin(); it != flares.end(); it++)
    190       (*it)->setVisibility(visibility);
    191   this->bVisible = visibility;
     179        (*it)->setVisibility(visibility);
     180    this->bVisible = visibility;
    192181}
    193182
     
    196185 * tick the effect
    197186 */
    198 void LenseFlare::tick(float dt)
    199 {
    200   if( unlikely(!this->bActivated || this->flares.size() == 0))
    201     return;
    202 
    203   // refetch light source information if needed
    204   if( unlikely( this->lightSource == NULL))
    205   {
    206     this->lightSource = (LightManager::getInstance())->getLight(0);
    207     if( this->flares.size() > 0)
    208       this->flares[0]->setBindNode(static_cast<PNode*>(this->lightSource));
    209   }
     187void LenseFlare::tick(float dt) {
     188    if( unlikely(!this->bActivated || this->flares.size() == 0))
     189        return;
     190
     191    // refetch light source information if needed
     192    if( unlikely( this->lightSource == NULL)) {
     193        this->lightSource = (LightManager::getInstance())->getLight(0);
     194        if( this->flares.size() > 0)
     195            this->flares[0]->setBindNode(static_cast<PNode*>(this->lightSource));
     196    }
    210197
    211198    //set the frustum plane
    212   if (!flares.empty())
    213     this->setSourceVisibility(this->flares[0]->isVisible());
    214 
    215 
    216   // always update the screen center, it could be, that the window is resized
    217   this->screenCenter = Vector2D(State::getResX()/2.0f, State::getResY()/2.0f);
    218 
    219   // flare vector is the direction from the center to the light source
    220   this->flareVector = this->flares[0]->getAbsCoor2D() - this->screenCenter;
    221   this->distance = this->flareVector.len();
    222   this->flareVector.normalize();
    223 
    224   // now calculate the new coordinates of the billboards
    225   std::vector<ImagePlane*>::iterator it;
    226   int i;
    227   for( it = flares.begin(), i = 0; it != flares.end(); it++, i++)
    228   {
    229     // set the new position
    230     if( i == 0)
    231       continue;
    232 
    233     (*it)->setAbsCoor2D( this->screenCenter + this->flareVector * this->flareMatrix[i * 2] * this->distance);
    234     (*it)->setSize2D(50.0f * this->flareMatrix[i * 2 + 1], 50.0f * this->flareMatrix[i * 2 + 1]);
    235     PRINTF(5)("Tick flare %i @ (%f, %f)\n", i, (*it)->getAbsCoor2D().x, (*it)->getAbsCoor2D().y);
    236   }
     199    if (!flares.empty())
     200        this->setSourceVisibility(this->flares[0]->isVisible());
     201
     202
     203    // always update the screen center, it could be, that the window is resized
     204    this->screenCenter = Vector2D(State::getResX()/2.0f, State::getResY()/2.0f);
     205
     206    // flare vector is the direction from the center to the light source
     207    this->flareVector = this->flares[0]->getAbsCoor2D() - this->screenCenter;
     208    this->distance = this->flareVector.len();
     209    this->flareVector.normalize();
     210
     211    // now calculate the new coordinates of the billboards
     212    std::vector<ImagePlane*>::iterator it;
     213    int i;
     214    for( it = flares.begin(), i = 0; it != flares.end(); it++, i++) {
     215        // set the new position
     216        if( i == 0)
     217            continue;
     218
     219        (*it)->setAbsCoor2D( this->screenCenter + this->flareVector * this->flareMatrix[i * 2] * this->distance);
     220        (*it)->setSize2D(50.0f * this->flareMatrix[i * 2 + 1], 50.0f * this->flareMatrix[i * 2 + 1]);
     221        PRINTF(5)("Tick flare %i @ (%f, %f)\n", i, (*it)->getAbsCoor2D().x, (*it)->getAbsCoor2D().y);
     222    }
    237223}
    238224
     
    241227 * draws the LenseFlares
    242228 */
    243 void LenseFlare::draw() const
    244 {
    245   if( !this->bActivated)
    246     return;
    247 }
     229void LenseFlare::draw() const {
     230    if( !this->bActivated)
     231        return;
     232}
Note: See TracChangeset for help on using the changeset viewer.