Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/world_entities/weather_effects/lense_flare.cc @ 9760

Last change on this file since 9760 was 9760, checked in by bensch, 18 years ago

moved around the weather effecs

File size: 5.8 KB
RevLine 
[6776]1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13### File Specific:
14   main-programmer: Patrick Boenzli
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
18
19#include "lense_flare.h"
20
[7193]21#include "util/loading/load_param.h"
22#include "util/loading/factory.h"
[6776]23
[8495]24#include "glincl.h"
[6779]25#include "texture.h"
[6776]26
[6786]27#include "light.h"
[6787]28#include "state.h"
[9727]29#include "debug.h"
[6786]30
[7810]31#include "render2D/image_plane.h"
[6776]32
[6884]33#include "light.h"
[6889]34#include "camera.h"
[6884]35
[9716]36#include "class_id_DEPRECATED.h"
[6976]37
[9715]38ObjectListDefinitionID(LenseFlare, CL_LENSE_FLARE);
[9709]39CREATE_FACTORY(LenseFlare);
[6776]40
41/**
[7843]42 * @brief default constructor
[6776]43 * @param root The XML-element to load the LenseFlare from
44 */
[8495]45LenseFlare::LenseFlare(const TiXmlElement* root) {
[9686]46  this->registerObject(this, LenseFlare::_objectList);
[6787]47
[8495]48    /*          length                      image scale */
49    this->flareMatrix[0] = 1.0f;
50    this->flareMatrix[1] = 1.0f;
51    this->flareMatrix[2] = 0.5f;
52    this->flareMatrix[3] = 0.5f;
53    this->flareMatrix[4] = 0.33f;
54    this->flareMatrix[5] = 0.25f;
55    this->flareMatrix[6] = 0.125f;
56    this->flareMatrix[7] = 1.0f;
57    this->flareMatrix[8] = -0.5f;
58    this->flareMatrix[9] = 0.5f;
59    this->flareMatrix[10] = -0.25f;
60    this->flareMatrix[11] = 0.15f;
61    this->flareMatrix[12] = -1.82f;
62    this->flareMatrix[13] = 0.25f;
[6884]63
[8495]64    this->lightSource = (LightManager::getInstance())->getLight(0);
[9006]65    PRINTF(4)("light is: %p\n", this->lightSource);
[6980]66
[8495]67    if (root != NULL) {
68        this->loadParams(root);
69        this->activate();
70    }
[7015]71
[8495]72    this->bVisible = true;
73    this->setSourceVisibility(false);
[7015]74
[6776]75}
76
77
78/**
79 *  destroys a LenseFlare
80 */
[8495]81LenseFlare::~LenseFlare() {
82    std::vector<ImagePlane*>::iterator it;
83    for( it = flares.begin(); it != flares.end(); it++)
84        delete (*it);
[6783]85}
[6776]86
87
88/**
89 * @param root The XML-element to load the LenseFlare from
90 */
[8495]91void LenseFlare::loadParams(const TiXmlElement* root) {
92    GraphicsEffect::loadParams(root);
[6776]93
[8495]94    LOAD_PARAM_START_CYCLE(root, element);
95    {
96        LoadParam_CYCLE(element, "add-flare-texture", this, LenseFlare, addFlare)
[6779]97        .describe("adds a lensflare texture to the engine");
[8495]98    }
99    LOAD_PARAM_END_CYCLE(element);
[6776]100}
101
[7009]102
[6776]103/**
104 * initializes the fog effect
105 */
[8495]106void LenseFlare::init() {}
[6776]107
108
109/**
110 * activates the fog effect
111 */
[8495]112void LenseFlare::activate() {
113    this->bActivated = true;
[6776]114}
115
116
117/**
118 * deactivates the fog effect
119 */
[8495]120void LenseFlare::deactivate() {
121    this->bActivated = false;
[6776]122}
123
124
125/**
[7843]126 * @brief converts a gl mode char to a GLint
[6776]127 * @param mode the mode character
128 */
[8495]129GLint LenseFlare::stringToFogMode(const std::string& mode) {
130    return 0;
[8316]131}
[6776]132
[6779]133
134/**
[7843]135 * @brief adds a texture flare
[6779]136 * @param textureName the name of the flare texture
[6783]137 *
[6785]138 *  1st: Texture of the Sun/Light source itself
139 *  2nd: Texture of the fist halo
140 *  3rd: Texture of small burst
141 *  4th: Texture of the second halo
142 *  5th: Texutre of the second burst
143 *  6th: Texture of the third halo
144 *  7th: Texture of the third burst
[6779]145 */
[8495]146void LenseFlare::addFlare(const std::string& textureName) {
147    if( this->flares.size() > LF_MAX_FLARES) {
148        PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
149        return;
150    }
[6787]151
[8495]152    ImagePlane* bb = new ImagePlane(NULL);
153    if (this->flares.empty())
154        bb->setLayer(E2D_LAYER_BELOW_ALL);
155    bb->setTexture(textureName);
156    bb->setSize(50, 50);
157    this->flares.push_back(bb);
158    bb->setVisibility(true);
[7844]159
[8495]160    PRINTF(4)("Added a Lenseflare ImagePlane with texture %s\n", textureName.c_str());
[6785]161
[8495]162    // the first flare belongs to the light source
163    if( this->flares.size() == 1 && this->lightSource != NULL) {
164        bb->setBindNode(static_cast<PNode*>(this->lightSource));
165    }
[7843]166
[8495]167    PRINTF(4)("Finished adding\n");
[6782]168}
[6779]169
170
[8495]171void LenseFlare::setSourceVisibility(bool visibility) {
172    if (this->bVisible == visibility)
173        return;
[6887]174
[8495]175    std::vector<ImagePlane*>::const_iterator it;
[7844]176    for(it = ++flares.begin(); it != flares.end(); it++)
[8495]177        (*it)->setVisibility(visibility);
178    this->bVisible = visibility;
[6886]179}
[6785]180
[6885]181
[6782]182/**
[6785]183 * tick the effect
184 */
[8495]185void LenseFlare::tick(float dt) {
186    if( unlikely(!this->bActivated || this->flares.size() == 0))
187        return;
[6884]188
[8495]189    // refetch light source information if needed
190    if( unlikely( this->lightSource == NULL)) {
191        this->lightSource = (LightManager::getInstance())->getLight(0);
192        if( this->flares.size() > 0)
193            this->flares[0]->setBindNode(static_cast<PNode*>(this->lightSource));
194    }
[6884]195
[6889]196    //set the frustum plane
[8495]197    if (!flares.empty())
198        this->setSourceVisibility(this->flares[0]->isVisible());
[6885]199
[6889]200
[8495]201    // always update the screen center, it could be, that the window is resized
202    this->screenCenter = Vector2D(State::getResX()/2.0f, State::getResY()/2.0f);
[7015]203
[8495]204    // flare vector is the direction from the center to the light source
205    this->flareVector = this->flares[0]->getAbsCoor2D() - this->screenCenter;
206    this->distance = this->flareVector.len();
207    this->flareVector.normalize();
[6785]208
[8495]209    // now calculate the new coordinates of the billboards
210    std::vector<ImagePlane*>::iterator it;
211    int i;
212    for( it = flares.begin(), i = 0; it != flares.end(); it++, i++) {
213        // set the new position
214        if( i == 0)
215            continue;
[6889]216
[8495]217        (*it)->setAbsCoor2D( this->screenCenter + this->flareVector * this->flareMatrix[i * 2] * this->distance);
218        (*it)->setSize2D(50.0f * this->flareMatrix[i * 2 + 1], 50.0f * this->flareMatrix[i * 2 + 1]);
219        PRINTF(5)("Tick flare %i @ (%f, %f)\n", i, (*it)->getAbsCoor2D().x, (*it)->getAbsCoor2D().y);
220    }
[6785]221}
222
223
224/**
[6782]225 * draws the LenseFlares
226 */
[8495]227void LenseFlare::draw() const {
228    if( !this->bActivated)
229        return;
[6779]230}
Note: See TracBrowser for help on using the repository browser.