Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2006, 3:21:12 PM (18 years ago)
Author:
bensch
Message:

orxonox/new_class_id: SoundSource completely added as a Resource

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/world_entities/weather_effects/snow_effect.cc

    r9760 r9805  
    1717#include "util/loading/load_param.h"
    1818#include "util/loading/factory.h"
    19 #include "util/loading/resource_manager.h"
     19#include "sound/resource_sound_buffer.h"
    2020
    2121#include "glincl.h"
     
    3838
    3939CREATE_SCRIPTABLE_CLASS(SnowEffect,
    40                             addMethod("activate", Executor0<SnowEffect, lua_State*>(&SnowEffect::activate))
    41                             ->addMethod("deactivate", Executor0<SnowEffect, lua_State*>(&SnowEffect::deactivate))
     40                        addMethod("activate", Executor0<SnowEffect, lua_State*>(&SnowEffect::activate))
     41                        ->addMethod("deactivate", Executor0<SnowEffect, lua_State*>(&SnowEffect::deactivate))
    4242                       );
    4343
     
    4848  this->registerObject(this, SnowEffect::_objectList);
    4949
    50         this->init();
    51 
    52         if (root != NULL)
    53                 this->loadParams(root);
    54 
    55         this->windBuffer = NULL;
    56         //load wind sound
    57         if (this->snowWindForce >= 1) {
    58           this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV);
    59         }
    60 
    61   if(snowActivate) {
    62                 this->activate();
     50  this->init();
     51
     52  if (root != NULL)
     53    this->loadParams(root);
     54
     55  //load wind sound
     56  if (this->snowWindForce >= 1)
     57  {
     58    this->windBuffer = OrxSound::ResourceSoundBuffer("sound/atmosphere/wind.wav");
     59  }
     60
     61  if(snowActivate)
     62  {
     63    this->activate();
    6364    SnowEffect::snowParticles->precache((int) this->snowLife);
    6465  }
     
    6869SnowEffect::~SnowEffect()
    6970{
    70         this->deactivate();
     71  this->deactivate();
    7172}
    7273
     
    7576void SnowEffect::loadParams(const TiXmlElement* root)
    7677{
    77         WeatherEffect::loadParams(root);
    78 
    79         LoadParam(root, "numParticles", this, SnowEffect, numParticles);
    80         LoadParam(root, "materialTexture", this, SnowEffect, materialTexture);
    81         LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan);
    82         LoadParam(root, "radius", this, SnowEffect, radius);
    83         LoadParam(root, "mass", this, SnowEffect, mass);
    84         LoadParam(root, "emissionRate", this, SnowEffect, emissionRate);
    85         LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity);
    86         LoadParam(root, "wind", this, SnowEffect, wind);
    87         LoadParam(root, "size", this, SnowEffect, size);
    88         LoadParam(root, "coord", this, SnowEffect, coord);
     78  WeatherEffect::loadParams(root);
     79
     80  LoadParam(root, "numParticles", this, SnowEffect, numParticles);
     81  LoadParam(root, "materialTexture", this, SnowEffect, materialTexture);
     82  LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan);
     83  LoadParam(root, "radius", this, SnowEffect, radius);
     84  LoadParam(root, "mass", this, SnowEffect, mass);
     85  LoadParam(root, "emissionRate", this, SnowEffect, emissionRate);
     86  LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity);
     87  LoadParam(root, "wind", this, SnowEffect, wind);
     88  LoadParam(root, "size", this, SnowEffect, size);
     89  LoadParam(root, "coord", this, SnowEffect, coord);
    8990  LoadParam(root, "cloudcolor", this, SnowEffect, setCloudColor);
    9091  LoadParam(root, "skycolor", this, SnowEffect, setSkyColor);
    9192  LoadParam(root, "fadetime", this, SnowEffect, setFadeTime);
    9293
    93         LOAD_PARAM_START_CYCLE(root, element);
    94         {
    95                 LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
    96         }
    97         LOAD_PARAM_END_CYCLE(element);
     94  LOAD_PARAM_START_CYCLE(root, element);
     95  {
     96    LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
     97  }
     98  LOAD_PARAM_END_CYCLE(element);
    9899}
    99100
    100101void SnowEffect::init()
    101102{
    102         this->emitter = new PlaneEmitter();
    103 
    104         // Default values
    105         this->snowActivate = false;
    106         this->snowMove = false;
    107         this->particles = 12000;
    108         this->texture = "maps/snow_flake_01_32x32.png";
    109         this->snowLife = 8;
    110         this->randomLife = 2;
    111         this->snowRadius = 3.5;
    112         this->randomRadius = 1;
    113         this->snowMass = 1.0;
    114         this->randomMass = 0.3;
    115         this->rate = 900;
    116         this->velocity = -100;
    117         this->randomVelocity = 5;
    118         this->angle = 0.5;
    119         this->randomAngle = 0.2;
    120         this->alpha = 0.5;
    121         this->snowSize = Vector2D(2500, 2500);
    122         this->snowCoord = Vector(100,450,400);
    123         this->snowWindForce = 1;
     103  this->emitter = new PlaneEmitter();
     104
     105  // Default values
     106  this->snowActivate = false;
     107  this->snowMove = false;
     108  this->particles = 12000;
     109  this->texture = "maps/snow_flake_01_32x32.png";
     110  this->snowLife = 8;
     111  this->randomLife = 2;
     112  this->snowRadius = 3.5;
     113  this->randomRadius = 1;
     114  this->snowMass = 1.0;
     115  this->randomMass = 0.3;
     116  this->rate = 900;
     117  this->velocity = -100;
     118  this->randomVelocity = 5;
     119  this->angle = 0.5;
     120  this->randomAngle = 0.2;
     121  this->alpha = 0.5;
     122  this->snowSize = Vector2D(2500, 2500);
     123  this->snowCoord = Vector(100,450,400);
     124  this->snowWindForce = 1;
    124125
    125126  this->fadeTime = 10;
     
    130131void SnowEffect::activate()
    131132{
    132         PRINTF(3)("Activating SnowEffect\n");
    133 
    134         this->snowActivate = true;
    135 
    136         SnowEffect::snowParticles = new SpriteParticles(particles);
    137         SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
    138         SnowEffect::snowParticles->setMaterialTexture(texture);
    139         SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife);
    140         SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius);
    141         SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8);
    142         SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5);
    143         SnowEffect::snowParticles->setMass(0, snowMass, randomMass);
    144         SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    145         SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    146         SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    147 
    148         this->emitter->setSystem(SnowEffect::snowParticles);
    149 
    150         this->emitter->setRelCoor(snowCoord);
    151         this->emitter->setEmissionRate(rate);
    152         this->emitter->setEmissionVelocity(velocity, randomVelocity);
    153         this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce);
    154         this->emitter->setSize(snowSize);
     133  PRINTF(3)("Activating SnowEffect\n");
     134
     135  this->snowActivate = true;
     136
     137  SnowEffect::snowParticles = new SpriteParticles(particles);
     138  SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
     139  SnowEffect::snowParticles->setMaterialTexture(texture);
     140  SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife);
     141  SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius);
     142  SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8);
     143  SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5);
     144  SnowEffect::snowParticles->setMass(0, snowMass, randomMass);
     145  SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
     146  SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
     147  SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
     148
     149  this->emitter->setSystem(SnowEffect::snowParticles);
     150
     151  this->emitter->setRelCoor(snowCoord);
     152  this->emitter->setEmissionRate(rate);
     153  this->emitter->setEmissionVelocity(velocity, randomVelocity);
     154  this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce);
     155  this->emitter->setSize(snowSize);
    155156
    156157  if (this->snowWindForce != 0)
     
    170171void SnowEffect::deactivate()
    171172{
    172         PRINTF(3)("Deactivating SnowEffect\n");
    173 
    174         this->snowActivate = false;
    175         this->emitter->setSystem(NULL);
    176 
    177         if (this->windBuffer != NULL)
    178                 ResourceManager::getInstance()->unload(this->windBuffer);
     173  PRINTF(3)("Deactivating SnowEffect\n");
     174
     175  this->snowActivate = false;
     176  this->emitter->setSystem(NULL);
    179177
    180178  // Restore the old cloud- and sky color
     
    185183void SnowEffect::draw() const
    186184{
    187         if (!this->snowActivate)
    188                 return;
     185  if (!this->snowActivate)
     186    return;
    189187}
    190188
    191189void SnowEffect::tick(float dt)
    192190{
    193         if (!this->snowActivate)
    194                 return;
    195 
    196         /*
    197         float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
    198 
    199         if(activated)
    200         {
    201         if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
    202                         this->deactivate();
    203         else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
    204         this->alpha = 0.15;
    205         else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
    206         this->alpha = 0.25;
    207         else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
    208         this->alpha = 0.4;
    209 
    210         SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    211         SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    212         SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    213         }
    214         else
    215         {
    216         if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
    217         this->activate();
    218         if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
    219         this->alpha = 0.25;
    220         else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
    221         this->alpha = 0.4;
    222         else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
    223         this->alpha = 0.5;
    224 
    225         SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    226         SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    227         SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    228         }*/
    229 
    230         if (this->snowMove) {
    231                 this->snowCoord = State::getCameraNode()->getAbsCoor();
    232                 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z);
    233         }
    234 }
     191  if (!this->snowActivate)
     192    return;
     193
     194  /*
     195  float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
     196
     197  if(activated)
     198  {
     199  if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
     200                  this->deactivate();
     201  else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
     202  this->alpha = 0.15;
     203  else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
     204  this->alpha = 0.25;
     205  else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
     206  this->alpha = 0.4;
     207
     208  SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
     209  SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
     210  SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
     211  }
     212  else
     213  {
     214  if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
     215  this->activate();
     216  if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
     217  this->alpha = 0.25;
     218  else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
     219  this->alpha = 0.4;
     220  else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
     221  this->alpha = 0.5;
     222
     223  SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
     224  SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
     225  SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
     226  }*/
     227
     228  if (this->snowMove)
     229  {
     230    this->snowCoord = State::getCameraNode()->getAbsCoor();
     231    this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z);
     232  }
     233}
Note: See TracChangeset for help on using the changeset viewer.