[7573] | 1 | /* |
---|
| 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: hdavid, amaechler |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include "snow_effect.h" |
---|
| 16 | |
---|
| 17 | #include "util/loading/load_param.h" |
---|
| 18 | #include "util/loading/factory.h" |
---|
| 19 | |
---|
| 20 | #include "glincl.h" |
---|
[7576] | 21 | #include "debug.h" |
---|
[7573] | 22 | |
---|
[7650] | 23 | #include "p_node.h" |
---|
[7573] | 24 | #include "state.h" |
---|
| 25 | #include "sprite_particles.h" |
---|
| 26 | #include "plane_emitter.h" |
---|
[7649] | 27 | #include "shell_command.h" |
---|
[7573] | 28 | |
---|
| 29 | #include "parser/tinyxml/tinyxml.h" |
---|
| 30 | |
---|
[7649] | 31 | SHELL_COMMAND(activate, SnowEffect, activateSnow); |
---|
| 32 | SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow); |
---|
[7576] | 33 | |
---|
[7573] | 34 | using namespace std; |
---|
| 35 | |
---|
| 36 | CREATE_FACTORY(SnowEffect, CL_SNOW_EFFECT); |
---|
| 37 | |
---|
| 38 | SnowEffect::SnowEffect(const TiXmlElement* root) |
---|
| 39 | { |
---|
| 40 | this->setClassID(CL_SNOW_EFFECT, "SnowEffect"); |
---|
| 41 | |
---|
[7649] | 42 | this->init(); |
---|
[7651] | 43 | |
---|
[7573] | 44 | if (root != NULL) |
---|
| 45 | this->loadParams(root); |
---|
| 46 | |
---|
| 47 | this->activate(); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | SnowEffect::~SnowEffect() |
---|
| 52 | { |
---|
| 53 | this->deactivate(); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | SpriteParticles* SnowEffect::snowParticles = NULL; |
---|
| 57 | |
---|
| 58 | void SnowEffect::loadParams(const TiXmlElement* root) |
---|
| 59 | { |
---|
| 60 | WeatherEffect::loadParams(root); |
---|
| 61 | |
---|
[7651] | 62 | LoadParam(root, "numParticles", this, SnowEffect, numParticles); |
---|
| 63 | LoadParam(root, "materialTexture", this, SnowEffect, materialTexture); |
---|
| 64 | LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan); |
---|
| 65 | LoadParam(root, "radius", this, SnowEffect, radius); |
---|
| 66 | LoadParam(root, "mass", this, SnowEffect, mass); |
---|
| 67 | LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); |
---|
| 68 | LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); |
---|
| 69 | LoadParam(root, "spread", this, SnowEffect, spread); |
---|
| 70 | LoadParam(root, "size", this, SnowEffect, size); |
---|
| 71 | LoadParam(root, "coord", this, SnowEffect, coord); |
---|
[7573] | 72 | } |
---|
| 73 | |
---|
| 74 | bool SnowEffect::init() |
---|
| 75 | { |
---|
[7576] | 76 | this->emitter = new PlaneEmitter(); |
---|
[7651] | 77 | |
---|
[7649] | 78 | // Default values |
---|
| 79 | particles = 10000; |
---|
| 80 | texture = "maps/snow_flake_01_32x32.png"; |
---|
| 81 | life = 8; |
---|
| 82 | randomLife = 2; |
---|
| 83 | snowRadius = 3.5; |
---|
| 84 | randomRadius = 1; |
---|
| 85 | snowMass = 1.0; |
---|
| 86 | randomMass = 0.3; |
---|
| 87 | rate = 900; |
---|
[7651] | 88 | velocity = -100; |
---|
| 89 | randomVelocity = 5; |
---|
[7649] | 90 | angle = 0; |
---|
| 91 | randomAngle = 0.3; |
---|
[7650] | 92 | alpha = 0.5; |
---|
[7649] | 93 | snowSize = Vector2D(1200, 1200); |
---|
| 94 | snowCoord = Vector(100, 600, 200); |
---|
[7651] | 95 | |
---|
[7650] | 96 | activated = false; |
---|
[7573] | 97 | } |
---|
| 98 | |
---|
| 99 | bool SnowEffect::activate() |
---|
| 100 | { |
---|
[7628] | 101 | PRINTF(0)("Activating SnowEffect\n"); |
---|
[7650] | 102 | activated = true; |
---|
[7576] | 103 | |
---|
[7649] | 104 | SnowEffect::snowParticles = new SpriteParticles(particles); |
---|
[7573] | 105 | SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); |
---|
[7649] | 106 | SnowEffect::snowParticles->setMaterialTexture(texture); |
---|
| 107 | SnowEffect::snowParticles->setLifeSpan(life, randomLife); |
---|
| 108 | SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); |
---|
| 109 | SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius); |
---|
| 110 | SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius); |
---|
| 111 | SnowEffect::snowParticles->setMass(0, snowMass, randomMass); |
---|
[7650] | 112 | SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); |
---|
| 113 | SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); |
---|
[7576] | 114 | SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); |
---|
| 115 | |
---|
[7573] | 116 | |
---|
| 117 | this->emitter->setSystem(SnowEffect::snowParticles); |
---|
[7576] | 118 | |
---|
| 119 | // this->updateNode(0); |
---|
[7649] | 120 | this->emitter->setRelCoor(snowCoord); |
---|
| 121 | this->emitter->setEmissionRate(rate); |
---|
| 122 | this->emitter->setEmissionVelocity(velocity, randomVelocity); |
---|
| 123 | this->emitter->setSpread(angle, randomAngle); |
---|
| 124 | this->emitter->setSize(snowSize); |
---|
[7573] | 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | bool SnowEffect::deactivate() |
---|
| 129 | { |
---|
[7628] | 130 | PRINTF(0)("Deactivating SnowEffect\n"); |
---|
[7650] | 131 | activated = false; |
---|
[7576] | 132 | |
---|
| 133 | this->emitter->setSystem(NULL); |
---|
[7573] | 134 | } |
---|
| 135 | |
---|
[7649] | 136 | void SnowEffect::activateSnow() |
---|
| 137 | { |
---|
| 138 | this->activate(); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | void SnowEffect::deactivateSnow() |
---|
| 142 | { |
---|
| 143 | this->deactivate(); |
---|
| 144 | } |
---|
| 145 | |
---|
[7573] | 146 | void SnowEffect::draw() const |
---|
| 147 | { |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void SnowEffect::tick(float dt) |
---|
| 151 | { |
---|
[7650] | 152 | float distance = (State::getCameraNode()->getAbsCoor() - snowCoord).len(); |
---|
| 153 | if( activated && ( distance > 0.6*snowSize.x || distance > 0.6*snowSize.y) ) |
---|
| 154 | this->deactivate(); |
---|
| 155 | if( !activated && ( distance < 0.6*snowSize.x || distance < 0.6*snowSize.y )) |
---|
| 156 | this->activate(); |
---|
[7573] | 157 | } |
---|
[7649] | 158 | |
---|