- Timestamp:
- Jun 1, 2006, 11:12:42 AM (18 years ago)
- Location:
- branches/atmospheric_engine/src/lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
r7977 r8052 22 22 #include "glincl.h" 23 23 //#include "graphics_engine.h" 24 #include "material.h" 24 25 #include <math.h> 25 26 … … 69 70 70 71 // Generate noise map a 71 CloudEffect::genNoiseMap(cloudMap32_a);72 //CloudEffect::genNoiseMap(cloudMap32_a); 72 73 73 74 if (this->cloudAnimTimeStep > 0) { 74 75 // Generate noise map b 75 CloudEffect::genNoiseMap(cloudMap32_b);76 //CloudEffect::genNoiseMap(cloudMap32_b); 76 77 } 78 79 this->material = new Material(); 80 77 81 } 78 82 … … 80 84 { 81 85 PRINTF(0)( "Activating CloudEffect\n"); 82 if (this->cloudAnimTimeStep == 0) {83 for (int i = 0; i < 32*32; i++)84 cloudMap32_c[i] = cloudMap32_a[i];85 86 86 CloudEffect::overlapOctaves(); 87 CloudEffect::expFilter(); 88 CloudEffect::genCloudTexture(); 89 } 87 90 88 } 91 89 … … 95 93 } 96 94 97 void CloudEffect::genCloudTexture() {98 for(int i=0; i<256; i++)99 for(int j=0; j<256; j++)100 {101 float color = cloudMap256[i*256+j];102 cloudTexture[i][j][0] = (char) color;103 cloudTexture[i][j][1] = (char) color;104 cloudTexture[i][j][2] = (char) color;105 }106 107 glBindTexture(GL_TEXTURE_2D, texID[0]);108 109 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, cloudTexture);110 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, cloudTexture);111 112 }113 114 void CloudEffect::calcAnimMap(float timer) {115 116 for (int x=0; x<32*32; x++)117 cloudMap32_c[x] = (cloudMap32_a[x] * ((this->cloudAnimTimeStep - timer) / this->cloudAnimTimeStep)) + (cloudMap32_b[x] * (timer / this->cloudAnimTimeStep));118 119 }120 121 95 void CloudEffect::draw() const 122 96 { 97 /* TODO: 98 -Load a texture, for now from an existing image, a cloud texture 99 -Blend / Overlay this with a blue sky like in the tutorial 100 -Make a skybox or whatever.... 101 -Animate it (for now move it along the sky) 102 */ 103 123 104 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 124 105 106 this->material->setDiffuseMap("maps/lightning_bolt.png"); 107 this->material->select(); 108 125 109 glPushMatrix(); 126 glEnable(GL_TEXTURE_2D);110 glEnable(GL_TEXTURE_2D); 127 111 128 glBindTexture(GL_TEXTURE_2D, texID[0]);112 glBindTexture(GL_TEXTURE_2D, texID[0]); 129 113 130 114 // FIXME : Bind this to the sky - how do I do this? 131 115 glBegin(GL_QUADS); 132 glTexCoord2f(0.0f, 0.0f); glVertex3f(20, 20, 60); // Bottom Left Of The Texture and Quad 133 glTexCoord2f(1.0f, 0.0f); glVertex3f(60, 20, 60); // Bottom Right Of The Texture and Quad 134 glTexCoord2f(1.0f, 1.0f); glVertex3f(60, 60, 60); // Top Right Of The Texture and Quad 135 glTexCoord2f(0.0f, 1.0f); glVertex3f(20, 60, 60); // Top Left Of The Texture and Quad 116 glTexCoord2f(0.0f, 0.0f); 117 glVertex3f(20, 20, 60); // Bottom Left Of The Texture and Quad 118 119 glTexCoord2f(1.0f, 0.0f); 120 glVertex3f(60, 20, 60); // Bottom Right Of The Texture and Quad 121 122 glTexCoord2f(1.0f, 1.0f); 123 glVertex3f(60, 60, 60); // Top Right Of The Texture and Quad 124 125 glTexCoord2f(0.0f, 1.0f); 126 glVertex3f(20, 60, 60); // Top Left Of The Texture and Quad 136 127 glEnd(); 137 128 … … 141 132 void CloudEffect::tick (float dt) 142 133 { 143 if (this->cloudAnimTimeStep > 0) { 144 if (timer >= this->cloudAnimTimeStep) { 145 timer -= this->cloudAnimTimeStep; 146 for (int i = 0; i < 32*32; i++) 147 cloudMap32_a[i] = cloudMap32_b[i]; 148 CloudEffect::genNoiseMap(cloudMap32_b); 149 } 150 151 //map32anim = (map32a * (10 - timer)) + (map32b * timer); 152 CloudEffect::calcAnimMap(timer); 153 //CloudEffect::overlapOctaves(); 154 //CloudEffect::expFilter(); 155 CloudEffect::genCloudTexture(); 156 157 timer += dt; 158 } 134 159 135 } 160 161 /*162 Random noise generator163 */164 float CloudEffect::noise(int x, int y, int random)165 {166 int n = x + y * 57 + random * 131;167 n = (n<<13) ^ n;168 return (1.0f - ( (n * (n * n * 15731 + 789221) +169 1376312589)&0x7fffffff)* 0.000000000931322574615478515625f);170 }171 172 /*173 Set noise for the 32*32 noise map:174 */175 void CloudEffect::genNoiseMap(float *map)176 {177 float temp[34][34];178 179 int random = rand() % 5000;180 181 for (int y = 1; y < 33; y++)182 for (int x = 1; x < 33; x++)183 temp[x][y] = 128.0f + CloudEffect::noise(x, y, random) * 128.0f;184 185 // Seamless cloud186 for (int x=1; x<33; x++)187 {188 temp[0][x] = temp[32][x];189 temp[33][x] = temp[1][x];190 temp[x][0] = temp[x][32];191 temp[x][33] = temp[x][1];192 }193 temp[0][0] = temp[32][32];194 temp[33][33] = temp[1][1];195 temp[0][33] = temp[32][1];196 temp[33][0] = temp[1][32];197 198 // We mirror the side and corner elements so our final cloud will be seamless without any ugly borders showing.199 for (int y=1; y<33; y++)200 for (int x=1; x<33; x++)201 {202 float center = temp[x][y]/4.0f;203 float sides = (temp[x+1][y] + temp[x-1][y] + temp[x][y+1] + temp[x][y-1])/8.0f;204 float corners = (temp[x+1][y+1] + temp[x+1][y-1] + temp[x-1][y+1] + temp[x-1][y-1])/16.0f;205 206 map[((x-1)*32) + (y-1)] = center + sides + corners;207 }208 }209 210 /*211 Interpolation - average the value of each pixel value with that of its neighbors' values.212 */213 float CloudEffect::interpolate(float x, float y, float *map)214 {215 int Xint = (int)x;216 int Yint = (int)y;217 218 float Xfrac = x - Xint;219 float Yfrac = y - Yint;220 221 int X0 = Xint % 32;222 int Y0 = Yint % 32;223 int X1 = (Xint + 1) % 32;224 int Y1 = (Yint + 1) % 32;225 226 float bot = map[X0*32 + Y0] + Xfrac * (map[X1*32 + Y0] - map[X0*32 + Y0]);227 float top = map[X0*32 + Y1] + Xfrac * (map[X1*32 + Y1] - map[X0*32 + Y1]);228 229 return (bot + Yfrac * (top - bot));230 }231 232 233 /*234 Octaves are overlapped together to give cloud more turbulence. We will use four octaves for our cloud.235 */236 void CloudEffect::overlapOctaves()237 {238 for (int x=0; x<256*256; x++)239 {240 cloudMap256[x] = 0;241 }242 243 for (int octave=0; octave<4; octave++)244 for (int x=0; x<256; x++)245 for (int y=0; y<256; y++)246 {247 float scale = 1 / pow(2.0f, (float) 3-octave);248 float noise = CloudEffect::interpolate(x*scale, y*scale , cloudMap32_c);249 250 //The octaves are added together with the proper weight factors.251 //You could replace pow(2, i) with 1<<i for faster computation252 cloudMap256[(y*256) + x] += noise / pow(2.0f, (float) octave);253 }254 }255 256 257 /*258 Filter the noise with exponential function259 */260 void CloudEffect::expFilter()261 {262 float cover = 20.0f;263 float sharpness = 0.95f;264 265 for (int x=0; x<256*256; x++)266 {267 float c = cloudMap256[x] - (255.0f-cover);268 if (c<0) c = 0;269 cloudMap256[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f);270 }271 }272 273 -
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
r7810 r8052 13 13 #include "sound_buffer.h" 14 14 #include "sound_source.h" 15 16 class Material; 17 15 18 16 19 class CloudEffect : public WeatherEffect … … 57 60 void genCloudTexture(); 58 61 void calcAnimMap(float timer); 62 Material* material; 59 63 60 64 }; -
branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc
r8023 r8052 35 35 CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); 36 36 37 // 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, sound volume,benchmark, possible to activate lightening, turn off visibility when in a building, variable emitter size depending on playable, also rain velocity37 // 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 38 38 39 39 RainEffect::RainEffect(const TiXmlElement* root) … … 139 139 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 140 140 141 this->soundSource.loop(this->rainBuffer );141 this->soundSource.loop(this->rainBuffer, 0.8f); 142 142 if (this->rainWindForce > 0) 143 this->soundSource.loop(this->windBuffer );143 this->soundSource.loop(this->windBuffer, 0.5f); 144 144 } 145 145 -
branches/atmospheric_engine/src/lib/sound/sound_source.cc
r7810 r8052 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 … … 24 24 namespace OrxSound 25 25 { 26 /** 27 * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer 28 */ 29 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) 30 { 31 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 32 33 // adding the Source to the SourcesList of the SoundEngine 34 this->buffer = buffer; 35 this->sourceNode = sourceNode; 36 this->resident = false; 37 38 this->sourceID = 0; 39 this->bPlay = false; 40 } 41 42 43 /** 44 * @brief construct a SoundSource out of the another soundSource 45 * @param source the Source to create this source from. 46 * 47 * Copies the buffer from source to this Source. 48 * Acquires a new SourceID if source is Playing. 49 */ 50 SoundSource::SoundSource(const SoundSource& source) 51 { 52 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 53 54 // adding the Source to the SourcesList of the SoundEngine 55 this->buffer = source.buffer; 56 this->sourceNode = source.sourceNode; 57 this->resident = source.resident; 58 59 this->sourceID = 0; 60 if (source.bPlay == true) 61 { 62 this->bPlay = true; 63 SoundEngine::getInstance()->popALSource(this->sourceID); 64 } 65 else 66 this->bPlay = false; 67 } 68 69 70 /** 71 * @brief paste a copy of the source into this Source. 72 * @param source the SoundSource to paste into this one. 73 * @returns a Reference to this Source. 74 * 75 */ 76 SoundSource& SoundSource::operator=(const SoundSource& source) 77 { 78 this->buffer = source.buffer; 79 this->sourceNode = sourceNode; 80 this->resident = source.resident; 81 82 if (source.bPlay) 83 this->play(); 84 else 85 this->stop(); 86 } 87 88 89 /** 90 * @brief compares two Sources with each other. 91 * @param source the Source to compare against this One. 92 * Two Sources are the same, if the PNodes match, and the Sound Played are the same. 93 * The alSource must not match, because no two Sources can have the same alSource. 94 */ 95 bool SoundSource::operator==(const SoundSource& source) 96 { 97 return (this->buffer == source.buffer && 98 this->bPlay == source.bPlay && 99 this->sourceNode == source.sourceNode); 100 } 101 102 103 /** 104 * @brief deletes a SoundSource 105 */ 106 SoundSource::~SoundSource() 107 { 108 this->stop(); 109 if (this->sourceID != 0) 110 SoundEngine::getInstance()->pushALSource(this->sourceID); 111 } 112 113 114 /** 115 * @brief Plays back a SoundSource 116 */ 117 void SoundSource::play() 118 { 119 if (this->buffer && this->retrieveSource()) 120 { 121 if (this->bPlay) 122 alSourceStop(this->sourceID); 123 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 124 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE ); 125 alSourcePlay(this->sourceID); 126 127 if (DEBUG_LEVEL >= 3) 128 SoundEngine::checkError("Play Source", __LINE__); 129 this->bPlay = true; 130 } 131 } 132 133 134 /** 135 * @brief Plays back buffer on this Source 136 * @param buffer the buffer to play back on this Source 137 */ 138 void SoundSource::play(const SoundBuffer* buffer) 139 { 140 if (!this->retrieveSource()) 141 { 142 PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n"); 143 return; 144 } 145 146 alSourceStop(this->sourceID); 147 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 148 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE ); 149 alSourcePlay(this->sourceID); 150 151 if (unlikely(this->buffer != NULL)) 152 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 153 this->bPlay = true; 154 155 if (DEBUG_LEVEL >= 3) 156 SoundEngine::checkError("Play Source", __LINE__); 157 } 158 26 /** 27 * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer 28 */ 29 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) 30 { 31 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 32 33 // adding the Source to the SourcesList of the SoundEngine 34 this->buffer = buffer; 35 this->sourceNode = sourceNode; 36 this->resident = false; 37 38 this->sourceID = 0; 39 this->bPlay = false; 40 } 41 42 43 /** 44 * @brief construct a SoundSource out of the another soundSource 45 * @param source the Source to create this source from. 46 * 47 * Copies the buffer from source to this Source. 48 * Acquires a new SourceID if source is Playing. 49 */ 50 SoundSource::SoundSource(const SoundSource& source) 51 { 52 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 53 54 // adding the Source to the SourcesList of the SoundEngine 55 this->buffer = source.buffer; 56 this->sourceNode = source.sourceNode; 57 this->resident = source.resident; 58 59 this->sourceID = 0; 60 if (source.bPlay == true) 61 { 62 this->bPlay = true; 63 SoundEngine::getInstance()->popALSource(this->sourceID); 64 } 65 else 66 this->bPlay = false; 67 } 68 69 70 /** 71 * @brief paste a copy of the source into this Source. 72 * @param source the SoundSource to paste into this one. 73 * @returns a Reference to this Source. 74 * 75 */ 76 SoundSource& SoundSource::operator=(const SoundSource& source) 77 { 78 this->buffer = source.buffer; 79 this->sourceNode = sourceNode; 80 this->resident = source.resident; 81 82 if (source.bPlay) 83 this->play(); 84 else 85 this->stop(); 86 } 87 88 89 /** 90 * @brief compares two Sources with each other. 91 * @param source the Source to compare against this One. 92 * Two Sources are the same, if the PNodes match, and the Sound Played are the same. 93 * The alSource must not match, because no two Sources can have the same alSource. 94 */ 95 bool SoundSource::operator==(const SoundSource& source) 96 { 97 return (this->buffer == source.buffer && 98 this->bPlay == source.bPlay && 99 this->sourceNode == source.sourceNode); 100 } 101 102 103 /** 104 * @brief deletes a SoundSource 105 */ 106 SoundSource::~SoundSource() 107 { 108 this->stop(); 109 if (this->sourceID != 0) 110 SoundEngine::getInstance()->pushALSource(this->sourceID); 111 } 112 113 114 /** 115 * @brief Plays back a SoundSource 116 */ 117 void SoundSource::play() 118 { 119 if (this->buffer && this->retrieveSource()) 120 { 121 if (this->bPlay) 122 alSourceStop(this->sourceID); 123 124 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 125 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 126 alSourcef (this->sourceID, AL_GAIN, 1); 127 alSourcePlay(this->sourceID); 128 129 if (DEBUG_LEVEL >= 3) 130 SoundEngine::checkError("Play Source", __LINE__); 131 this->bPlay = true; 132 } 133 } 134 135 136 /** 137 * @brief Plays back buffer on this Source 138 * @param buffer the buffer to play back on this Source 139 */ 140 void SoundSource::play(const SoundBuffer* buffer) 141 { 142 if (!this->retrieveSource()) 143 { 144 PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n"); 145 return; 146 } 147 148 alSourceStop(this->sourceID); 149 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 150 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 151 alSourcef (this->sourceID, AL_GAIN, 1); 152 153 alSourcePlay(this->sourceID); 154 155 if (unlikely(this->buffer != NULL)) 156 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 157 this->bPlay = true; 158 159 if (DEBUG_LEVEL >= 3) 160 SoundEngine::checkError("Play Source", __LINE__); 161 } 162 163 164 /** 165 * @brief Plays back buffer on this Source with gain 166 * @param buffer the buffer to play back on this Source 167 */ 168 void SoundSource::play(const SoundBuffer* buffer, float gain) 169 { 170 if (!this->retrieveSource()) 171 { 172 PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n"); 173 return; 174 } 175 176 alSourceStop(this->sourceID); 177 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 178 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 179 alSourcef (this->sourceID, AL_GAIN, gain); 180 181 alSourcePlay(this->sourceID); 182 183 if (unlikely(this->buffer != NULL)) 184 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 185 this->bPlay = true; 186 187 if (DEBUG_LEVEL >= 3) 188 SoundEngine::checkError("Play Source", __LINE__); 189 } 190 191 192 /** 193 * @brief Plays and loops back a SoundSource 194 */ 195 void SoundSource::loop() 196 { 197 if (this->buffer && this->retrieveSource()) 198 { 199 if (this->bPlay) 200 alSourceStop(this->sourceID); 201 202 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 203 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 204 alSourcef (this->sourceID, AL_GAIN, 1); 205 alSourcePlay(this->sourceID); 206 207 if (DEBUG_LEVEL >= 3) 208 SoundEngine::checkError("Play Source", __LINE__); 209 this->bPlay = true; 210 } 211 } 159 212 160 213 /** 161 162 163 214 * @brief Plays and loops buffer on this Source 215 * @param buffer the buffer to play back on this Source 216 */ 164 217 void SoundSource::loop(const SoundBuffer* buffer) 165 218 { 166 if (this->buffer && this->retrieveSource()) 167 { 168 if (this->bPlay) 169 alSourceStop(this->sourceID); 170 171 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 172 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE ); 173 alSourcePlay(this->sourceID); 174 175 if (DEBUG_LEVEL >= 3) 176 SoundEngine::checkError("Play LoopSource", __LINE__); 177 this->bPlay = true; 178 } 219 if (this->buffer && this->retrieveSource()) 220 { 221 if (this->bPlay) 222 alSourceStop(this->sourceID); 223 224 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 225 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 226 alSourcef (this->sourceID, AL_GAIN, 1); 227 228 alSourcePlay(this->sourceID); 229 230 if (DEBUG_LEVEL >= 3) 231 SoundEngine::checkError("Play LoopSource", __LINE__); 232 this->bPlay = true; 233 } 179 234 } 180 235 181 236 182 237 /** 183 * @brief Stops playback of a SoundSource 184 */ 238 * @brief Plays and loops buffer on this Source with gain control 239 * @param buffer the buffer to play back on this Source 240 */ 241 void SoundSource::loop(const SoundBuffer* buffer, float gain) 242 { 243 if (this->buffer && this->retrieveSource()) 244 { 245 if (this->bPlay) 246 alSourceStop(this->sourceID); 247 248 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 249 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 250 alSourcef (this->sourceID, AL_GAIN, gain); 251 252 alSourcePlay(this->sourceID); 253 254 if (DEBUG_LEVEL >= 3) 255 SoundEngine::checkError("Play LoopSource", __LINE__); 256 this->bPlay = true; 257 } 258 } 259 260 261 /** 262 * @brief Stops playback of a SoundSource 263 */ 185 264 void SoundSource::stop() 186 265 { 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 266 this->bPlay = false; 267 if (this->sourceID != 0) 268 { 269 this->bPlay = false; 270 if (this->sourceID != 0) 271 { 272 alSourceStop(this->sourceID); 273 if (DEBUG_LEVEL >= 3) 274 SoundEngine::checkError("StopSource", __LINE__); 275 alSourcei(this->sourceID, AL_BUFFER, 0); 276 if (!this->resident) 277 SoundEngine::getInstance()->pushALSource(this->sourceID); 278 this->sourceID = 0; 279 } 280 } 202 281 } 203 282 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 283 /** 284 * @brief Pauses Playback of a SoundSource 285 */ 286 void SoundSource::pause() 287 { 288 alSourcePause(this->sourceID); 289 if (DEBUG_LEVEL >= 3) 290 SoundEngine::checkError("Pause Source", __LINE__); 291 } 292 293 294 /** 295 * @brief Rewinds Playback of a SoundSource 296 */ 297 void SoundSource::rewind() 298 { 299 alSourceRewind(this->sourceID); 300 301 if (DEBUG_LEVEL >= 3) 302 SoundEngine::checkError("Rewind Source", __LINE__); 303 } 304 305 306 /** 307 * @brief sets the RolloffFactor of the Sound emitted from the SoundSource 308 * @param rolloffFactor The Factor described 309 * 310 * this tells openAL how fast the Sounds decay outward from the Source 311 */ 312 void SoundSource::setRolloffFactor(ALfloat rolloffFactor) 313 { 314 alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor); 315 316 if (DEBUG_LEVEL >= 3) 317 SoundEngine::checkError("Set Source Rolloff-factor", __LINE__); 318 } 319 320 321 /** 322 * @brief sets the Positional this Source should be attached to. 323 * @param sourceNode the Source this is attached to. 324 * If sourceNode == NULL then the Source will be centered, and Audio will be played on all channels. 325 */ 326 void SoundSource::setSourceNode(const PNode* sourceNode) 327 { 328 this->sourceNode = sourceNode; 329 } 330 331 /** 332 * @brief retrieve a Source. 333 */ 334 bool SoundSource::retrieveSource() 335 { 336 if (this->sourceID != 0) 337 return true; 338 else 339 { 340 SoundEngine::getInstance()->popALSource(this->sourceID); 341 if (this->sourceID != 0) 342 { 343 if (unlikely(this->sourceNode == NULL)) 344 resetSource(this->sourceID); 345 return true; 346 } 347 } 348 return false; 349 } 350 351 352 /** 353 * @brief reset an alSource to its default Values. 354 */ 355 void SoundSource::resetSource(ALuint sourceID) 356 { 357 alSource3f(sourceID, AL_POSITION, 0.0, 0.0, 0.0); 358 alSource3f(sourceID, AL_VELOCITY, 0.0, 0.0, 0.0); 359 alSource3f(sourceID, AL_DIRECTION, 0.0, 0.0, 0.0); 360 alSourcef (sourceID, AL_ROLLOFF_FACTOR, 0.0 ); 361 //alSourcei (sourceID, AL_SOURCE_RELATIVE, AL_TRUE ); 362 alSourcef (sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume()); 363 } 285 364 } -
branches/atmospheric_engine/src/lib/sound/sound_source.h
r7810 r8052 29 29 void play(); 30 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 31 32 void loop(); 32 33 void loop(const SoundBuffer* buffer); 34 void loop(const SoundBuffer* buffer, float gain); 33 35 void stop(); 34 36 void pause();
Note: See TracChangeset
for help on using the changeset viewer.