- Timestamp:
- Jun 15, 2006, 9:50:56 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_reaction/collision_handle.cc
r8490 r8495 1 1 /* 2 orxonox - the future of 3D-vertical-scrollers 2 orxonox - the future of 3D-vertical-scrollersf 3 3 4 4 Copyright (C) 2004 orx … … 101 101 return; 102 102 103 // add element 104 PRINTF(0)("addTarget: %i \n", target); 103 // add element 104 //PRINTF(0)("addTarget: %i \n", target); 105 105 106 this->targetList.push_back(target); 106 107 } -
trunk/src/lib/graphics/effects/atmospheric_engine.cc
r8190 r8495 30 30 * @param root The XML-element to load the AtmosphericEngine from 31 31 */ 32 AtmosphericEngine::AtmosphericEngine() 33 { 34 this->setClassID(CL_ATMOSPHERIC_ENGINE, "AtmosphericEngine"); 32 AtmosphericEngine::AtmosphericEngine() { 33 this->setClassID(CL_ATMOSPHERIC_ENGINE, "AtmosphericEngine"); 35 34 } 36 35 … … 44 43 * destroys a AtmosphericEngine 45 44 */ 46 AtmosphericEngine::~AtmosphericEngine() 47 { 48 AtmosphericEngine::singletonRef = NULL; 45 AtmosphericEngine::~AtmosphericEngine() { 46 AtmosphericEngine::singletonRef = NULL; 49 47 50 const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);48 const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); 51 49 52 if (weatherEffects != NULL) 53 { 54 while(!weatherEffects->empty()) 55 delete weatherEffects->front(); 56 } 50 if (weatherEffects != NULL) { 51 while(!weatherEffects->empty()) 52 delete weatherEffects->front(); 53 } 57 54 } 58 55 … … 60 57 * @param root The XML-element to load the AtmosphericEngine from 61 58 */ 62 void AtmosphericEngine::loadParams(const TiXmlElement* root) 63 { 64 LoadParamXML(root, "WeatherEffect", this, AtmosphericEngine, loadWeatherEffect); 65 LoadParamXML(root, "SunEffect", this, AtmosphericEngine, loadSunEffect); 59 void AtmosphericEngine::loadParams(const TiXmlElement* root) { 60 LoadParamXML(root, "WeatherEffect", this, AtmosphericEngine, loadWeatherEffect); 61 LoadParamXML(root, "SunEffect", this, AtmosphericEngine, loadSunEffect); 66 62 } 67 63 … … 69 65 * @param root The XML-element to load WeatherEffects from 70 66 */ 71 void AtmosphericEngine::loadWeatherEffect(const TiXmlElement* root) 72 { 73 LOAD_PARAM_START_CYCLE(root, element); 74 { 75 PRINTF(4)("element is: %s\n", element->Value()); 76 // Factory::fabricate(element); 67 void AtmosphericEngine::loadWeatherEffect(const TiXmlElement* root) { 68 LOAD_PARAM_START_CYCLE(root, element); 69 { 70 PRINTF(4)("element is: %s\n", element->Value()); 71 // Factory::fabricate(element); 77 72 78 BaseObject* bo = Factory::fabricate(element);79 if( bo == NULL)80 PRINTF(0)(" Could not create Element %s\n", element->Value());81 }82 LOAD_PARAM_END_CYCLE(element);73 BaseObject* bo = Factory::fabricate(element); 74 if( bo == NULL) 75 PRINTF(0)(" Could not create Element %s\n", element->Value()); 76 } 77 LOAD_PARAM_END_CYCLE(element); 83 78 } 84 79 … … 86 81 * @param root The XML-element to load SunEffects from 87 82 */ 88 void AtmosphericEngine::loadSunEffect(const TiXmlElement* root) 89 { 90 LOAD_PARAM_START_CYCLE(root, element); 91 { 92 PRINTF(4)("element is: %s\n", element->Value()); 93 } 94 LOAD_PARAM_END_CYCLE(element); 83 void AtmosphericEngine::loadSunEffect(const TiXmlElement* root) { 84 LOAD_PARAM_START_CYCLE(root, element); 85 { 86 PRINTF(4)("element is: %s\n", element->Value()); 87 } 88 LOAD_PARAM_END_CYCLE(element); 95 89 } 96 90 … … 99 93 * draws the effect, if needed 100 94 */ 101 void AtmosphericEngine::draw() const 102 { 103 const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); 95 void AtmosphericEngine::draw() const { 96 const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); 104 97 105 // draw the weather effects 106 if (weatherEffects != NULL) 107 { 108 std::list<BaseObject*>::const_iterator it; 109 for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) 110 dynamic_cast<WeatherEffect*>(*it)->draw(); 111 } 98 // draw the weather effects 99 if (weatherEffects != NULL) { 100 std::list<BaseObject*>::const_iterator it; 101 for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) 102 dynamic_cast<WeatherEffect*>(*it)->draw(); 103 } 112 104 } 113 105 … … 117 109 * ticks the effect if there is any time dependancy 118 110 */ 119 void AtmosphericEngine::tick(float dt) 120 { 121 const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); 111 void AtmosphericEngine::tick(float dt) { 112 const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); 122 113 123 // tick the weather effects 124 if (weatherEffects != NULL) 125 { 126 std::list<BaseObject*>::const_iterator it; 127 for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) 128 { 129 /* printf("%s::%s \n", (*it)->getClassName(), (*it)->getName());*/ 130 dynamic_cast<WeatherEffect*>(*it)->tick(dt); 114 // tick the weather effects 115 if (weatherEffects != NULL) { 116 std::list<BaseObject*>::const_iterator it; 117 for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) { 118 /* printf("%s::%s \n", (*it)->getClassName(), (*it)->getName());*/ 119 dynamic_cast<WeatherEffect*>(*it)->tick(dt); 120 } 131 121 } 132 }133 122 } -
trunk/src/lib/graphics/effects/cloud_effect.cc
r8255 r8495 21 21 #include "util/loading/resource_manager.h" 22 22 23 #include "glincl.h"24 23 #include "material.h" 25 24 #include <math.h> … … 31 30 #include "parser/tinyxml/tinyxml.h" 32 31 33 #include "sglmodel.h"34 32 35 33 using namespace std; … … 43 41 { 44 42 this->setClassID(CL_CLOUD_EFFECT, "CloudEffect"); 43 // this->toList(OM_ENVIRON); 45 44 46 45 this->init(); … … 49 48 this->loadParams(root); 50 49 51 if(cloudActivate)50 //if(cloudActivate) 52 51 this->activate(); 53 52 } … … 56 55 { 57 56 this->deactivate(); 58 59 delete this->cloudMaterial;60 61 cloudModel.Delete();62 Shader::unload(this->cloudShader);63 64 57 } 65 58 66 59 67 boolCloudEffect::init()60 void CloudEffect::init() 68 61 { 69 PRINTF(1)("Initializing CloudEffect\n"); 62 PRINTF(0)("Initializing CloudEffect\n"); 63 64 /// initialization of the texture coords, speeds etc... 65 /* this->move = 0.0f; 66 this->g_WaterUV = 35.0f; 67 this->kNormalMapScale = 0.25f; 68 this->g_WaterFlow = 0.0015f;*/ 69 70 cloudMaterial.setDiffuseMap("pictures/sky/cloud1.jpg", GL_TEXTURE_2D, 0); 70 71 71 // Default values 72 this->cloudActivate = false; 73 this->cloudTint[4] = ( 0.9f, 0.7f, 0.7f, 1.0f ); 74 this->cloudScroll = 1.0f; 75 this->time = 0.0f; 76 //g_cloud_texture = 0; 72 shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert", 73 ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag"); 74 75 this->shader->activateShader(); 77 76 78 this->cloudTexture = "pictures/sky/cloud1.jpg"; 79 80 cloudModel.Load("sky.sgl"); 81 cloudModel.Unitize(); 82 83 // Get the bounding box of the sky dome 84 float bbox[3] = {0}; 85 cloudModel.GetDimensions(bbox[0], bbox[1], bbox[2]); 86 87 // Load Shaders 88 this->cloudShader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/sky.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/sky.frag"); 89 90 // Tell the shader the bounding box of the sky dome 91 this->cloudShader->bindShader("bbox", bbox, 4); 92 93 // Initialze Cloud Material 94 this->cloudMaterial = new Material("Sky"); 95 this->cloudMaterial->setIllum(3); 96 this->cloudMaterial->setAmbient(1.0, 1.0, 1.0); 97 this->cloudMaterial->setDiffuseMap(this->cloudTexture); 98 77 Shader::Uniform(shader, "Noise").set(0); 78 Shader::Uniform(shader, "SkyColor").set(0.0f, 0.0f, 0.8f); 79 Shader::Uniform(shader, "CloudColor").set(0.8f, 0.8f, 0.8f); 80 81 // Change: Have to be updated each frame!like camerpos in mapped_water.cc 82 Shader::Uniform(shader, "Offset").set(0.0f, 0.0f, 0.0f); 83 84 Shader::Uniform(shader, "LightPos").set(100.0f, 100.0f, 100.0f); 85 Shader::Uniform(shader, "Scale").set(1.0f); 86 87 this->shader->deactivateShader(); 99 88 } 100 89 … … 106 95 // LoadParam(root, "speed", this, CloudEffect, setCloudAnimation); 107 96 // LoadParam(root, "texture", this, CloudEffect, setCloudTexture); 108 97 /* 109 98 LOAD_PARAM_START_CYCLE(root, element); 110 99 { 111 100 LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); 112 101 } 113 LOAD_PARAM_END_CYCLE(element); 102 LOAD_PARAM_END_CYCLE(element);*/ 114 103 } 115 104 116 105 117 boolCloudEffect::activate()106 void CloudEffect::activate() 118 107 { 119 PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str());108 PRINTF(0)( "Activating\n"); 120 109 121 this->cloudActivate = true; 122 110 // this->cloudActivate = true; 123 111 } 124 112 125 boolCloudEffect::deactivate()113 void CloudEffect::deactivate() 126 114 { 127 115 PRINTF(0)("Deactivating CloudEffect\n"); 128 116 129 this->cloudActivate = false;117 // this->cloudActivate = false; 130 118 } 131 119 132 120 void CloudEffect::draw() const 133 121 { 134 if (!this->cloudActivate) 135 return; 136 137 // glMatrixMode(GL_MODELVIEW); 138 // glPushMatrix(); 139 // 140 // // Move sphere along with the camera 141 // Vector r = State::getCameraNode()->getAbsCoor(); 142 // glTranslatef(r.x, r.y, r.z); 143 // 144 // // Sky movement 145 // glRotatef(mover, 0, 0, 1); 146 // 147 // cloudMaterial->select(); 148 // gluSphere(this->sphereObj, this->sphereRadius, 20, 20); 149 // glPopMatrix(); 122 //if (!this->cloudActivate) 123 // return; 150 124 151 // ****** 125 //glMatrixMode(GL_MODELVIEW); 126 //glColor4f(1,1,1,1); 127 glPushMatrix(); 128 //glTranslatef(0,this->waterHeight,0); 152 129 153 glMatrixMode(GL_MODELVIEW);154 glPushMatrix();130 cloudMaterial.unselect(); 131 cloudMaterial.select(); 155 132 156 // glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 157 // glShadeModel(GL_SMOOTH); 158 // glEnable(GL_DEPTH_TEST); 159 // glEnable(GL_CULL_FACE); 160 // glCullFace(GL_BACK); 161 // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 162 163 // glLineWidth(3.0f); 133 this->shader->activateShader(); 164 134 165 static float time = 0.0f;166 // static vector3f eye = {0.0f, 0.0f, 0.0f}, look = {0.0f, 0.0f, 1.0f}, up = {0.0f, 1.0f, 0.0f};167 135 168 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 169 // glLoadIdentity(); 170 // gluLookAt(eye[x], eye[y], eye[z], look[x], look[y], look[z], up[x], up[y], up[z]); 136 glBegin(GL_QUADS); 137 138 glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); 139 glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, 100.0f); 140 glTexCoord2f(0.0f, 0.0f); glVertex3f( 100.0f, 0.0f, 100.0f); 141 glTexCoord2f(1.0f, 0.0f); glVertex3f(100.0f, 0.0f, 0.0f); 142 143 glEnd(); 171 144 172 // Turn off the depth buffer when rendering the background 173 // glDisable(GL_DEPTH_TEST); 145 this->shader->deactivateShader(); 174 146 175 this->cloudShader->activateShader();147 cloudMaterial.unselect(); 176 148 177 /* Select the shader program and update parameters. */ 178 /* The "time" parameter controls the cloud scrolling. */ 179 this->cloudShader->bindShader("time", &time, 1); 180 /* The "horizon" parameter controls the sky tinting. */ 181 this->cloudShader->bindShader("horizon", cloudTint, 4); 149 glPopMatrix(); 182 150 183 glActiveTexture(GL_TEXTURE0 + 0);184 glActiveTexture(GL_TEXTURE0 + 1);185 186 // Load the cloud texture187 //glBindTexture(GL_TEXTURE_2D, g_cloud_texture);188 this->cloudMaterial->select();189 190 // Render the sky dome191 cloudModel.Render();192 193 // Unselect the shader194 Shader::deactivateShader();195 196 /* Turn on the depth buffer when rendering the foreground. */197 // glEnable(GL_DEPTH_TEST);198 199 /* Render the forground, for example, a teapot or bunny. */200 // glEnable(GL_LIGHTING);201 // glColor3f(0.0f, 1.0f, 0.0f);202 // glBegin(GL_QUADS);203 // glNormal3f( 0.0f, 1.0f, 0.0f);204 // glVertex3f( 20.0f, -1.0f, 20.0f);205 // glVertex3f( 20.0f, -1.0f, -20.0f);206 // glVertex3f(-20.0f, -1.0f, -20.0f);207 // glVertex3f(-20.0f, -1.0f, 20.0f);208 // glEnd();209 // glDisable(GL_LIGHTING);210 211 glPopMatrix();212 213 151 } 214 152 215 153 void CloudEffect::tick (float dt) 216 154 { 217 if (!this->cloudActivate) 218 return; 219 220 // Update the timer for scrolling the clouds 221 time = time + ((1.0f / 2000.0f) * cloudScroll); 155 //if (!this->cloudActivate) 156 // return; 222 157 } 223 158 -
trunk/src/lib/graphics/effects/cloud_effect.h
r8255 r8495 12 12 13 13 #include "world_entity.h" 14 #include "glincl.h" 14 #include "material.h" 15 #include "shader.h" 15 16 16 #include "sglmodel.h" 17 class CloudEffect : public WeatherEffect { 18 public: 19 CloudEffect(const TiXmlElement* root = NULL); 20 virtual ~CloudEffect(); 17 21 18 class Shader; 19 class Material; 20 class Vector; 22 virtual void loadParams(const TiXmlElement* root); 21 23 22 class CloudEffect : public WeatherEffect 23 { 24 public: 25 CloudEffect(const TiXmlElement* root = NULL); 26 virtual ~CloudEffect(); 24 virtual void init(); 27 25 28 virtual void loadParams(const TiXmlElement* root); 26 virtual void activate(); 27 virtual void deactivate(); 29 28 30 virtual bool init(); 29 inline void activateCloud() { 30 this->activate(); 31 } 32 inline void deactivateCloud() { 33 this->deactivate(); 34 } 31 35 32 virtual bool activate();33 virtual bool deactivate();36 virtual void draw() const; 37 virtual void tick(float dt); 34 38 35 inline void activateCloud() { this->activate(); } 36 inline void deactivateCloud() { this->deactivate(); } 37 38 virtual void draw() const; 39 virtual void tick(float dt); 40 41 inline void setCloudOption(const std::string& option) { 42 if (option == "activate") this->cloudActivate = true; 43 } 39 /*inline void setCloudOption(const std::string& option) { 40 if (option == "activate") 41 this->cloudActivate = true; 42 }*/ 44 43 45 44 46 47 45 private: 46 //void initialize(char* fileName); 48 47 49 boolcloudActivate;48 //bool cloudActivate; 50 49 51 Material* cloudMaterial; // A Material for the Sphere. 52 53 std::string cloudTexture; 54 55 Sglmodel_sgl cloudModel; 56 Shader* cloudShader; 57 58 GLfloat cloudTint[4]; 59 GLfloat cloudScroll; 60 61 float time; 62 50 Material cloudMaterial; 51 Shader* shader; 63 52 }; 64 53 -
trunk/src/lib/graphics/effects/fog_effect.cc
r8362 r8495 1 1 /* 2 3 4 5 6 7 8 9 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: hdavid, amaechler 13 13 */ 14 14 … … 22 22 SHELL_COMMAND(activate, FogEffect, activateFog); 23 23 SHELL_COMMAND(deactivate, FogEffect, deactivateFog); 24 SHELL_COMMAND(startfogging, FogEffect, startFogging); 24 SHELL_COMMAND(fadein, FogEffect, fadeInFog); 25 SHELL_COMMAND(fadeout, FogEffect, fadeOutFog); 26 27 // TODO: Fix fades 25 28 26 29 using namespace std; … … 28 31 CREATE_FACTORY(FogEffect, CL_FOG_EFFECT); 29 32 30 FogEffect::FogEffect(const TiXmlElement* root) 31 { 32 this->setClassID(CL_FOG_EFFECT, "FogEffect"); 33 34 this->init(); 35 36 if (root != NULL) 37 this->loadParams(root); 38 39 if (this->fogActivate) 40 this->activate(); 41 } 42 43 44 FogEffect::~FogEffect() 45 { 46 this->deactivate(); 47 } 48 49 50 void FogEffect::loadParams(const TiXmlElement* root) 51 { 52 WeatherEffect::loadParams(root);53 54 LoadParam(root, "mode", this, FogEffect, setFogMode);55 LoadParam(root, "density", this, FogEffect, setFogDensity);56 LoadParam(root, "range", this, FogEffect, setFogRange);57 LoadParam(root, "color", this, FogEffect, setFogColor); 58 59 LOAD_PARAM_START_CYCLE(root, element); 60 { 61 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption); 62 } 63 LOAD_PARAM_END_CYCLE(element); 64 } 65 66 bool FogEffect::init() 67 { 68 //default values 69 this->fogActivate = false;70 this->fogFadeDuration =0;71 this->localTimer = 0;72 73 this->fogMode = GL_EXP2; 74 this->fogDensity = 0.001;75 this->fogStart= 0;76 this->fogEnd = 5000;77 this->colorVector = Vector(0.7, 0.7, 0.7);78 79 return true;80 } 81 82 83 bool FogEffect::activate() 84 { 85 PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z); 86 87 this->fogActivate = true; 88 89 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; 90 glFogi(GL_FOG_MODE, this->fogMode);91 glFogfv(GL_FOG_COLOR, fogColor);92 glFogf(GL_FOG_DENSITY, this->fogDensity);93 94 glFogf(GL_FOG_START, this->fogStart);95 glFogf(GL_FOG_END, this->fogEnd);96 97 glEnable(GL_FOG); 98 // glClearColor(0.5, 0.5, 0.5, 1.0);99 return true; 100 } 101 102 103 bool FogEffect::deactivate() 104 { 105 PRINTF(0)("Deactivating FogEffect\n"); 106 107 this->fogActivate = false;108 109 glDisable(GL_FOG); 110 111 return true; 33 FogEffect::FogEffect(const TiXmlElement* root) { 34 this->setClassID(CL_FOG_EFFECT, "FogEffect"); 35 36 this->init(); 37 38 if (root != NULL) 39 this->loadParams(root); 40 41 if (this->fogActivate) 42 this->activate(); 43 } 44 45 46 FogEffect::~FogEffect() { 47 this->deactivate(); 48 } 49 50 51 void FogEffect::loadParams(const TiXmlElement* root) { 52 WeatherEffect::loadParams(root); 53 54 LoadParam(root, "mode", this, FogEffect, setFogMode); 55 LoadParam(root, "density", this, FogEffect, setFogDensity); 56 LoadParam(root, "range", this, FogEffect, setFogRange); 57 LoadParam(root, "color", this, FogEffect, setFogColor); 58 LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn); 59 LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut); 60 61 LOAD_PARAM_START_CYCLE(root, element); 62 { 63 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption); 64 } 65 LOAD_PARAM_END_CYCLE(element); 66 } 67 68 void FogEffect::init() { 69 // default values 70 this->fogMode = GL_LINEAR; 71 this->fogDensity = 0.03; 72 this->fogStart = 0; 73 this->fogEnd = 50; 74 this->colorVector = Vector(0.3, 0.3, 0.3); 75 76 // init variables 77 this->fogFadeInDuration = 0; 78 this->fogFadeOutDuration = 0; 79 this->fogFadeDensity = 0; 80 this->localTimer = 0; 81 this->fogActivate = false; 82 this->fogFadeInActivate = false; 83 this->fogFadeOutActivate = false; 84 85 } 86 87 88 void FogEffect::activate() { 89 PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z); 90 91 this->fogActivate = true; 92 93 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; 94 glFogi(GL_FOG_MODE, this->fogMode); 95 glFogfv(GL_FOG_COLOR, fogColor); 96 glHint(GL_FOG_HINT, GL_DONT_CARE); 97 glFogf(GL_FOG_DENSITY, this->fogDensity); 98 glFogf(GL_FOG_START, this->fogStart); 99 glFogf(GL_FOG_END, this->fogEnd); 100 101 glEnable(GL_FOG); 102 103 } 104 105 106 void FogEffect::deactivate() { 107 PRINTF(0)("Deactivating FogEffect\n"); 108 109 this->fogFadeInActivate = false; 110 this->fogFadeOutActivate = false; 111 this->fogActivate = false; 112 113 glDisable(GL_FOG); 114 112 115 } 113 116 114 117 void FogEffect::draw() const { 115 118 116 if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration) 117 glFogf(GL_FOG_DENSITY, this->fogFadeDensity); 118 //else 119 // glFogf(GL_FOG_DENSITY, this->fogDensity); 120 121 } 122 void FogEffect::tick(float dt) 123 { 124 if (!this->fogActivate) 125 return; 126 127 128 if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration) { 129 this->localTimer += dt; 130 float progress = this->localTimer / this->fogFadeDuration; 131 this->fogFadeDensity = progress * this->fogDensity; 132 } 133 } 134 135 void FogEffect::startFogging() { 136 137 if (this->fogActivate) 138 this->deactivate(); 139 140 this->fogFadeDuration = 10; 141 this->localTimer = 0; 142 this->activate(); 143 144 } 145 146 147 GLint FogEffect::stringToFogMode(const std::string& mode) 148 { 149 if(mode == "GL_LINEAR") 150 return GL_LINEAR; 151 else if(mode == "GL_EXP") 152 return GL_EXP; 153 else if(mode == "GL_EXP2" ) 154 return GL_EXP2; 155 else 156 return -1; 157 } 158 159 119 if (!this->fogActivate) 120 return; 121 122 // If Fog Fade 123 if ( this->fogFadeInActivate || this->fogFadeOutActivate ) 124 glFogf(GL_FOG_DENSITY, this->fogFadeDensity); 125 126 } 127 128 void FogEffect::tick(float dt) { 129 if (!this->fogActivate) 130 return; 131 132 if ( this->fogFadeInActivate ) { 133 this->localTimer += dt; 134 this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity; 135 136 if ( this->localTimer >= this->fogFadeOutDuration ) 137 this->fogFadeInActivate = false; 138 } 139 140 if ( this->fogFadeOutActivate ) { 141 this->localTimer += dt; 142 this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity); 143 144 if ( this->localTimer >= this->fogFadeOutDuration ) 145 this->deactivate(); 146 } 147 } 148 149 void FogEffect::fadeInFog() { 150 151 // If Fog is already fading out, stop it 152 this->fogFadeOutActivate = false; 153 154 // If Fog is already on, turn it off first 155 if (this->fogActivate) 156 this->deactivate(); 157 158 // If no manual FadeIn value was set, set a default value 159 if (!this->fogFadeInDuration > 0) 160 this->fogFadeInDuration = 20; 161 162 // Reset local timer 163 this->localTimer = 0; 164 165 // set FogFadeIn activate 166 this->fogFadeInActivate = true; 167 168 // Activate Fog 169 this->activate(); 170 171 } 172 173 174 void FogEffect::fadeOutFog() { 175 176 // If Fog is already fading in, stop it 177 this->fogFadeInActivate = false; 178 179 // If Fog is off, turn it on first 180 if (!this->fogActivate) 181 this->activate(); 182 183 // If no manual FadeOut value was set, set a default value 184 if (!this->fogFadeOutDuration > 0) 185 this->fogFadeOutDuration = 20; 186 187 // set FogFadeOut activate 188 this->fogFadeOutActivate = true; 189 190 // Reset local timer 191 this->localTimer = 0; 192 193 } 194 195 196 GLint FogEffect::stringToFogMode(const std::string& mode) { 197 if(mode == "GL_LINEAR") 198 return GL_LINEAR; 199 else if(mode == "GL_EXP") 200 return GL_EXP; 201 else if(mode == "GL_EXP2" ) 202 return GL_EXP2; 203 else 204 return -1; 205 } 206 207 -
trunk/src/lib/graphics/effects/fog_effect.h
r8362 r8495 6 6 #define _FOG_EFFECT 7 7 8 #include "vector.h"9 8 10 9 #include "weather_effect.h" 11 10 #include "glincl.h" 11 #include "vector.h" 12 13 class FogEffect : public WeatherEffect { 14 public: 15 FogEffect(const TiXmlElement* root = NULL); 16 virtual ~FogEffect(); 17 18 virtual void loadParams(const TiXmlElement* root); 19 20 virtual void init(); 21 22 virtual void activate(); 23 virtual void deactivate(); 24 25 void activateFog() { 26 this->activate(); 27 } 28 void deactivateFog() { 29 this->deactivate(); 30 } 31 32 virtual void draw() const; 33 virtual void tick(float dt); 34 35 inline void setFogMode(const std::string& mode) { 36 this->fogMode = this->stringToFogMode(mode); 37 } 38 inline void setFogDensity(float density) { 39 this->fogDensity = density; 40 } 41 inline void setFogRange(float start, float end) { 42 this->fogStart = start; 43 this->fogEnd = end; 44 } 45 inline void setFogColor(float r, float g, float b) { 46 this->colorVector = Vector(r, g, b); 47 } 48 inline void setFogFadeIn(float fadein) { 49 this->fogFadeInDuration = fadein; 50 } 51 inline void setFogFadeOut(float fadeout) { 52 this->fogFadeOutDuration = fadeout; 53 } 54 55 inline void setFogOption(const std::string& option) { 56 if (option == "activate") 57 this->fogActivate = true; 58 } 59 60 void fadeInFog(); 61 void fadeOutFog(); 12 62 13 63 14 class FogEffect : public WeatherEffect 15 { 16 public: 17 FogEffect(const TiXmlElement* root = NULL); 18 virtual ~FogEffect(); 64 private: 65 GLint stringToFogMode(const std::string& mode); 19 66 20 virtual void loadParams(const TiXmlElement* root);67 bool fogActivate; 21 68 22 virtual bool init(); 69 bool fogFadeInActivate; 70 bool fogFadeOutActivate; 23 71 24 virtual bool activate();25 virtual bool deactivate();72 GLfloat fogFadeInDuration; 73 GLfloat fogFadeOutDuration; 26 74 27 void activateFog() { this->activate(); } 28 void deactivateFog() { this->deactivate(); } 75 float localTimer; 29 76 30 virtual void draw() const; 31 virtual void tick(float dt); 77 GLint fogMode; 78 GLfloat fogDensity; 79 GLfloat fogFadeDensity; 32 80 33 inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); } 34 inline void setFogDensity(float density) { this->fogDensity = density; } 35 inline void setFogRange(float start, float end) { this->fogStart = start; this->fogEnd = end; } 36 inline void setFogColor(float r, float g, float b) { this->colorVector = Vector(r, g, b); } 37 inline void setFogOption(const std::string& option) { if (option == "activate") this->fogActivate = true; } 38 39 void startFogging(); 40 41 private: 42 GLint stringToFogMode(const std::string& mode); 43 44 bool fogActivate; 45 GLfloat fogFadeDuration; 46 float localTimer; 47 48 GLint fogMode; 49 GLfloat fogDensity; 50 GLfloat fogFadeDensity; 51 52 GLfloat fogStart; 53 GLfloat fogEnd; 54 Vector colorVector; 81 GLfloat fogStart; 82 GLfloat fogEnd; 83 Vector colorVector; 55 84 }; 56 85 -
trunk/src/lib/graphics/effects/graphics_effect.cc
r8316 r8495 32 32 @todo what to do, if no GraphicsEffect-Slots are open anymore ??? 33 33 */ 34 GraphicsEffect::GraphicsEffect(const TiXmlElement* root) 35 { 36 this->setClassID(CL_GRAPHICS_EFFECT, "GraphicsEffect"); 37 this->bActivated = false; 34 GraphicsEffect::GraphicsEffect(const TiXmlElement* root) { 35 this->setClassID(CL_GRAPHICS_EFFECT, "GraphicsEffect"); 36 this->bActivated = false; 38 37 } 39 38 … … 42 41 * destroys a GraphicsEffect 43 42 */ 44 GraphicsEffect::~GraphicsEffect() 45 { 46 43 GraphicsEffect::~GraphicsEffect() { 47 44 } 48 45 … … 51 48 * @param root The XML-element to load the GraphicsEffect from 52 49 */ 53 void GraphicsEffect::loadParams(const TiXmlElement* root) 54 { 55 BaseObject::loadParams(root); 50 void GraphicsEffect::loadParams(const TiXmlElement* root) { 51 BaseObject::loadParams(root); 56 52 } 57 53 … … 60 56 * initializes the graphics effect 61 57 */ 62 bool GraphicsEffect::init() 63 { 64 return true; 65 } 58 void GraphicsEffect::init() {} 66 59 67 60 … … 70 63 * draws the effect, if needed 71 64 */ 72 void GraphicsEffect::draw() const 73 {} 65 void GraphicsEffect::draw() const {} 74 66 75 67 … … 78 70 * ticks the effect if there is any time dependancy 79 71 */ 80 void GraphicsEffect::tick(float dt) 81 {} 72 void GraphicsEffect::tick(float dt) {} -
trunk/src/lib/graphics/effects/graphics_effect.h
r6815 r8495 12 12 13 13 //! A class that handles GraphicsEffects. The GraphicsEffectManager operates on this. 14 class GraphicsEffect : public BaseObject 15 { 16 public: 14 class GraphicsEffect : public BaseObject { 15 public: 17 16 GraphicsEffect(const TiXmlElement* root = NULL); 18 17 virtual ~GraphicsEffect(); … … 20 19 virtual void loadParams(const TiXmlElement* root); 21 20 22 virtual boolinit();21 virtual void init(); 23 22 24 virtual boolactivate() = 0;25 virtual booldeactivate() = 0;23 virtual void activate() = 0; 24 virtual void deactivate() = 0; 26 25 27 26 virtual void draw() const; 28 27 virtual void tick(float dt); 29 28 30 inline bool isActivated() const { return this->bActivated; } 29 inline bool isActivated() const { 30 return this->bActivated; 31 } 31 32 32 33 33 34 protected: 34 35 bool bActivated; 35 36 }; -
trunk/src/lib/graphics/effects/lense_flare.cc
r8362 r8495 22 22 #include "util/loading/factory.h" 23 23 24 #include "glincl.h" 24 25 #include "texture.h" 25 26 … … 43 44 * @param root The XML-element to load the LenseFlare from 44 45 */ 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); 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); 70 76 71 77 } … … 75 81 * destroys a LenseFlare 76 82 */ 77 LenseFlare::~LenseFlare() 78 { 79 std::vector<ImagePlane*>::iterator it; 80 for( it = flares.begin(); it != flares.end(); it++) 81 delete (*it); 83 LenseFlare::~LenseFlare() { 84 std::vector<ImagePlane*>::iterator it; 85 for( it = flares.begin(); it != flares.end(); it++) 86 delete (*it); 82 87 } 83 88 … … 86 91 * @param root The XML-element to load the LenseFlare from 87 92 */ 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) 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) 95 99 .describe("adds a lensflare texture to the engine"); 96 }97 LOAD_PARAM_END_CYCLE(element);100 } 101 LOAD_PARAM_END_CYCLE(element); 98 102 } 99 103 … … 102 106 * initializes the fog effect 103 107 */ 104 bool LenseFlare::init() 105 { 106 return true; 107 } 108 void LenseFlare::init() {} 108 109 109 110 … … 111 112 * activates the fog effect 112 113 */ 113 bool LenseFlare::activate() 114 { 115 this->bActivated = true; 116 117 return true; 114 void LenseFlare::activate() { 115 this->bActivated = true; 118 116 } 119 117 … … 122 120 * deactivates the fog effect 123 121 */ 124 bool LenseFlare::deactivate() 125 { 126 this->bActivated = false; 127 128 return true; 122 void LenseFlare::deactivate() { 123 this->bActivated = false; 129 124 } 130 125 … … 134 129 * @param mode the mode character 135 130 */ 136 GLint LenseFlare::stringToFogMode(const std::string& mode) 137 { 138 PRINTF(1)("NOT IMPLEMENTED"); 139 return 0; 131 GLint LenseFlare::stringToFogMode(const std::string& mode) { 132 return 0; 140 133 } 141 134 … … 153 146 * 7th: Texture of the third burst 154 147 */ 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; 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; 189 178 for(it = ++flares.begin(); it != flares.end(); it++) 190 (*it)->setVisibility(visibility);191 this->bVisible = visibility;179 (*it)->setVisibility(visibility); 180 this->bVisible = visibility; 192 181 } 193 182 … … 196 185 * tick the effect 197 186 */ 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 } 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 } 210 197 211 198 //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 } 237 223 } 238 224 … … 241 227 * draws the LenseFlares 242 228 */ 243 void LenseFlare::draw() const 244 { 245 if( !this->bActivated) 246 return; 247 } 229 void LenseFlare::draw() const { 230 if( !this->bActivated) 231 return; 232 } -
trunk/src/lib/graphics/effects/lense_flare.h
r8362 r8495 32 32 virtual void loadParams(const TiXmlElement* root); 33 33 34 virtual boolinit();34 virtual void init(); 35 35 36 virtual boolactivate();37 virtual booldeactivate();36 virtual void activate(); 37 virtual void deactivate(); 38 38 39 39 virtual void draw() const; -
trunk/src/lib/graphics/effects/lightening_effect.cc
r8316 r8495 33 33 CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT); 34 34 35 // TODO: FIx Lightening with Fog enabled 36 35 37 LighteningEffect::LighteningEffect(const TiXmlElement* root) 36 38 { … … 42 44 this->loadParams(root); 43 45 44 45 46 if(this->lighteningActivate) 47 this->activate(); 46 48 } 47 49 … … 55 57 WeatherEffect::loadParams(root); 56 58 57 LoadParam(root, "coord", this, LighteningEffect, coord); 58 LoadParam(root, "option", this, LighteningEffect, setLighteningOption); 59 LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency); 60 LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime); 61 LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime); 62 LoadParam(root, "size", this, LighteningEffect, setFlashSize); 63 LoadParam(root, "seed", this, LighteningEffect, setFlashSeed); 64 } 65 66 67 bool LighteningEffect::init() 68 { 69 lighteningActivate = false; 70 71 this->time = 0.0; 72 this->flashFrequency = 1.4f; 73 this->flashConstTime = 0.5f; 74 this->flashRisingTime = 0.1f; 75 76 this->width = 400.0f; 77 this->height = 100.0f; 78 this->seedWidth = 50; 79 this->seedHeight = 50; 80 this->bNewCoordinate = false; 81 82 this->seedX = 500.f; 83 this->seedZ = 1000.0f; 84 this->seedTime = 4.0f; 85 86 this->billboard[0] = new Billboard(NULL); 87 this->billboard[0]->setTexture("maps/lightning_bolt1.png"); 88 this->billboard[0]->setSize(this->width, this->height); 89 this->billboard[0]->setAbsCoor(3000,850,0); 90 this->billboard[0]->setVisibiliy(false); 91 92 this->billboard[1] = new Billboard(NULL); 93 this->billboard[1]->setTexture("maps/lightning_bolt2.png"); 94 this->billboard[1]->setSize(this->width, this->height); 95 this->billboard[1]->setAbsCoor(3000,850,0); 96 this->billboard[1]->setVisibiliy(false); 97 98 this->billboard[2] = new Billboard(NULL); 99 this->billboard[2]->setTexture("maps/lightning_bolt3.png"); 100 this->billboard[2]->setSize(this->width, this->height); 101 this->billboard[2]->setAbsCoor(3000,850,0); 102 this->billboard[2]->setVisibiliy(false); 103 104 this->billboard[3] = new Billboard(NULL); 105 this->billboard[3]->setTexture("maps/lightning_bolt4.png"); 106 this->billboard[3]->setSize(this->width, this->height); 107 this->billboard[3]->setAbsCoor(0.0f, 50.0f, 0.0f); 108 this->billboard[3]->setVisibiliy(false); 109 /* 110 this->soundSource = NULL; 111 this->thunderBuffer = NULL; 112 113 this->soundSource.setSourceNode(this); 114 115 //load sound 116 if (this->thunderBuffer != NULL) 117 ResourceManager::getInstance()->unload(this->thunderBuffer); 118 this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ 119 120 return true; 59 LoadParam(root, "coord", this, LighteningEffect, coord); 60 LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency); 61 LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime); 62 LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime); 63 LoadParam(root, "size", this, LighteningEffect, setFlashSize); 64 LoadParam(root, "seed", this, LighteningEffect, setFlashSeed); 65 66 LOAD_PARAM_START_CYCLE(root, element); 67 { 68 LoadParam_CYCLE(element, "option", this, LighteningEffect, setLighteningOption); 69 } 70 LOAD_PARAM_END_CYCLE(element); 71 } 72 73 74 void LighteningEffect::init() 75 { 76 //default values 77 this->lighteningActivate = false; 78 79 this->time = 0.0; 80 this->flashFrequency = 4.0f; 81 this->mainFrequency = 4.0f; 82 this->flashConstTime = 0.1f; 83 this->flashRisingTime = 0.03f; 84 85 this->width = 700.0f; 86 this->height = 250.0f; 87 this->seedWidth = 50.0f; 88 this->seedHeight = 50.0f; 89 this->bNewCoordinate = false; 90 this->lighteningMove = false; 91 92 this->seedX = 500.f; 93 this->seedZ = 1000.0f; 94 this->seedTime = 2.0f; 95 96 this->mainPosX = 3000; 97 this->mainPosY = 900; 98 this->mainPosZ = 0; 99 100 // initialize lightening textures 101 this->billboard[0] = new Billboard(NULL); 102 this->billboard[0]->setTexture("maps/lightning_bolt1.png"); 103 this->billboard[0]->setSize(this->width, this->height); 104 this->billboard[0]->setVisibiliy(false); 105 106 this->billboard[1] = new Billboard(NULL); 107 this->billboard[1]->setTexture("maps/lightning_bolt2.png"); 108 this->billboard[1]->setSize(this->width, this->height); 109 this->billboard[1]->setVisibiliy(false); 110 111 this->billboard[2] = new Billboard(NULL); 112 this->billboard[2]->setTexture("maps/lightning_bolt3.png"); 113 this->billboard[2]->setSize(this->width, this->height); 114 this->billboard[2]->setVisibiliy(false); 115 116 this->billboard[3] = new Billboard(NULL); 117 this->billboard[3]->setTexture("maps/lightning_bolt4.png"); 118 this->billboard[3]->setSize(this->width, this->height); 119 this->billboard[3]->setVisibiliy(false); 120 121 if (this->lighteningMove) { 122 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 123 this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 124 this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 125 this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 126 this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 127 } else { 128 this->billboard[0]->setAbsCoor(3000,900,0); 129 this->billboard[1]->setAbsCoor(3000,900,0); 130 this->billboard[2]->setAbsCoor(3000,900,0); 131 this->billboard[3]->setAbsCoor(3000,900,0); 132 } 133 134 this->flashLight = new Light(); 135 this->flashLight->setDiffuseColor(0,0,0); 136 this->flashLight->setSpecularColor(0,0,0); 137 138 /* 139 this->soundSource = NULL; 140 this->thunderBuffer = NULL; 141 142 this->soundSource.setSourceNode(this); 143 144 //load sound 145 if (this->thunderBuffer != NULL) 146 ResourceManager::getInstance()->unload(this->thunderBuffer); 147 this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ 148 121 149 } 122 150 123 151 void LighteningEffect::coord(float x, float y, float z) 124 152 { 125 this->billboard[0]->setAbsCoor(x, y, z); 126 this->billboard[1]->setAbsCoor(x, y, z); 127 this->billboard[2]->setAbsCoor(x, y, z); 128 this->billboard[3]->setAbsCoor(x, y, z); 129 this->mainPosX = x; 130 this->mainPosY = y; 131 this->mainPosZ = z; 153 if (this->lighteningMove) { 154 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 155 this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 156 this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 157 this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 158 this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 159 } else { 160 this->billboard[0]->setAbsCoor(x, y, z); 161 this->billboard[1]->setAbsCoor(x, y, z); 162 this->billboard[2]->setAbsCoor(x, y, z); 163 this->billboard[3]->setAbsCoor(x, y, z); 164 } 165 166 this->mainPosX = x; 167 this->mainPosY = y; 168 this->mainPosZ = z; 132 169 } 133 170 … … 135 172 void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight) 136 173 { 137 this->width = width; 138 this->height = height; 139 this->seedWidth = seedWidth; 140 this->seedHeight = seedHeight; 141 this->billboard[0]->setSize(this->width, this->height); 142 this->billboard[1]->setSize(this->width, this->height); 143 this->billboard[2]->setSize(this->width, this->height); 144 this->billboard[3]->setSize(this->width, this->height); 145 } 146 147 148 bool LighteningEffect::activate() 174 this->width = width; 175 this->height = height; 176 this->seedWidth = seedWidth; 177 this->seedHeight = seedHeight; 178 179 this->billboard[0]->setSize(this->width, this->height); 180 this->billboard[1]->setSize(this->width, this->height); 181 this->billboard[2]->setSize(this->width, this->height); 182 this->billboard[3]->setSize(this->width, this->height); 183 } 184 185 186 void LighteningEffect::activate() 149 187 { 150 188 PRINTF(0)( "Activating LighteningEffect\n" ); 151 this->time = 0; 152 lighteningActivate = true; 153 154 return true; 155 } 156 157 158 bool LighteningEffect::deactivate() 189 this->lighteningActivate = true; 190 191 this->time = 0; 192 } 193 194 195 void LighteningEffect::deactivate() 159 196 { 160 197 PRINTF(0)("Deactivating LighteningEffect\n"); 161 this->billboard[0]->setVisibiliy(false); 162 this->billboard[1]->setVisibiliy(false); 163 this->billboard[2]->setVisibiliy(false); 164 this->billboard[3]->setVisibiliy(false); 165 lighteningActivate = false; 166 167 168 return true; 198 this->lighteningActivate = false; 199 200 this->billboard[0]->setVisibiliy(false); 201 this->billboard[1]->setVisibiliy(false); 202 this->billboard[2]->setVisibiliy(false); 203 this->billboard[3]->setVisibiliy(false); 169 204 } 170 205 171 206 void LighteningEffect::tick (float dt) 172 207 { 173 if(!lighteningActivate) 174 return; 175 176 this->time += dt; 177 178 /*if( flashLight != NULL) 179 { 180 if((int)(100*time)%2) 181 this->flashLight->setDiffuseColor(0,0,0); 182 else 183 this->flashLight->setDiffuseColor(100,100,100); 184 185 //PRINTF(0)("100*time: %f %i\n", 100*time, (int)(100*time)); 186 }*/ 187 188 if( this->time > this->flashFrequency) 189 { 190 this->billboard[0]->setVisibiliy(true); 191 this->time = 0.0f; 192 193 this->flashLight = new Light(); 194 this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z); 195 this->flashLight->setDiffuseColor(100,100,100); 196 197 //this->soundSource.play(this->thunderBuffer); 198 } 199 else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) 200 { 201 this->billboard[3]->setVisibiliy(false); 202 this->time = 0.0f; 203 this->bNewCoordinate = true; 204 205 if(flashLight != NULL) 206 { 207 delete this->flashLight; 208 flashLight = NULL; 209 } 210 } 211 212 if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) 213 { 214 this->billboard[2]->setVisibiliy(false); 215 this->billboard[3]->setVisibiliy(true); 216 this->flashLight->setDiffuseColor(100,100,100); 217 } 218 else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) 219 { 220 this->billboard[1]->setVisibiliy(false); 221 this->billboard[2]->setVisibiliy(true); 222 this->flashLight->setDiffuseColor(0,0,0); 223 } 224 else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) 225 { 226 this->billboard[0]->setVisibiliy(false); 227 this->billboard[1]->setVisibiliy(true); 228 this->flashLight->setDiffuseColor(100,100,100); 229 } 230 231 if( this->bNewCoordinate) 232 { 233 float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX; 234 float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX; 235 this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ); 236 this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ); 237 this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ); 238 this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ); 239 this->bNewCoordinate = false; 240 } 208 if(!lighteningActivate) 209 return; 210 211 this->time += dt; 212 213 // TODO: Make random flashing with short light dingsda:) 214 215 if( this->time > this->flashFrequency) { 216 217 this->billboard[0]->setVisibiliy(true); 218 this->time = 0.0f; 219 220 this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z); 221 222 // flash environmental lightening 223 this->flashLight->setDiffuseColor(1,1,1); 224 this->flashLight->setSpecularColor(1,1,1); 225 226 //this->soundSource.play(this->thunderBuffer); 227 228 } else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) { 229 230 this->billboard[3]->setVisibiliy(false); 231 this->time = 0.0f; 232 this->flashLight->setDiffuseColor(0,0,0); 233 this->flashLight->setSpecularColor(0,0,0); 234 this->bNewCoordinate = true; 235 236 } 237 238 if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) { 239 240 this->billboard[2]->setVisibiliy(false); 241 this->billboard[3]->setVisibiliy(true); 242 // this->flashLight->setDiffuseColor(1,1,1); 243 // this->flashLight->setSpecularColor(1,1,1); 244 245 } else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) { 246 247 this->billboard[1]->setVisibiliy(false); 248 this->billboard[2]->setVisibiliy(true); 249 //this->flashLight->setDiffuseColor(0,0,0); 250 //this->flashLight->setSpecularColor(0,0,0); 251 252 } else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) { 253 254 this->billboard[0]->setVisibiliy(false); 255 this->billboard[1]->setVisibiliy(true); 256 //this->flashLight->setDiffuseColor(1,1,1); 257 //this->flashLight->setSpecularColor(1,1,1); 258 259 } 260 261 if( this->bNewCoordinate) { 262 float posX, posZ; 263 264 if(this->lighteningMove) { 265 266 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 267 posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x; 268 posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z; 269 270 } else { 271 272 posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX; 273 posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX; 274 275 } 276 277 this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ); 278 this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ); 279 this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ); 280 this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ); 281 282 this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX; 283 284 float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX; 285 float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX; 286 287 this->billboard[0]->setSize(w, h); 288 this->billboard[1]->setSize(w, h); 289 this->billboard[2]->setSize(w, h); 290 this->billboard[3]->setSize(w, h); 291 292 this->bNewCoordinate = false; 293 } 241 294 } 242 295 -
trunk/src/lib/graphics/effects/lightening_effect.h
r8255 r8495 14 14 #include "sound_source.h" 15 15 16 17 16 class Billboard; 18 17 class Light; … … 26 25 virtual void loadParams(const TiXmlElement* root); 27 26 28 virtual boolinit();27 virtual void init(); 29 28 30 virtual boolactivate();31 virtual booldeactivate();29 virtual void activate(); 30 virtual void deactivate(); 32 31 33 virtual void draw() const; 34 virtual void tick(float dt); 35 36 void coord(float x, float y, float z); 37 void setFlashSize(float width, float height, float seedWidth, float seedHeight); 38 39 inline void setLighteningOption(const std::string& option) { if (option == "activate") this->lighteningActivate = true;} 40 inline void setFlashFrequency(float flashFrequency) { this->flashFrequency = flashFrequency; } 41 inline void setFlashConstTime(float flashConstTime) { this->flashConstTime = flashConstTime; } 42 inline void setFlashRisingTime(float flashRisingTime) { if(flashRisingTime > this->flashConstTime) 43 this->flashRisingTime = this->flashConstTime/2; 44 else 45 this->flashRisingTime = flashRisingTime; } 46 inline void setFlashSeed(float seedX, float seedZ, float seedTime) { this->seedX = seedX; 47 this->seedZ = seedZ; 48 this->seedTime = seedTime; } 32 inline void activateLightening() { this->activate(); } 33 inline void deactivateLightening() { this->deactivate(); } 49 34 50 void activateLightening() { this->activate(); } 51 void deactivateLightening() { this->deactivate(); } 52 35 virtual void draw() const; 36 virtual void tick(float dt); 37 38 void coord(float x, float y, float z); 39 void setFlashSize(float width, float height, float seedWidth, float seedHeight); 40 41 inline void setLighteningOption(const std::string& option) { 42 if (option == "activate") this->lighteningActivate = true; 43 if (option == "movelightening") this->lighteningMove = true; 44 } 45 46 inline void setFlashFrequency(float mainFrequency, float seedTime) { 47 this->mainFrequency = mainFrequency; 48 this->flashFrequency = mainFrequency; 49 this->seedTime = seedTime; 50 } 51 52 inline void setFlashConstTime(float flashConstTime) { this->flashConstTime = flashConstTime; } 53 54 inline void setFlashRisingTime(float flashRisingTime) { 55 if(flashRisingTime > this->flashConstTime) 56 this->flashRisingTime = this->flashConstTime/2; 57 else 58 this->flashRisingTime = flashRisingTime; 59 } 60 61 inline void setFlashSeed(float seedX, float seedZ) { 62 this->seedX = seedX; 63 this->seedZ = seedZ; 64 } 65 66 53 67 private: 54 Billboard* billboard[4]; 55 bool lighteningActivate; 56 57 float flashFrequency; 58 float flashConstTime; 59 float flashRisingTime; 60 61 float time; 62 63 bool bNewCoordinate; 64 float width; 65 float height; 66 float seedWidth; 67 float seedHeight; 68 69 float seedX; 70 float seedZ; 71 float seedTime; 72 73 float mainPosX; 74 float mainPosY; 75 float mainPosZ; 76 77 Light* flashLight; 78 79 //OrxSound::SoundSource soundSource; 80 //OrxSound::SoundBuffer* thunderBuffer; 68 Billboard* billboard[4]; 69 bool lighteningActivate; 70 bool lighteningMove; 71 72 float flashFrequency; 73 float mainFrequency; 74 float flashConstTime; 75 float flashRisingTime; 76 77 float time; 78 79 bool bNewCoordinate; 80 float width; 81 float height; 82 float seedWidth; 83 float seedHeight; 84 85 float seedX; 86 float seedZ; 87 float seedTime; 88 89 float mainPosX; 90 float mainPosY; 91 float mainPosZ; 92 93 Vector cameraCoor; 94 95 Light* flashLight; 96 97 //OrxSound::SoundSource soundSource; 98 //OrxSound::SoundBuffer* thunderBuffer; 81 99 82 100 }; -
trunk/src/lib/graphics/effects/rain_effect.cc
r8316 r8495 31 31 SHELL_COMMAND(activate, RainEffect, activateRain); 32 32 SHELL_COMMAND(deactivate, RainEffect, deactivateRain); 33 34 SHELL_COMMAND(st artRaining, RainEffect, startRaining);33 SHELL_COMMAND(startraining, RainEffect, startRaining); 34 SHELL_COMMAND(stopraining, RainEffect, stopRaining); 35 35 36 36 using namespace std; … … 38 38 CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); 39 39 40 // TODO: Dim Light with Rain, Finish preCaching, check out if multiple rain emitters work, Think about what happens with building poss. to hang movewithcam off, benchmark, possible to activate lightening, turn off visibility when in a building, variable emitter size depending on playable, also rain velocity 41 42 RainEffect::RainEffect(const TiXmlElement* root) 43 { 44 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 45 46 this->init(); 47 48 if (root != NULL) 49 this->loadParams(root); 50 51 //load rain sound 52 if (this->rainBuffer != NULL) 53 ResourceManager::getInstance()->unload(this->rainBuffer); 54 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV); 55 56 //load wind sound 57 if (this->rainWindForce != 0) { 58 if (this->windBuffer != NULL) 59 ResourceManager::getInstance()->unload(this->windBuffer); 60 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/wind.wav", WAV); 61 } 62 63 if(rainActivate) 64 this->activate(); 65 } 66 67 RainEffect::~RainEffect() 68 { 69 this->deactivate(); 70 71 if (this->rainBuffer != NULL) 72 ResourceManager::getInstance()->unload(this->rainBuffer); 73 74 if (this->windBuffer != NULL) 75 ResourceManager::getInstance()->unload(this->windBuffer); 76 } 77 78 void RainEffect::loadParams(const TiXmlElement* root) 79 { 80 WeatherEffect::loadParams(root); 81 82 LoadParam(root, "coord", this, RainEffect, setRainCoord); 83 LoadParam(root, "size", this, RainEffect, setRainSize); 84 LoadParam(root, "rate", this, RainEffect, setRainRate); 85 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 86 LoadParam(root, "life", this, RainEffect, setRainLife); 87 LoadParam(root, "wind", this, RainEffect, setRainWind); 88 LoadParam(root, "startraining", this, RainEffect, setRainStart); 89 90 LOAD_PARAM_START_CYCLE(root, element); 91 { 92 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 93 } 94 LOAD_PARAM_END_CYCLE(element); 95 96 } 97 98 99 bool RainEffect::init() 100 { 101 //Default values 102 this->rainActivate = false; 103 this->rainMove = false; 104 this->rainCoord = Vector(500, 500, 500); 105 this->rainSize = Vector2D(1000, 1000); 106 this->rainRate = 3000; 107 this->rainVelocity = -300; 108 this->rainLife = 4; 109 this->rainMaxParticles = this->rainRate * this->rainLife; 110 this->rainWindForce = 0; 111 this->rainStartDuration = 0; 112 this->localTimer = 0; 113 this->soundRainVolume = 0.8f; 114 115 this->emitter = new PlaneEmitter(this->rainSize); 116 117 lightMan = LightManager::getInstance(); 118 this->rainAmbient = lightMan->getAmbientColor(); 119 120 return true; 40 /* TODO: 41 - test multiple rain emitters 42 - Think about what happens with building poss. to hang movewithcam off 43 - Possible to activate lightening 44 - turn off visibility when in a building 45 - variable emitter size depending on playable 46 */ 47 48 RainEffect::RainEffect(const TiXmlElement* root) { 49 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 50 51 this->init(); 52 53 if (root != NULL) 54 this->loadParams(root); 55 56 //load rain sound 57 if (this->rainBuffer != NULL) 58 ResourceManager::getInstance()->unload(this->rainBuffer); 59 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 60 61 //load wind sound 62 if (this->rainWindForce != 0) { 63 if (this->windBuffer != NULL) 64 ResourceManager::getInstance()->unload(this->windBuffer); 65 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 66 } 67 68 if(rainActivate) { 69 this->activate(); 70 RainEffect::rainParticles->precache((int)this->rainLife * 5); // TODO: Figure out the correct value 71 } 72 } 73 74 RainEffect::~RainEffect() { 75 this->deactivate(); 76 77 if (this->rainBuffer != NULL) 78 ResourceManager::getInstance()->unload(this->rainBuffer); 79 80 if (this->windBuffer != NULL) 81 ResourceManager::getInstance()->unload(this->windBuffer); 82 } 83 84 void RainEffect::loadParams(const TiXmlElement* root) { 85 WeatherEffect::loadParams(root); 86 87 LoadParam(root, "coord", this, RainEffect, setRainCoord); 88 LoadParam(root, "size", this, RainEffect, setRainSize); 89 LoadParam(root, "rate", this, RainEffect, setRainRate); 90 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 91 LoadParam(root, "life", this, RainEffect, setRainLife); 92 LoadParam(root, "wind", this, RainEffect, setRainWind); 93 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 94 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 95 96 LOAD_PARAM_START_CYCLE(root, element); 97 { 98 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 99 } 100 LOAD_PARAM_END_CYCLE(element); 101 102 } 103 104 105 void RainEffect::init() { 106 //Default values 107 this->rainActivate = false; 108 this->rainMove = false; 109 this->rainCoord = Vector(500, 500, 500); 110 this->rainSize = Vector2D(1000, 1000); 111 this->rainRate = 4000; 112 this->rainVelocity = -300; 113 this->rainLife = 4; 114 this->rainMaxParticles = this->rainRate * this->rainLife; 115 this->rainWindForce = 0; 116 this->rainFadeInDuration = 0; 117 this->rainFadeOutDuration = 0; 118 this->localTimer = 0; 119 this->soundRainVolume = 0.8f; 120 121 this->emitter = new PlaneEmitter(this->rainSize); 122 123 lightMan = LightManager::getInstance(); 124 this->rainAmbient = lightMan->getAmbientColor(); 121 125 } 122 126 … … 124 128 SparkParticles* RainEffect::rainParticles = NULL; 125 129 126 bool RainEffect::activate() 127 { 128 PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" ); 129 130 this->rainActivate = true; 131 132 if (unlikely(RainEffect::rainParticles == NULL)) 133 { 134 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 135 RainEffect::rainParticles->setName("RainParticles"); 136 RainEffect::rainParticles->precache((int)this->rainLife); 137 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 138 RainEffect::rainParticles->setRadius(0, 0.03); 139 RainEffect::rainParticles->setRadius(0.2, 0.02); 140 RainEffect::rainParticles->setRadius(1, 0.01); 141 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 142 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 143 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 144 } 145 146 this->emitter->setSystem(RainEffect::rainParticles); 147 148 this->emitter->setRelCoor(this->rainCoord); 149 150 this->emitter->setEmissionRate(this->rainRate); 151 this->emitter->setEmissionVelocity(this->rainVelocity); 152 153 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 154 155 this->soundSource.loop(this->rainBuffer, this->soundRainVolume); 156 if (this->rainWindForce != 0) this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce); 157 158 lightMan->setAmbientColor(.1,.1,.1); 159 160 return true; 161 } 162 163 164 bool RainEffect::deactivate() 165 { 166 PRINTF(0)("Deactivating RainEffect\n"); 167 168 this->rainActivate = false; 169 this->emitter->setSystem(NULL); 170 171 // Stop Sound 172 this->soundSource.stop(); 173 174 // Restore Light Ambient 175 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 176 177 return true; 178 } 179 180 void RainEffect::tick (float dt) 181 { 182 if (!this->rainActivate) 183 return; 184 185 if (this->rainMove) { 186 this->rainCoord = State::getCameraNode()->getAbsCoor(); 187 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 188 } 189 190 if (this->rainStartDuration != 0 && this->localTimer < this->rainStartDuration) { 191 this->localTimer += dt; 192 float progress = this->localTimer / this->rainStartDuration; 193 194 // Dim Light 195 lightMan->setAmbientColor(1.1 - progress, 1.1 - progress, 1.1 - progress); 196 197 // use alpha in color to fade in 198 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 199 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 200 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 201 202 // increase radius for more "heavy" rain 203 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 204 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 205 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 206 207 // increase sound volume 208 // this->soundSource.fadein(this->rainBuffer, 10); 209 } 130 void RainEffect::activate() { 131 PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" ); 132 133 this->rainActivate = true; 134 135 if (unlikely(RainEffect::rainParticles == NULL)) { 136 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 137 RainEffect::rainParticles->setName("RainParticles"); 138 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 139 RainEffect::rainParticles->setRadius(0, 0.03); 140 RainEffect::rainParticles->setRadius(0.2, 0.02); 141 RainEffect::rainParticles->setRadius(1, 0.01); 142 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 143 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 144 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 145 } 146 147 this->emitter->setSystem(RainEffect::rainParticles); 148 149 this->emitter->setRelCoor(this->rainCoord); 150 151 this->emitter->setEmissionRate(this->rainRate); 152 this->emitter->setEmissionVelocity(this->rainVelocity); 153 154 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 155 156 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 157 158 if (this->rainWindForce != 0) 159 this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true); 160 161 if (this->rainFadeInDuration == 0) 162 lightMan->setAmbientColor(.1,.1,.1); 163 164 } 165 166 167 void RainEffect::deactivate() { 168 PRINTF(0)("Deactivating RainEffect\n"); 169 170 this->rainActivate = false; 171 this->emitter->setSystem(NULL); 172 173 // Stop Sound 174 this->soundSource.stop(); 175 176 // Restore Light Ambient 177 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 178 179 } 180 181 void RainEffect::tick (float dt) { 182 if (!this->rainActivate) 183 return; 184 185 if (this->rainMove) { 186 this->rainCoord = State::getCameraNode()->getAbsCoor(); 187 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 188 } 189 190 if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) { 191 this->localTimer += dt; 192 float progress = this->localTimer / this->rainFadeInDuration; 193 194 // Dim Light 195 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 196 197 // use alpha in color to fade in 198 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 199 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 200 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 201 202 // increase radius for more "heavy" rain 203 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 204 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 205 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 206 207 // increase sound volume 208 // this->soundSource.fadein(this->rainBuffer, 10); 209 } else if ( this->rainFadeOutDuration != 0 ) { 210 if ( this->localTimer < this->rainFadeOutDuration ) { 211 this->localTimer += dt; 212 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 213 214 // Fade In Light 215 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 216 217 // use alpha in color to fade out 218 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 219 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 220 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 221 222 // decrease radius 223 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 224 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 225 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 226 227 // decrease sound volume 228 // this->soundSource.fadeout(this->rainBuffer, 10); 229 } else 230 this->deactivate(); 231 } 210 232 211 233 } … … 213 235 void RainEffect::startRaining() { 214 236 215 if (this->rainActivate) 216 this->deactivate(); 217 218 this->rainStartDuration = 10; 219 this->localTimer = 0; 220 this->activate(); 221 222 } 237 if (this->rainActivate) 238 this->deactivate(); 239 240 if (!this->rainFadeInDuration > 0) 241 this->rainFadeInDuration = 20; 242 243 this->localTimer = 0; 244 245 this->activate(); 246 247 } 248 249 void RainEffect::stopRaining() { 250 251 if (!this->rainActivate) 252 this->activate(); 253 254 if (!this->rainFadeOutDuration > 0) 255 this->rainFadeOutDuration = 20; 256 257 this->localTimer = 0; 258 259 } -
trunk/src/lib/graphics/effects/rain_effect.h
r8255 r8495 22 22 23 23 24 class RainEffect : public WeatherEffect 25 { 26 public: 27 RainEffect(const TiXmlElement* root = NULL); 28 virtual ~RainEffect(); 24 class RainEffect : public WeatherEffect { 25 public: 26 RainEffect(const TiXmlElement* root = NULL); 27 virtual ~RainEffect(); 29 28 30 29 virtual void loadParams(const TiXmlElement* root); 31 30 32 virtual boolinit();31 virtual void init(); 33 32 34 virtual boolactivate();35 virtual booldeactivate();33 virtual void activate(); 34 virtual void deactivate(); 36 35 37 virtual void tick(float dt); 36 inline void activateRain() { 37 this->activate(); 38 } 39 inline void deactivateRain() { 40 this->deactivate(); 41 } 38 42 39 inline void activateRain() { this->activate(); } 40 inline void deactivateRain() { this->deactivate(); } 41 void startRaining(); 43 virtual void tick(float dt); 42 44 43 inline void setRainCoord(float x, float y, float z) { this->rainCoord = Vector(x, y, z); } 44 inline void setRainSize(float x, float y) { this->rainSize = Vector2D(x, y); } 45 inline void setRainRate(float rate) { this->rainRate = rate;} 46 inline void setRainVelocity(float velocity) { this->rainVelocity = -velocity; } 47 inline void setRainLife(float life) { this->rainLife = life; } 48 inline void setRainWind(int force) { this->rainWindForce = force; } 49 inline void setRainStart(float duration) { this->rainStartDuration = duration; } 45 void startRaining(); 46 void stopRaining(); 50 47 51 inline void setRainOption(const std::string& option) { 52 if (option == "moverain") this->rainMove = true; 53 if (option == "activate") this->rainActivate = true; 54 } 48 inline void setRainCoord(float x, float y, float z) { 49 this->rainCoord = Vector(x, y, z); 50 } 51 inline void setRainSize(float x, float y) { 52 this->rainSize = Vector2D(x, y); 53 } 54 inline void setRainRate(float rate) { 55 this->rainRate = rate; 56 } 57 inline void setRainVelocity(float velocity) { 58 this->rainVelocity = -velocity; 59 } 60 inline void setRainLife(float life) { 61 this->rainLife = life; 62 } 63 inline void setRainWind(int force) { 64 this->rainWindForce = force; 65 } 66 67 inline void setRainFadeIn(float fadein) { 68 this->rainFadeInDuration = fadein; 69 } 70 inline void setRainFadeOut(float fadeout) { 71 this->rainFadeOutDuration = fadeout; 72 } 73 74 inline void setRainOption(const std::string& option) { 75 if (option == "moverain") 76 this->rainMove = true; 77 if (option == "activate") 78 this->rainActivate = true; 79 } 55 80 56 81 57 58 static SparkParticles*rainParticles;59 ParticleEmitter*emitter;82 private: 83 static SparkParticles* rainParticles; 84 ParticleEmitter* emitter; 60 85 61 float localTimer; 86 GLfloat rainFadeInDuration; 87 GLfloat rainFadeOutDuration; 88 float localTimer; 62 89 63 Vector rainCoord; 64 Vector2D rainSize; 65 GLfloat rainRate; 66 GLfloat rainVelocity; 67 GLfloat rainLife; 68 GLfloat rainMaxParticles; 69 int rainWindForce; 70 GLfloat rainStartDuration; 71 bool rainMove; 72 bool rainActivate; 90 Vector rainCoord; 91 Vector2D rainSize; 92 GLfloat rainRate; 93 GLfloat rainVelocity; 94 GLfloat rainLife; 95 GLfloat rainMaxParticles; 96 int rainWindForce; 97 bool rainMove; 98 bool rainActivate; 73 99 74 OrxSound::SoundSourcesoundSource;75 OrxSound::SoundBuffer*rainBuffer;76 OrxSound::SoundBuffer*windBuffer;100 OrxSound::SoundSource soundSource; 101 OrxSound::SoundBuffer* rainBuffer; 102 OrxSound::SoundBuffer* windBuffer; 77 103 78 floatsoundRainVolume;104 float soundRainVolume; 79 105 80 LightManager*lightMan;81 GLfloatrainAmbient;106 LightManager* lightMan; 107 GLfloat rainAmbient; 82 108 83 109 }; -
trunk/src/lib/graphics/effects/snow_effect.cc
r8316 r8495 50 50 if (this->windBuffer != NULL) 51 51 ResourceManager::getInstance()->unload(this->windBuffer); 52 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/ wind.wav", WAV);53 } 54 55 if(snowActivate) 52 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 53 } 54 55 if(snowActivate) { 56 56 this->activate(); 57 SnowEffect::snowParticles->precache((int) this->snowLife); 58 } 57 59 } 58 60 … … 87 89 } 88 90 89 boolSnowEffect::init()91 void SnowEffect::init() 90 92 { 91 93 this->emitter = new PlaneEmitter(); … … 96 98 this->particles = 12000; 97 99 this->texture = "maps/snow_flake_01_32x32.png"; 98 this-> life = 8;100 this->snowLife = 8; 99 101 this->randomLife = 2; 100 102 this->snowRadius = 3.5; … … 111 113 this->snowCoord = Vector(100,450,400); 112 114 this->snowWindForce = 1; 113 114 return true; 115 } 116 117 bool SnowEffect::activate() 115 } 116 117 void SnowEffect::activate() 118 118 { 119 119 PRINTF(0)("Activating SnowEffect\n"); … … 124 124 SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); 125 125 SnowEffect::snowParticles->setMaterialTexture(texture); 126 SnowEffect::snowParticles->setLifeSpan( life, randomLife);126 SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife); 127 127 SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); 128 128 SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8); … … 141 141 this->emitter->setSize(snowSize); 142 142 143 // SnowEffect::snowParticles->precache(8); 144 145 if (this->snowWindForce > 1) 146 this->soundSource.loop(this->windBuffer); 147 148 return true; 149 } 150 151 152 bool SnowEffect::deactivate() 143 if (this->snowWindForce != 0) 144 this->soundSource.play(this->windBuffer, 0.1f * this->snowWindForce, true); 145 146 } 147 148 149 void SnowEffect::deactivate() 153 150 { 154 151 PRINTF(0)("Deactivating SnowEffect\n"); … … 159 156 if (this->windBuffer != NULL) 160 157 ResourceManager::getInstance()->unload(this->windBuffer); 161 162 return true;163 158 } 164 159 -
trunk/src/lib/graphics/effects/snow_effect.h
r8255 r8495 20 20 #include "sound_buffer.h" 21 21 22 class SnowEffect : public WeatherEffect 23 { 24 public: 25 SnowEffect(const TiXmlElement* root = NULL); 26 virtual ~SnowEffect(); 22 class SnowEffect : public WeatherEffect { 23 public: 24 SnowEffect(const TiXmlElement* root = NULL); 25 virtual ~SnowEffect(); 27 26 28 27 virtual void loadParams(const TiXmlElement* root); 29 28 30 virtual boolinit();29 virtual void init(); 31 30 32 virtual boolactivate();33 virtual booldeactivate();31 virtual void activate(); 32 virtual void deactivate(); 34 33 35 inline void activateSnow() { this->activate(); } 36 inline void deactivateSnow() { this->deactivate(); } 37 38 virtual void draw() const; 39 virtual void tick(float dt); 34 inline void activateSnow() { 35 this->activate(); 36 } 37 inline void deactivateSnow() { 38 this->deactivate(); 39 } 40 41 virtual void draw() const; 42 virtual void tick(float dt); 40 43 41 44 42 inline void numParticles(int n) { this->particles = n; } 43 inline void materialTexture(const std::string& texture) { this->texture = texture; } 44 inline void lifeSpan(float lifeSpan, float randomLifeSpan) { this->life = lifeSpan; this->randomLife = randomLifeSpan; } 45 inline void radius(float radius, float randomRadius) { this->snowRadius = radius; this->randomRadius = randomRadius; } 46 inline void mass(float mass, float randomMass) { this->snowMass = mass; this->randomMass = randomMass; } 47 inline void emissionRate(float emissionRate){ this->rate = emissionRate; } 48 inline void emissionVelocity(float velocity, float randomVelocity){ this->velocity = velocity; this->randomVelocity = randomVelocity; } 49 inline void size(float sizeX, float sizeY) { this->snowSize = Vector2D(sizeX, sizeY); } 50 inline void coord(float x, float y, float z) { this->snowCoord = Vector(x, y, z); } 51 inline void wind(int force) { this->snowWindForce = force; } 45 inline void numParticles(int n) { 46 this->particles = n; 47 } 48 inline void materialTexture(const std::string& texture) { 49 this->texture = texture; 50 } 51 inline void lifeSpan(float lifeSpan, float randomLifeSpan) { 52 this->snowLife = lifeSpan; 53 this->randomLife = randomLifeSpan; 54 } 55 inline void radius(float radius, float randomRadius) { 56 this->snowRadius = radius; 57 this->randomRadius = randomRadius; 58 } 59 inline void mass(float mass, float randomMass) { 60 this->snowMass = mass; 61 this->randomMass = randomMass; 62 } 63 inline void emissionRate(float emissionRate) { 64 this->rate = emissionRate; 65 } 66 inline void emissionVelocity(float velocity, float randomVelocity) { 67 this->velocity = velocity; 68 this->randomVelocity = randomVelocity; 69 } 70 inline void size(float sizeX, float sizeY) { 71 this->snowSize = Vector2D(sizeX, sizeY); 72 } 73 inline void coord(float x, float y, float z) { 74 this->snowCoord = Vector(x, y, z); 75 } 76 inline void wind(int force) { 77 this->snowWindForce = force; 78 } 52 79 53 inline void setSnowOption(const std::string& option) { 54 /*if (option == "fade") this->snowFade = true;*/ 55 if (option == "movesnow") this->snowMove = true; 56 if (option == "activate") this->snowActivate = true; 57 } 80 inline void setSnowOption(const std::string& option) { 81 /*if (option == "fade") this->snowFade = true;*/ 82 if (option == "movesnow") 83 this->snowMove = true; 84 if (option == "activate") 85 this->snowActivate = true; 86 } 58 87 59 88 60 61 intparticles;62 std::stringtexture;63 float life, randomLife;64 floatsnowRadius, randomRadius;65 floatsnowMass, randomMass;66 floatrate;67 floatvelocity, randomVelocity;68 floatangle, randomAngle;69 floatalpha;70 VectorsnowCoord;71 Vector2DsnowSize;72 intsnowWindForce;89 private: 90 int particles; 91 std::string texture; 92 float snowLife, randomLife; 93 float snowRadius, randomRadius; 94 float snowMass, randomMass; 95 float rate; 96 float velocity, randomVelocity; 97 float angle, randomAngle; 98 float alpha; 99 Vector snowCoord; 100 Vector2D snowSize; 101 int snowWindForce; 73 102 74 boolsnowMove;75 boolsnowActivate;103 bool snowMove; 104 bool snowActivate; 76 105 77 PlaneEmitter*emitter;106 PlaneEmitter* emitter; 78 107 79 static SpriteParticles*snowParticles;80 OrxSound::SoundSourcesoundSource;81 OrxSound::SoundBuffer*windBuffer;108 static SpriteParticles* snowParticles; 109 OrxSound::SoundSource soundSource; 110 OrxSound::SoundBuffer* windBuffer; 82 111 83 112 }; -
trunk/src/lib/graphics/effects/volfog_effect.cc
r8362 r8495 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 orx 5 5 6 7 8 9 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: hdavid, amaechler 13 13 */ 14 14 … … 21 21 #include "state.h" 22 22 23 #include "glincl.h" 24 //#include "shell_command.h" 23 25 24 26 #define GLX_GLXEXT_PROTOTYPES … … 49 51 CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); 50 52 51 VolFogEffect::VolFogEffect(const TiXmlElement* root) 52 { 53 this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); 53 VolFogEffect::VolFogEffect(const TiXmlElement* root) { 54 this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); 54 55 55 56 56 if (root != NULL) 57 this->loadParams(root); 57 58 58 59 59 // Initialize Effect 60 this->init(); 60 61 61 62 62 // Activate Effect 63 this->activate(); 63 64 } 64 65 65 66 66 VolFogEffect::~VolFogEffect() 67 { 68 this->deactivate(); 67 VolFogEffect::~VolFogEffect() { 68 this->deactivate(); 69 69 } 70 70 71 void VolFogEffect::loadParams(const TiXmlElement* root) 72 { 73 WeatherEffect::loadParams(root); 71 void VolFogEffect::loadParams(const TiXmlElement* root) { 72 WeatherEffect::loadParams(root); 74 73 } 75 74 76 bool VolFogEffect::init() 77 { 78 PRINTF(0)("Initalize VolFogEffect\n"); 75 void VolFogEffect::init() { 76 PRINTF(0)("Initalize VolFogEffect\n"); 79 77 80 81 78 // set fog mode 79 GLenum fogMode = GL_EXP; 82 80 83 84 81 // set fog density 82 float fogDensity = 0.001f; 85 83 86 87 88 84 // set fog near & far distance 85 float fogStart = 0.0f; 86 float fogEnd = 1000.0f; 89 87 90 91 88 // Set fog color 89 float fogColor[4] = {0.6f,0.58f,0.79f,0.0f}; 92 90 93 91 94 95 96 97 98 92 glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT"); 93 glFogCoordfvEXT = (PFNGLFOGCOORDFVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfvEXT"); 94 glFogCoorddEXT = (PFNGLFOGCOORDDEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddEXT"); 95 glFogCoorddvEXT = (PFNGLFOGCOORDDVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddvEXT"); 96 glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordPointerEXT"); 99 97 100 101 102 103 104 105 106 98 // set the fog attributes 99 glFogf (GL_FOG_START, fogStart); 100 glFogf (GL_FOG_END, fogEnd); 101 glFogfv(GL_FOG_COLOR, fogColor); 102 glFogi (GL_FOG_MODE, fogMode); 103 glFogf (GL_FOG_DENSITY,fogDensity); 104 glFogi (GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT); 107 105 108 109 106 // enable the fog 107 glEnable(GL_FOG); 110 108 111 112 113 114 109 if (glewInit() == GLEW_OK) 110 PRINTF(0)("glewInit OK\n"); 111 else 112 PRINTF(0)("glewInit failed\n"); 115 113 116 if (glewGetExtension("GL_EXT_fog_coord")) 117 { 118 PRINTF(0)("GL_EXT_fog_coord extension found\n"); 119 return true; 120 } 121 else 122 { 123 PRINTF(0)("GL_EXT_fog_coord extension NOT found\n"); 124 return false; 125 } 114 if (glewGetExtension("GL_EXT_fog_coord")) 115 PRINTF(0)("GL_EXT_fog_coord extension found\n"); 126 116 } 127 117 128 118 129 bool VolFogEffect::activate() 130 { 131 PRINTF(0)("Activating VolFogEffect\n"); 132 133 return true; 119 void VolFogEffect::activate() { 120 PRINTF(0)("Activating VolFogEffect\n"); 134 121 } 135 122 136 bool VolFogEffect::deactivate() 137 { 138 PRINTF(0)("Deactivating VolFogEffect\n"); 123 void VolFogEffect::deactivate() { 124 PRINTF(0)("Deactivating VolFogEffect\n"); 139 125 140 glDisable(GL_FOG); 141 142 return true; 126 glDisable(GL_FOG); 143 127 } 144 128 … … 147 131 * draws the effect, if needed 148 132 */ 149 void VolFogEffect::draw() const 150 { 151 glPushAttrib(GL_ENABLE_BIT); 152 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); 153 glShadeModel(GL_SMOOTH); 154 glEnable(GL_DEPTH_TEST); 155 glEnable(GL_CULL_FACE); 156 glCullFace(GL_BACK); 133 void VolFogEffect::draw() const { 134 glPushAttrib(GL_ENABLE_BIT); 135 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); 136 glShadeModel(GL_SMOOTH); 137 glEnable(GL_DEPTH_TEST); 138 glEnable(GL_CULL_FACE); 139 glCullFace(GL_BACK); 157 140 158 159 141 /* clear all pixels in colour buffer */ 142 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 160 143 161 162 163 144 /* Enable blending */ 145 //glEnable(GL_BLEND); 146 //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 164 147 165 166 148 int i; 149 glLoadIdentity(); 167 150 168 151 169 glBegin( GL_LINES ); 170 glNormal3f(0,1,0); 171 for(i=-20;i<=20;i+=2) 172 { 173 float fog_c; 174 float diff[3]; 152 glBegin( GL_LINES ); 153 glNormal3f(0,1,0); 154 for(i=-20;i<=20;i+=2) { 155 float fog_c; 156 float diff[3]; 175 157 176 177 178 179 180 181 158 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 159 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 160 diff[1] = State::getCameraNode()->getAbsCoor().y; 161 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 162 glFogCoordfEXT(fog_c*2); 163 glVertex3f(i,0,-20); 182 164 183 184 185 186 187 188 165 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 166 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 167 diff[1] = State::getCameraNode()->getAbsCoor().y; 168 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 169 glFogCoordfEXT(fog_c*2); 170 glVertex3f(i,0,20); 189 171 190 191 192 193 194 195 172 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 173 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 174 diff[1] = State::getCameraNode()->getAbsCoor().y; 175 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 176 glFogCoordfEXT(fog_c*2); 177 glVertex3f(-20,0,i); 196 178 197 198 199 200 201 202 203 204 179 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 180 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 181 diff[1] = State::getCameraNode()->getAbsCoor().y; 182 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 183 glFogCoordfEXT(fog_c*2); 184 glVertex3f(20,0,i); 185 } 186 glEnd(); 205 187 206 glPopAttrib();188 glPopAttrib(); 207 189 208 190 } … … 212 194 * ticks the effect if there is any time dependancy 213 195 */ 214 void VolFogEffect::tick(float dt) 215 { 216 } 196 void VolFogEffect::tick(float dt) {} -
trunk/src/lib/graphics/effects/volfog_effect.h
r8362 r8495 11 11 #include "glincl.h" 12 12 13 class VolFogEffect : public WeatherEffect 14 { 15 public: 16 VolFogEffect(const TiXmlElement* root = NULL); 17 virtual ~VolFogEffect(); 13 class VolFogEffect : public WeatherEffect { 14 public: 15 VolFogEffect(const TiXmlElement* root = NULL); 16 virtual ~VolFogEffect(); 18 17 19 18 virtual void loadParams(const TiXmlElement* root); 20 19 21 virtual boolinit();20 virtual void init(); 22 21 23 virtual boolactivate();24 virtual booldeactivate();22 virtual void activate(); 23 virtual void deactivate(); 25 24 26 27 25 virtual void draw() const; 26 virtual void tick(float dt); 28 27 29 30 28 private: 29 GLfloat fogColor[4]; 31 30 32 31 }; -
trunk/src/lib/graphics/effects/weather_effect.cc
r8316 r8495 55 55 * initializes the graphics effect 56 56 */ 57 boolWeatherEffect::init()57 void WeatherEffect::init() 58 58 { 59 return true;60 59 } 61 60 -
trunk/src/lib/graphics/effects/weather_effect.h
r7810 r8495 1 1 /*! 2 2 * @file weather_effect.h 3 * 3 * 4 4 */ 5 5 … … 18 18 virtual void loadParams(const TiXmlElement* root); 19 19 20 virtual boolinit();20 virtual void init(); 21 21 22 virtual boolactivate() = 0;23 virtual booldeactivate() = 0;22 virtual void activate() = 0; 23 virtual void deactivate() = 0; 24 24 25 25 virtual void draw() const; 26 26 virtual void tick(float dt); 27 27 28 inline bool isActivated() const { return this->bActivated; }28 inline bool isActivated() const { return this->bActivated; } 29 29 30 30 -
trunk/src/lib/gui/qt/gui_control.cc
r8316 r8495 286 286 return -1; 287 287 } 288 289 return 0; 290 288 291 } 289 292 -
trunk/src/lib/sound/sound_source.cc
r8362 r8495 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 ### File Specific: 12 main-programmer: Benjamin Grauer 13 co-programmer: ... 14 14 */ 15 15 … … 85 85 else 86 86 this->stop(); 87 return *this;88 87 } 89 88 … … 190 189 SoundEngine::checkError("Play Source", __LINE__); 191 190 } 192 193 194 /** 195 * @brief Plays and loops back a SoundSource 196 */ 197 void SoundSource::loop() 198 { 199 if (this->buffer && this->retrieveSource()) 200 { 201 if (this->bPlay) 202 alSourceStop(this->sourceID); 203 191 192 /** 193 * @brief Plays back buffer on this Source with gain and looping possibility 194 * @param buffer the buffer to play back on this Source 195 */ 196 void SoundSource::play(const SoundBuffer* buffer, float gain, bool loop) 197 { 198 if (!this->retrieveSource()) 199 { 200 PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n"); 201 return; 202 } 203 204 alSourceStop(this->sourceID); 205 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 206 207 if (loop) 208 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 209 else 210 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 211 212 alSourcef (this->sourceID, AL_GAIN, gain); 213 214 alSourcePlay(this->sourceID); 215 216 if (unlikely(this->buffer != NULL)) 204 217 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 205 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 206 alSourcef (this->sourceID, AL_GAIN, 1); 207 alSourcePlay(this->sourceID); 208 209 if (DEBUG_LEVEL >= 3) 210 SoundEngine::checkError("Play Source", __LINE__); 211 this->bPlay = true; 212 } 213 } 214 215 /** 216 * @brief Plays and loops buffer on this Source 217 * @param buffer the buffer to play back on this Source 218 */ 219 void SoundSource::loop(const SoundBuffer* buffer) 220 { 221 if (this->buffer && this->retrieveSource()) 222 { 223 if (this->bPlay) 224 alSourceStop(this->sourceID); 225 226 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 227 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 228 alSourcef (this->sourceID, AL_GAIN, 1); 229 230 alSourcePlay(this->sourceID); 231 232 if (DEBUG_LEVEL >= 3) 233 SoundEngine::checkError("Loop Source", __LINE__); 234 this->bPlay = true; 235 } 236 } 237 238 239 /** 240 * @brief Plays and loops buffer on this Source with gain control 241 * @param buffer the buffer to play back on this Source 242 */ 243 void SoundSource::loop(const SoundBuffer* buffer, float gain) 244 { 245 if (this->buffer && this->retrieveSource()) 246 { 247 if (this->bPlay) 248 alSourceStop(this->sourceID); 249 250 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 251 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 252 alSourcef (this->sourceID, AL_GAIN, gain); 253 254 alSourcePlay(this->sourceID); 255 256 if (DEBUG_LEVEL >= 3) 257 SoundEngine::checkError("Loop Source", __LINE__); 258 this->bPlay = true; 259 } 260 } 218 this->bPlay = true; 219 220 if (DEBUG_LEVEL >= 3) 221 SoundEngine::checkError("Play Source", __LINE__); 222 } 261 223 262 224 … … 381 343 } 382 344 383 // 384 385 // 386 // 387 // 345 // alSourcePlay(this->sourceID); 346 347 // if (DEBUG_LEVEL >= 3) 348 // SoundEngine::checkError("Loop Source", __LINE__); 349 // this->bPlay = true; 388 350 //} 389 351 -
trunk/src/lib/sound/sound_source.h
r8255 r8495 30 30 void play(const SoundBuffer* buffer); 31 31 void play(const SoundBuffer* buffer, float gain); 32 void loop(); 33 void loop(const SoundBuffer* buffer); 34 void loop(const SoundBuffer* buffer, float gain); 32 void play(const SoundBuffer* buffer, float gain, bool loop); 33 35 34 void stop(); 36 35 void pause(); -
trunk/src/subprojects/benchmark.cc
r5750 r8495 455 455 } 456 456 printf("\n"); 457 458 459 460 457 } 461 458 459 return 0; 462 460 } 463 461 -
trunk/src/util/kill_target.cc
r7466 r8495 31 31 */ 32 32 KillTarget::KillTarget (const TiXmlElement* root) 33 : MissionGoal(root) 34 { 35 this->setClassID(CL_KILL_TARGET, "KillTarget"); 33 : MissionGoal(root) { 34 this->setClassID(CL_KILL_TARGET, "KillTarget"); 36 35 37 if( root != NULL)38 this->loadParams(root);36 if( root != NULL) 37 this->loadParams(root); 39 38 } 40 39 … … 43 42 * standard deconstructor 44 43 */ 45 KillTarget::~KillTarget () 46 { 47 44 KillTarget::~KillTarget () { 48 45 } 49 46 50 47 51 void KillTarget::loadParams(const TiXmlElement* root) 52 { 53 MissionGoal::loadParams(root); 48 void KillTarget::loadParams(const TiXmlElement* root) { 49 MissionGoal::loadParams(root); 54 50 55 LoadParam(root, "numberofkills", this, KillTarget, setNumberOfKills)56 57 LoadParam(root, "targetclassid", this, KillTarget, setTargetClassID)58 51 LoadParam(root, "numberofkills", this, KillTarget, setNumberOfKills) 52 .describe("sets the number of kills a target has to be killed"); 53 LoadParam(root, "targetclassid", this, KillTarget, setTargetClassID) 54 .describe("sets the targets class id"); 59 55 } 60 56 61 57 62 MissionState KillTarget::checkMissionGoal(float dt) 63 { 58 MissionState KillTarget::checkMissionGoal(float dt) {} 64 59 65 }66 67 68 69 70 -
trunk/src/world_entities/effects/billboard.cc
r8255 r8495 121 121 return; 122 122 123 glPushAttrib(GL_ENABLE_BIT); 124 glDisable(GL_LIGHTING); 125 glDisable(GL_FOG); 126 123 127 glPushMatrix(); 124 128 … … 164 168 165 169 glPopMatrix(); 170 171 glPopAttrib(); 166 172 } -
trunk/src/world_entities/space_ships/helicopter.cc
r8408 r8495 107 107 if (this->chopperBuffer != NULL) 108 108 ResourceManager::getInstance()->unload(this->chopperBuffer); 109 this->chopperBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/ chopper.wav", WAV);109 this->chopperBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/engine/chopper.wav", WAV); 110 110 111 111 } … … 219 219 State::getCameraTargetNode()->setParentSoft(this->getWeaponManager().getFixedTarget()); 220 220 221 this->soundSource.loop(this->chopperBuffer, 0.8f); 222 // PRINTF(0)( "Playing ChopperSound\n" ); 221 this->soundSource.play(this->chopperBuffer, 0.7f, true); 223 222 } 224 223
Note: See TracChangeset
for help on using the changeset viewer.