Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/lense_flare.cc @ 6818

Last change on this file since 6818 was 6815, checked in by bensch, 19 years ago

orxonox/trunk: merged branches/network back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6774:HEAD

no conflicts…
thats what i call orthogonal work

File size: 4.3 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
21#include "load_param.h"
22#include "factory.h"
23
24#include "glincl.h"
[6779]25#include "texture.h"
[6776]26
[6786]27#include "light.h"
[6787]28#include "state.h"
[6786]29
[6782]30#include "render2D/billboard.h"
[6776]31
32using namespace std;
33
34CREATE_FACTORY(LenseFlare, CL_LENSE_FLARE);
35
36
37
38/**
39 *  default constructor
40 * @param root The XML-element to load the LenseFlare from
41 */
42 LenseFlare::LenseFlare(const TiXmlElement* root)
43{
44  if (root != NULL)
45    this->loadParams(root);
[6787]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;
[6776]56}
57
58
59/**
60 *  destroys a LenseFlare
61 */
62LenseFlare::~LenseFlare()
[6783]63{
64  std::vector<Billboard*>::iterator it;
65  for( it = flares.begin(); it != flares.end(); it++)
66    delete (*it);
67}
[6776]68
69
70/**
71 * @param root The XML-element to load the LenseFlare from
72 */
73void LenseFlare::loadParams(const TiXmlElement* root)
74{
75  GraphicsEffect::loadParams(root);
76
[6779]77    LoadParam(root, "add-flare-texture", this, LenseFlare, addFlare)
78        .describe("adds a lensflare texture to the engine");
[6776]79}
80
81
82/**
83 * initializes the fog effect
84 */
85bool LenseFlare::init()
[6782]86{}
[6776]87
88
89/**
90 * activates the fog effect
91 */
92bool LenseFlare::activate()
93{
[6782]94  this->bActivated = true;
[6776]95}
96
97
98/**
99 * deactivates the fog effect
100 */
101bool LenseFlare::deactivate()
102{
[6782]103  this->bActivated = false;
[6776]104}
105
106
107/**
108 * converts a gl mode char to a GLint
109 * @param mode the mode character
110 */
111GLint LenseFlare::charToFogMode(const char* mode)
112{}
113
[6779]114
115/**
116 * adds a texture flare
117 * @param textureName the name of the flare texture
[6783]118 *
[6785]119 *  1st: Texture of the Sun/Light source itself
120 *  2nd: Texture of the fist halo
121 *  3rd: Texture of small burst
122 *  4th: Texture of the second halo
123 *  5th: Texutre of the second burst
124 *  6th: Texture of the third halo
125 *  7th: Texture of the third burst
[6779]126 */
[6782]127void LenseFlare::addFlare(const char* textureName)
[6779]128{
[6787]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
[6782]135  Billboard* bb = new Billboard(NULL);
136  bb->setTexture(textureName);
[6783]137  this->flares.push_back(bb);
[6787]138  PRINTF(0)("Added a Lenseflare Billboard with texture %s\n", textureName);
[6785]139
140  // the first flare belongs to the light source
141  if( this->flares.size() == 1 && this->lightSource != NULL)
142  {
[6786]143    bb->setBindNode(static_cast<PNode*>(this->lightSource));
[6785]144  }
[6782]145}
[6779]146
147
[6785]148
[6782]149/**
[6785]150 * tick the effect
151 */
152void LenseFlare::tick(float dt)
153{
[6787]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();
[6785]162
[6787]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  }
[6785]174}
175
176
177/**
[6782]178 * draws the LenseFlares
179 */
180void LenseFlare::draw() const
181{
182  if( !this->bActivated)
183    return;
184
[6786]185  std::vector<Billboard*>::const_iterator it;
[6785]186  for( it = flares.begin(); it != flares.end(); it++)
187    (*it)->draw();
[6779]188}
Note: See TracBrowser for help on using the repository browser.