Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/effects/lense_flare.cc @ 9716

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

more renamings

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