/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: hdavid, amaechler */ #include "rain_effect.h" #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "util/loading/resource_manager.h" #include "glincl.h" #include "p_node.h" #include "state.h" #include "spark_particles.h" #include "plane_emitter.h" #include "parser/tinyxml/tinyxml.h" //SHELL_COMMAND(activate, RainEffect, activateRain); //SHELL_COMMAND(deactivate, RainEffect, deactivateRain); using namespace std; CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); RainEffect::RainEffect(const TiXmlElement* root) { this->setClassID(CL_RAIN_EFFECT, "RainEffect"); this->init(); if (root != NULL) this->loadParams(root); //load sound if (this->rainBuffer != NULL) ResourceManager::getInstance()->unload(this->rainBuffer); this->rainBuffer = (SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV); this->activate(); } RainEffect::~RainEffect() { this->deactivate(); } void RainEffect::loadParams(const TiXmlElement* root) { WeatherEffect::loadParams(root); // LoadParam(root, "moverain", this, RainEffect, setMoveRain); LoadParam(root, "coord", this, RainEffect, setRainCoord); LoadParam(root, "size", this, RainEffect, setRainSize); LoadParam(root, "rate", this, RainEffect, setRainRate); LoadParam(root, "velocity", this, RainEffect, setRainVelocity); LoadParam(root, "life", this, RainEffect, setRainLife); LoadParam(root, "wind", this, RainEffect, setRainWind); LoadParam(root, "option", this, RainEffect, setRainOption); } bool RainEffect::init() { //Default values this->rainCoord = Vector(500, 500, 500); this->rainSize = Vector2D(1000, 1000); this->rainRate = 3000; this->rainVelocity = -300; this->rainLife = 4; this->rainMaxParticles = this->rainRate * this->rainLife; this->rainWindForce = 0; this->emitter = new PlaneEmitter(this->rainSize); } SparkParticles* RainEffect::rainParticles = NULL; bool RainEffect::activate() { 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" ); if (unlikely(RainEffect::rainParticles == NULL)) { RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); RainEffect::rainParticles->setName("RainParticles"); RainEffect::rainParticles->precache((int)this->rainLife); RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); RainEffect::rainParticles->setRadius(0, 0.03); RainEffect::rainParticles->setRadius(0.2, 0.02); RainEffect::rainParticles->setRadius(1, 0.01); RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey } this->emitter->setSystem(RainEffect::rainParticles); this->emitter->setRelCoor(this->rainCoord); this->emitter->setEmissionRate(this->rainRate); this->emitter->setEmissionVelocity(this->rainVelocity); this->emitter->setSpread(this->rainWindForce / 50, 0.2); this->soundSource.loop(this->rainBuffer); PRINTF(0)( "Playing RainSound\n" ); } bool RainEffect::deactivate() { PRINTF(0)("Deactivating RainEffect\n"); this->emitter->setSystem(NULL); } void RainEffect::tick (float dt) { //float distance = (State::getCameraNode()->getAbsCoor() - rainCoord).len(); // PRINTF(0)( "RainEffect, coords: %f, %f, %f\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z ); if (this->rainMove) { PRINTF(0)( "Moving Rain" ); this->rainCoord = State::getCameraNode()->getAbsCoor(); this->emitter->setRelCoor(this->rainCoord.x +150, this->rainCoord.y+700, this->rainCoord.z+150); } }