Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.cc @ 7651

Last change on this file since 7651 was 7651, checked in by amaechler, 18 years ago

branches/atmosphere_engine: cosmetics

File size: 3.9 KB
Line 
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"
21#include "debug.h"
22
23#include "p_node.h"
24#include "state.h"
25#include "sprite_particles.h"
26#include "plane_emitter.h"
27#include "shell_command.h"
28
29#include "parser/tinyxml/tinyxml.h"
30
31SHELL_COMMAND(activate, SnowEffect, activateSnow);
32SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow);
33
34using namespace std;
35
36CREATE_FACTORY(SnowEffect, CL_SNOW_EFFECT);
37
38SnowEffect::SnowEffect(const TiXmlElement* root)
39{
40  this->setClassID(CL_SNOW_EFFECT, "SnowEffect");
41
42  this->init();
43
44  if (root != NULL)
45    this->loadParams(root);
46
47  this->activate();
48}
49
50
51SnowEffect::~SnowEffect()
52{
53  this->deactivate();
54}
55
56SpriteParticles* SnowEffect::snowParticles = NULL;
57
58void SnowEffect::loadParams(const TiXmlElement* root)
59{
60  WeatherEffect::loadParams(root);
61
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);
72}
73
74bool SnowEffect::init()
75{
76  this->emitter = new PlaneEmitter();
77
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;
88  velocity = -100;
89  randomVelocity = 5;
90  angle = 0;
91  randomAngle = 0.3;
92  alpha = 0.5;
93  snowSize = Vector2D(1200, 1200);
94  snowCoord = Vector(100, 600, 200);
95
96  activated = false;
97}
98
99bool SnowEffect::activate()
100{
101  PRINTF(0)("Activating SnowEffect\n");
102  activated = true;
103 
104  SnowEffect::snowParticles = new SpriteParticles(particles);
105  SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
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);
112  SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
113  SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
114  SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
115
116 
117  this->emitter->setSystem(SnowEffect::snowParticles);
118 
119 // this->updateNode(0);
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);
125}
126
127
128bool SnowEffect::deactivate()
129{
130  PRINTF(0)("Deactivating SnowEffect\n");
131  activated = false;
132 
133  this->emitter->setSystem(NULL);
134}
135
136void SnowEffect::activateSnow()
137{
138  this->activate();
139}
140
141void SnowEffect::deactivateSnow()
142{
143  this->deactivate();
144}
145
146void SnowEffect::draw() const
147{
148}
149
150void SnowEffect::tick(float dt)
151{
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();
157}
158
Note: See TracBrowser for help on using the repository browser.