source: OGRE/trunk/ogrenew/PlugIns/ParticleFX/src/OgreRotationAffector.cpp @ 692

Revision 692, 7.9 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4        (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreRotationAffector.h"
26#include "OgreParticleSystem.h"
27#include "OgreStringConverter.h"
28#include "OgreParticle.h"
29
30
31namespace Ogre {
32   
33    // init statics
34        RotationAffector::CmdRotationSpeedRangeStart    RotationAffector::msRotationSpeedRangeStartCmd;
35    RotationAffector::CmdRotationSpeedRangeEnd          RotationAffector::msRotationSpeedRangeEndCmd;
36    RotationAffector::CmdRotationRangeStart                     RotationAffector::msRotationRangeStartCmd;
37    RotationAffector::CmdRotationRangeEnd                       RotationAffector::msRotationRangeEndCmd;
38   
39    //-----------------------------------------------------------------------
40        RotationAffector::RotationAffector(ParticleSystem* psys) :
41        ParticleAffector(psys),
42                mRotationSpeedRangeStart(0),
43                mRotationSpeedRangeEnd(0),
44                mRotationRangeStart(0),
45                mRotationRangeEnd(0)
46    {
47                mType = "Rotator";
48
49        // Init parameters
50        if (createParamDictionary("RotationAffector"))
51        {
52            ParamDictionary* dict = getParamDictionary();
53
54            dict->addParameter(ParameterDef("rotation_speed_range_start",
55                                "The start of a range of rotation speed to be assigned to emitted particles.", PT_REAL),
56                                &msRotationSpeedRangeStartCmd);
57
58                        dict->addParameter(ParameterDef("rotation_speed_range_end",
59                                "The end of a range of rotation speed to be assigned to emitted particles.", PT_REAL),
60                                &msRotationSpeedRangeEndCmd);
61
62                        dict->addParameter(ParameterDef("rotation_range_start",
63                                "The start of a range of rotation angles to be assigned to emitted particles.", PT_REAL),
64                                &msRotationRangeStartCmd);
65
66                        dict->addParameter(ParameterDef("rotation_range_end",
67                                "The end of a range of rotation angles to be assigned to emitted particles.", PT_REAL),
68                                &msRotationRangeEndCmd);
69        }
70    }
71
72    //-----------------------------------------------------------------------
73        void RotationAffector::_initParticle(Particle* pParticle)
74        {
75                pParticle->setRotation(
76            mRotationRangeStart +
77            (Math::UnitRandom() *
78                (mRotationRangeEnd - mRotationRangeStart)));
79        pParticle->rotationSpeed =
80            mRotationSpeedRangeStart +
81            (Math::UnitRandom() *
82                (mRotationSpeedRangeEnd - mRotationSpeedRangeStart));
83       
84        }
85        //-----------------------------------------------------------------------
86    void RotationAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
87    {
88        ParticleIterator pi = pSystem->_getIterator();
89        Particle *p;
90        Real ds;
91
92        // Rotation adjustments by time
93        ds = timeElapsed;
94
95                Radian NewRotation;
96
97        while (!pi.end())
98        {
99            p = pi.getNext();
100
101                        NewRotation = p->rotation + (ds * p->rotationSpeed);
102                        p->setRotation( NewRotation );
103        }
104
105    }
106    //-----------------------------------------------------------------------
107    const Radian& RotationAffector::getRotationSpeedRangeStart(void) const
108    {
109        return mRotationSpeedRangeStart;
110    }
111    //-----------------------------------------------------------------------
112    const Radian& RotationAffector::getRotationSpeedRangeEnd(void) const
113    {
114        return mRotationSpeedRangeEnd;
115    }
116    //-----------------------------------------------------------------------
117    void RotationAffector::setRotationSpeedRangeStart(const Radian& val)
118    {
119        mRotationSpeedRangeStart = val;
120    }
121    //-----------------------------------------------------------------------
122    void RotationAffector::setRotationSpeedRangeEnd(const Radian& val )
123    {
124        mRotationSpeedRangeEnd = val;
125    }
126    //-----------------------------------------------------------------------
127    const Radian& RotationAffector::getRotationRangeStart(void) const
128    {
129        return mRotationRangeStart;
130    }
131    //-----------------------------------------------------------------------
132    const Radian& RotationAffector::getRotationRangeEnd(void) const
133    {
134        return mRotationRangeEnd;
135    }
136    //-----------------------------------------------------------------------
137    void RotationAffector::setRotationRangeStart(const Radian& val)
138    {
139        mRotationRangeStart = val;
140    }
141    //-----------------------------------------------------------------------
142    void RotationAffector::setRotationRangeEnd(const Radian& val )
143    {
144        mRotationRangeEnd = val;
145    }
146        //-----------------------------------------------------------------------
147
148    //-----------------------------------------------------------------------
149    //-----------------------------------------------------------------------
150    // Command objects
151    //-----------------------------------------------------------------------
152    //-----------------------------------------------------------------------
153    String RotationAffector::CmdRotationSpeedRangeEnd::doGet(const void* target) const
154    {
155        return StringConverter::toString(
156            static_cast<const RotationAffector*>(target)->getRotationSpeedRangeEnd() );
157    }
158    void RotationAffector::CmdRotationSpeedRangeEnd::doSet(void* target, const String& val)
159    {
160        static_cast<RotationAffector*>(target)->setRotationSpeedRangeEnd(StringConverter::parseAngle(val));
161    }
162    //-----------------------------------------------------------------------
163    String RotationAffector::CmdRotationSpeedRangeStart::doGet(const void* target) const
164    {
165        return StringConverter::toString(
166            static_cast<const RotationAffector*>(target)->getRotationSpeedRangeStart() );
167    }
168    void RotationAffector::CmdRotationSpeedRangeStart::doSet(void* target, const String& val)
169    {
170        static_cast<RotationAffector*>(target)->setRotationSpeedRangeStart(StringConverter::parseAngle(val));
171    }
172   
173        //-----------------------------------------------------------------------
174    String RotationAffector::CmdRotationRangeEnd::doGet(const void* target) const
175    {
176        return StringConverter::toString(
177            static_cast<const RotationAffector*>(target)->getRotationRangeEnd() );
178    }
179    void RotationAffector::CmdRotationRangeEnd::doSet(void* target, const String& val)
180    {
181        static_cast<RotationAffector*>(target)->setRotationRangeEnd(StringConverter::parseAngle(val));
182    }
183    //-----------------------------------------------------------------------
184    String RotationAffector::CmdRotationRangeStart::doGet(const void* target) const
185    {
186        return StringConverter::toString(
187            static_cast<const RotationAffector*>(target)->getRotationRangeStart() );
188    }
189    void RotationAffector::CmdRotationRangeStart::doSet(void* target, const String& val)
190    {
191        static_cast<RotationAffector*>(target)->setRotationRangeStart(StringConverter::parseAngle(val));
192    }
193}
194
195
196
Note: See TracBrowser for help on using the repository browser.