/* 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 "snow_effect.h" #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "glincl.h" #include "debug.h" #include "p_node.h" #include "state.h" #include "sprite_particles.h" #include "plane_emitter.h" #include "shell_command.h" #include "parser/tinyxml/tinyxml.h" SHELL_COMMAND(activate, SnowEffect, activateSnow); SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow); using namespace std; CREATE_FACTORY(SnowEffect, CL_SNOW_EFFECT); SnowEffect::SnowEffect(const TiXmlElement* root) { this->setClassID(CL_SNOW_EFFECT, "SnowEffect"); this->init(); if (root != NULL) this->loadParams(root); this->activate(); } SnowEffect::~SnowEffect() { this->deactivate(); } SpriteParticles* SnowEffect::snowParticles = NULL; void SnowEffect::loadParams(const TiXmlElement* root) { WeatherEffect::loadParams(root); LoadParam(root, "numParticles", this, SnowEffect, numParticles); LoadParam(root, "materialTexture", this, SnowEffect, materialTexture); LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan); LoadParam(root, "radius", this, SnowEffect, radius); LoadParam(root, "mass", this, SnowEffect, mass); LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); LoadParam(root, "spread", this, SnowEffect, spread); LoadParam(root, "size", this, SnowEffect, size); LoadParam(root, "coord", this, SnowEffect, coord); } bool SnowEffect::init() { this->emitter = new PlaneEmitter(); // Default values particles = 10000; texture = "maps/snow_flake_01_32x32.png"; life = 8; randomLife = 2; snowRadius = 3.5; randomRadius = 1; snowMass = 1.0; randomMass = 0.3; rate = 900; velocity = -100; randomVelocity = 5; angle = 0; randomAngle = 0.3; alpha = 0.5; snowSize = Vector2D(1200, 1200); snowCoord = Vector(100, 600, 200); activated = false; } bool SnowEffect::activate() { PRINTF(0)("Activating SnowEffect\n"); activated = true; SnowEffect::snowParticles = new SpriteParticles(particles); SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); SnowEffect::snowParticles->setMaterialTexture(texture); SnowEffect::snowParticles->setLifeSpan(life, randomLife); SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius); SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius); SnowEffect::snowParticles->setMass(0, snowMass, randomMass); SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); this->emitter->setSystem(SnowEffect::snowParticles); // this->updateNode(0); this->emitter->setRelCoor(snowCoord); this->emitter->setEmissionRate(rate); this->emitter->setEmissionVelocity(velocity, randomVelocity); this->emitter->setSpread(angle, randomAngle); this->emitter->setSize(snowSize); } bool SnowEffect::deactivate() { PRINTF(0)("Deactivating SnowEffect\n"); activated = false; this->emitter->setSystem(NULL); } void SnowEffect::activateSnow() { this->activate(); } void SnowEffect::deactivateSnow() { this->deactivate(); } void SnowEffect::draw() const { } void SnowEffect::tick(float dt) { float distance = (State::getCameraNode()->getAbsCoor() - snowCoord).len(); if( activated && ( distance > 0.6*snowSize.x || distance > 0.6*snowSize.y) ) this->deactivate(); if( !activated && ( distance < 0.6*snowSize.x || distance < 0.6*snowSize.y )) this->activate(); }