Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc @ 7577

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

branches/atmospheric_engine

File size: 5.8 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 "rain_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "glincl.h"
21
22// *****
23
24#include "material.h"
25#include "state.h"
26#include "shell_command.h"
27
28#include "parser/tinyxml/tinyxml.h"
29#include <algorithm>
30#include "box_emitter.h"
31#include "spark_particles.h"
32
33
34using namespace std;
35
36CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
37
38RainEffect::RainEffect(const TiXmlElement* root)
39{
40  this->setClassID(CL_RAIN_EFFECT, "RainEffect");
41
42  // BoxEmitter::BoxEmitter(const Vector& size, float emissionRate, float velocity, float angle)
43
44//         <name>RainEmitter</name>
45//         <rel-coor>-1200, 300, 0</rel-coor>
46//         <rel-dir>3.1412, 0, 0, 1</rel-dir>
47//         <spread>0,.3</spread>
48//         <emission-velocity>500,50</emission-velocity>
49//         <size>1000, 1000</size>
50//         <rate>5000</rate>
51
52  this->emitter = new BoxEmitter(Vector(1000, 300, 100), 20000, 1000, M_2_PI);
53  this->emitter->setRelCoor(100, 0, 0);
54  // this->emitter->setParent(this);
55  this->emitter->setSpread(0, 0.3);
56
57  if (root != NULL)
58    this->loadParams(root);
59
60  this->activate();
61}
62
63RainEffect::~RainEffect()
64{
65  this->deactivate();
66}
67
68
69void RainEffect::loadParams(const TiXmlElement* root)
70{
71  WeatherEffect::loadParams(root);
72
73//   LoadParam(root, "rel-coor", this, RainEffect, setRainMode);
74//
75//   LoadParam(root, "rate", this, RainEffect, setRainColor);
76//   LoadParam(root, "velocity", this, RainEffect, setRainColor);
77//   LoadParam(root, "angle", this, RainEffect, setRainColor);
78//
79//   LoadParam(root, "spread", this, RainEffect, setRainColor);
80
81  // BoxEmitter::BoxEmitter(const Vector& size, float emissionRate, float velocity, float angle)
82
83  this->emitter = new BoxEmitter(Vector(0, 1000, 0), 20000, 4000, 1);
84  this->emitter->setRelCoor(0, 100, 0);
85  // this->emitter->setParent(this);
86  this->emitter->setSpread(0, 0.3);
87
88// LOAD_PARAM_START_CYCLE(root, element);
89//   {
90//     element->ToText();
91//     // PER-PARTICLE-ATTRIBUTES:
92//     LoadParam_CYCLE(element, "radius", this, ParticleSystem, setRadius)
93//     .describe("The Radius of each particle over time (TimeIndex [0-1], radius at TimeIndex, randomRadius at TimeIndex)");
94//
95//     LoadParam_CYCLE(element, "mass", this, ParticleSystem, setMass)
96//     .describe("The Mass of each particle over time (TimeIndex: [0-1], mass at TimeIndex, randomMass at TimeIndex)");
97//
98//     LoadParam_CYCLE(element, "color", this, ParticleSystem, setColor)
99//     .describe("The Color of each particle over time (TimeIndex: [0-1], red: [0-1], green: [0-1], blue: [0-1], alpha: [0-1])");
100//   }
101//   LOAD_PARAM_END_CYCLE(element);
102
103}
104
105bool RainEffect::init()
106{}
107
108SparkParticles* RainEffect::rainParticles = NULL;
109
110bool RainEffect::activate()
111{
112//   PRINTF(0)( "Enabling Rain Effect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->rainMode, this->rainDensity, this->rainStart, this->rainEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
113        PRINTF(0)("Activating Rain Effect\n");
114
115        if (unlikely(RainEffect::rainParticles == NULL))
116        {
117                RainEffect::rainParticles = new SparkParticles(10000);
118                RainEffect::rainParticles->setName("RainParticles");
119                RainEffect::rainParticles->setLifeSpan(2, 2);
120                RainEffect::rainParticles->setRadius(0.05, 0.05);
121                RainEffect::rainParticles->setRadius(0.04, 0.04);
122                RainEffect::rainParticles->setRadius(0.03, 0.03);
123                RainEffect::rainParticles->setColor(0, 0, 0, 1, .3);
124                RainEffect::rainParticles->setColor(0.5, 0.5, 0.5, 1, 0.2);
125                RainEffect::rainParticles->setColor(0.8, 0.8, 0.2, 0.3, 0.3);
126                RainEffect::rainParticles->setColor(1, 0.5, 0.5, 1, 0);
127
128//      <life-span>2,2</life-span>
129//      <radius>0, 0.05, 0.05</radius>
130//      <radius>1, 0.05, 0.05</radius>
131//      <mass>0,1, .05</mass>
132//      <color>0, 0, 0, 1, .3</color>
133//      <color>.5, .5, .5, 1, .2</color>
134//      <color>1,0.5, .5,1, .0</color>
135//      <precache>2</precache>
136//      <emitters>
137//       <PlaneEmitter>
138
139//       </PlaneEmitter>
140//      </emitters>
141
142        }
143
144        this->emitter->setSystem(RainEffect::rainParticles);
145//      this->size = 4.0;
146
147        RainEffect::rainParticles->debug();
148//      this->updateNode(0);
149        this->emitter->setEmissionRate(5000.0);
150        this->emitter->setEmissionVelocity(50.0);
151
152//      this->setHealth(200);
153
154}
155
156
157bool RainEffect::deactivate()
158{
159  PRINTF(0)("Deactivating Rain Effect\n");
160
161  this->emitter->setSystem(NULL);
162 // this->lifeCycle = 0.0;
163 // this->toList(OM_NULL);
164
165//  GarbageCollector::getInstance()->collect(this);
166//  this->toList(OM_DEAD);
167
168}
169
170void RainEffect::draw() const
171{
172//  Particle* drawPart = ParticleSystem::particles;
173
174//   glDepthMask(GL_FALSE);
175//   glPushAttrib(GL_ENABLE_BIT);
176//
177//   glDisable(GL_LIGHTING);
178//   glDisable(GL_TEXTURE_2D);
179//
180//   glEnable(GL_LINE_SMOOTH);
181//   glEnable(GL_BLEND);
182//   glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
183//
184//   glLineWidth(2.0);
185//   glBegin(GL_LINES);
186//   while (likely(drawPart != NULL))
187//   {
188//   //    printf("%f %f %f %f\n", drawPart->color[0], drawPart->color[1], drawPart->color[2], drawPart->color[3]);
189//     glColor4fv(drawPart->color);
190//     glVertex3f(drawPart->position.x,  drawPart->position.y,  drawPart->position.z);
191//     glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius,
192//                drawPart->position.y - drawPart->velocity.y * drawPart->radius,
193//                drawPart->position.z - drawPart->velocity.z * drawPart->radius);
194//     drawPart = drawPart->next;
195//   }
196//   glEnd();
197//
198//   glDepthMask(GL_TRUE);
199//   glPopAttrib();
200}
Note: See TracBrowser for help on using the repository browser.