Changeset 8457 in orxonox.OLD for branches/atmospheric_engine/src/lib/graphics/effects/lense_flare.cc
- Timestamp:
- Jun 15, 2006, 1:43:24 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/lense_flare.cc
r7844 r8457 44 44 * @param root The XML-element to load the LenseFlare from 45 45 */ 46 LenseFlare::LenseFlare(const TiXmlElement* root) 47 { 48 this->setClassID(CL_LENSE_FLARE, "LenseFlare"); 49 50 this->flareMatrix = new float[14]; 51 /* length image scale */ 52 this->flareMatrix[0] = 1.0f; this->flareMatrix[1] = 1.0f; 53 this->flareMatrix[2] = 0.5f; this->flareMatrix[3] = 0.5f; 54 this->flareMatrix[4] = 0.33f; this->flareMatrix[5] = 0.25f; 55 this->flareMatrix[6] = 0.125f; this->flareMatrix[7] = 1.0f; 56 this->flareMatrix[8] = -0.5f; this->flareMatrix[9] = 0.5f; 57 this->flareMatrix[10] = -0.25f; this->flareMatrix[11] = 0.15f; 58 this->flareMatrix[12] = -1.82f; this->flareMatrix[13] = 0.25f; 59 60 this->lightSource = (LightManager::getInstance())->getLight(0); 61 PRINTF(0)("light is: %p\n", this->lightSource); 62 63 if (root != NULL) 64 { 65 this->loadParams(root); 66 this->activate(); 67 } 68 69 this->bVisible = true; 70 this->setSourceVisibility(false); 46 LenseFlare::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); 71 76 72 77 } … … 76 81 * destroys a LenseFlare 77 82 */ 78 LenseFlare::~LenseFlare() 79 { 80 std::vector<ImagePlane*>::iterator it; 81 for( it = flares.begin(); it != flares.end(); it++) 82 delete (*it); 83 LenseFlare::~LenseFlare() { 84 std::vector<ImagePlane*>::iterator it; 85 for( it = flares.begin(); it != flares.end(); it++) 86 delete (*it); 83 87 } 84 88 … … 87 91 * @param root The XML-element to load the LenseFlare from 88 92 */ 89 void LenseFlare::loadParams(const TiXmlElement* root) 90 { 91 GraphicsEffect::loadParams(root); 92 93 LOAD_PARAM_START_CYCLE(root, element); 94 { 95 LoadParam_CYCLE(element, "add-flare-texture", this, LenseFlare, addFlare) 93 void 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) 96 99 .describe("adds a lensflare texture to the engine"); 97 }98 LOAD_PARAM_END_CYCLE(element);100 } 101 LOAD_PARAM_END_CYCLE(element); 99 102 } 100 103 … … 103 106 * initializes the fog effect 104 107 */ 105 bool LenseFlare::init() 106 {} 108 void LenseFlare::init() {} 107 109 108 110 … … 110 112 * activates the fog effect 111 113 */ 112 bool LenseFlare::activate() 113 { 114 this->bActivated = true; 114 void LenseFlare::activate() { 115 this->bActivated = true; 115 116 } 116 117 … … 119 120 * deactivates the fog effect 120 121 */ 121 bool LenseFlare::deactivate() 122 { 123 this->bActivated = false; 122 void LenseFlare::deactivate() { 123 this->bActivated = false; 124 124 } 125 125 … … 129 129 * @param mode the mode character 130 130 */ 131 GLint LenseFlare::stringToFogMode(const std::string& mode) 132 {} 131 GLint LenseFlare::stringToFogMode(const std::string& mode) { 132 return 0; 133 } 133 134 134 135 … … 145 146 * 7th: Texture of the third burst 146 147 */ 147 void LenseFlare::addFlare(const std::string& textureName) 148 { 149 if( this->flares.size() > LF_MAX_FLARES) 150 { 151 PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES); 152 return; 153 } 154 155 ImagePlane* bb = new ImagePlane(NULL); 156 if (this->flares.empty()) 157 bb->setLayer(E2D_LAYER_BELOW_ALL); 158 bb->setTexture(textureName); 159 bb->setSize(50, 50); 160 this->flares.push_back(bb); 161 bb->setVisibility(true); 162 163 PRINTF(4)("Added a Lenseflare ImagePlane with texture %s\n", textureName.c_str()); 164 165 // the first flare belongs to the light source 166 if( this->flares.size() == 1 && this->lightSource != NULL) 167 { 168 bb->setBindNode(static_cast<PNode*>(this->lightSource)); 169 } 170 171 PRINTF(4)("Finished adding\n"); 172 } 173 174 175 void LenseFlare::setSourceVisibility(bool visibility) 176 { 177 if (this->bVisible == visibility) 178 return; 179 180 std::vector<ImagePlane*>::const_iterator it; 148 void 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 173 void LenseFlare::setSourceVisibility(bool visibility) { 174 if (this->bVisible == visibility) 175 return; 176 177 std::vector<ImagePlane*>::const_iterator it; 181 178 for(it = ++flares.begin(); it != flares.end(); it++) 182 (*it)->setVisibility(visibility);183 this->bVisible = visibility;179 (*it)->setVisibility(visibility); 180 this->bVisible = visibility; 184 181 } 185 182 … … 188 185 * tick the effect 189 186 */ 190 void LenseFlare::tick(float dt) 191 { 192 if( unlikely(!this->bActivated || this->flares.size() == 0)) 193 return; 194 195 // refetch light source information if needed 196 if( unlikely( this->lightSource == NULL)) 197 { 198 this->lightSource = (LightManager::getInstance())->getLight(0); 199 if( this->flares.size() > 0) 200 this->flares[0]->setBindNode(static_cast<PNode*>(this->lightSource)); 201 } 187 void 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 } 202 197 203 198 //set the frustum plane 204 if (!flares.empty()) 205 this->setSourceVisibility(this->flares[0]->isVisible()); 206 207 208 // always update the screen center, it could be, that the window is resized 209 this->screenCenter = Vector2D(State::getResX()/2.0f, State::getResY()/2.0f); 210 211 // flare vector is the direction from the center to the light source 212 this->flareVector = this->flares[0]->getAbsCoor2D() - this->screenCenter; 213 this->distance = this->flareVector.len(); 214 this->flareVector.normalize(); 215 216 // now calculate the new coordinates of the billboards 217 std::vector<ImagePlane*>::iterator it; 218 int i; 219 for( it = flares.begin(), i = 0; it != flares.end(); it++, i++) 220 { 221 // set the new position 222 if( i == 0) 223 continue; 224 225 (*it)->setAbsCoor2D( this->screenCenter + this->flareVector * this->flareMatrix[i * 2] * this->distance); 226 (*it)->setSize2D(50.0f * this->flareMatrix[i * 2 + 1], 50.0f * this->flareMatrix[i * 2 + 1]); 227 PRINTF(5)("Tick flare %i @ (%f, %f)\n", i, (*it)->getAbsCoor2D().x, (*it)->getAbsCoor2D().y); 228 } 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 } 229 223 } 230 224 … … 233 227 * draws the LenseFlares 234 228 */ 235 void LenseFlare::draw() const 236 { 237 if( !this->bActivated) 238 return; 239 } 229 void LenseFlare::draw() const { 230 if( !this->bActivated) 231 return; 232 }
Note: See TracChangeset
for help on using the changeset viewer.