root/OpenSceneGraph/trunk/src/osgParticle/ParticleEffect.cpp @ 13041

Revision 13041, 4.3 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgParticle/ParticleEffect>
15#include <osgParticle/ParticleSystemUpdater>
16#include <osg/Geode>
17
18using namespace osgParticle;
19
20ParticleEffect::ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop):
21    osg::Group(copy,copyop),
22    _automaticSetup(copy._automaticSetup),
23    _useLocalParticleSystem(copy._useLocalParticleSystem),
24    _textureFileName(copy._textureFileName),
25    _defaultParticleTemplate(copy._defaultParticleTemplate),
26    _position(copy._position),
27    _scale(copy._scale),
28    _intensity(copy._intensity),
29    _startTime(copy._startTime),
30    _emitterDuration(copy._emitterDuration),
31    _wind(copy._wind)
32{
33}
34
35void ParticleEffect::setUseLocalParticleSystem(bool local)
36{
37    if (_useLocalParticleSystem==local) return;
38
39    _useLocalParticleSystem = local;
40
41    if (_automaticSetup) buildEffect();
42}
43
44void ParticleEffect::setTextureFileName(const std::string& filename)
45{
46    _textureFileName = filename;
47
48    if (_automaticSetup) setUpEmitterAndProgram();
49}
50
51void ParticleEffect::setDefaultParticleTemplate(const Particle& p)
52{
53    _defaultParticleTemplate = p;
54
55    if (_automaticSetup) setUpEmitterAndProgram();
56}
57
58void ParticleEffect::setPosition(const osg::Vec3& position)
59{
60    if (_position==position) return;
61
62    _position = position;
63
64    if (_automaticSetup) setUpEmitterAndProgram();
65}
66
67void ParticleEffect::setScale(float scale)
68{
69    if (_scale==scale) return;
70
71    _scale = scale;
72
73    if (_automaticSetup) setUpEmitterAndProgram();
74}
75
76void ParticleEffect::setIntensity(float intensity)
77{
78    if (_intensity==intensity) return;
79
80    _intensity = intensity;
81
82    if (_automaticSetup) setUpEmitterAndProgram();
83}
84
85void ParticleEffect::setStartTime(double startTime)
86{
87    if (_startTime==startTime) return;
88
89    _startTime =startTime;
90
91    if (_automaticSetup) setUpEmitterAndProgram();
92}
93
94void ParticleEffect::setEmitterDuration(double duration)
95{
96    if (_emitterDuration==duration) return;
97
98    _emitterDuration = duration;
99
100    if (_automaticSetup) setUpEmitterAndProgram();
101}
102
103void ParticleEffect::setParticleDuration(double duration)
104{
105    if (_defaultParticleTemplate.getLifeTime()==duration) return;
106
107    _defaultParticleTemplate.setLifeTime(duration);
108
109    if (_automaticSetup) setUpEmitterAndProgram();
110}
111
112void ParticleEffect::setWind(const osg::Vec3& wind)
113{
114    if (_wind==wind) return;
115
116    _wind = wind;
117
118    if (_automaticSetup) setUpEmitterAndProgram();
119}
120
121void ParticleEffect::setParticleSystem(ParticleSystem* ps)
122{
123    if (_particleSystem==ps) return;
124
125    _particleSystem = ps;
126
127    if (_automaticSetup) buildEffect();
128}
129
130void ParticleEffect::setDefaults()
131{
132    _useLocalParticleSystem = true;
133    _scale = 1.0f;
134    _intensity = 1.0f;
135    _startTime = 0.0;
136    _emitterDuration = 1.0;
137    _wind.set(0.0f,0.0f,0.0f);
138}
139
140void ParticleEffect::buildEffect()
141{
142    setUpEmitterAndProgram();
143
144    osg::ref_ptr<Emitter> emitter = getEmitter();
145    osg::ref_ptr<Program> program = getProgram();
146    osg::ref_ptr<ParticleSystem> particleSystem = getParticleSystem();
147
148    if (!emitter || !particleSystem || !program) return;
149
150
151    // clear the children.
152    removeChildren(0,getNumChildren());
153
154    // add the emitter
155    addChild(emitter.get());
156
157    // add the program to update the particles
158    addChild(program.get());
159
160    // add the particle system updater.
161    osg::ref_ptr<osgParticle::ParticleSystemUpdater> psu = new osgParticle::ParticleSystemUpdater;
162    psu->addParticleSystem(particleSystem.get());
163    addChild(psu.get());
164
165    if (_useLocalParticleSystem)
166    {
167        particleSystem->setParticleScaleReferenceFrame(ParticleSystem::LOCAL_COORDINATES);
168
169        // add the geode to the scene graph
170        osg::Geode* geode = new osg::Geode;
171        geode->addDrawable(particleSystem.get());
172        addChild(geode);
173    }
174}
Note: See TracBrowser for help on using the browser.