Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreRotationAffector.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreRotationAffector.h"
    00026 #include "OgreParticleSystem.h"
    00027 #include "OgreStringConverter.h"
    00028 #include "OgreParticle.h"
    00029
    00030
    00031 namespace Ogre {
    00032
    00033     // init statics
    00034     RotationAffector::CmdRotationSpeedRangeStart    RotationAffector::msRotationSpeedRangeStartCmd;
    00035     RotationAffector::CmdRotationSpeedRangeEnd      RotationAffector::msRotationSpeedRangeEndCmd;
    00036     RotationAffector::CmdRotationRangeStart         RotationAffector::msRotationRangeStartCmd;
    00037     RotationAffector::CmdRotationRangeEnd           RotationAffector::msRotationRangeEndCmd;
    00038
    00039     //-----------------------------------------------------------------------
    00040     RotationAffector::RotationAffector() :
    00041         mRotationSpeedRangeStart(0),
    00042         mRotationSpeedRangeEnd(0),
    00043         mRotationRangeStart(0),
    00044         mRotationRangeEnd(0)
    00045     {
    00046         mType = "Rotator";
    00047
    00048         // Init parameters
    00049         if (createParamDictionary("RotationAffector"))
    00050         {
    00051             ParamDictionary* dict = getParamDictionary();
    00052
    00053             dict->addParameter(ParameterDef("rotation_speed_range_start",
    00054                 "The start of a range of rotation speed to be assigned to emitted particles.", PT_REAL),
    00055                 &msRotationSpeedRangeStartCmd);
    00056
    00057             dict->addParameter(ParameterDef("rotation_speed_range_end",
    00058                 "The end of a range of rotation speed to be assigned to emitted particles.", PT_REAL),
    00059                 &msRotationSpeedRangeEndCmd);
    00060
    00061             dict->addParameter(ParameterDef("rotation_range_start",
    00062                 "The start of a range of rotation angles to be assigned to emitted particles.", PT_REAL),
    00063                 &msRotationRangeStartCmd);
    00064
    00065             dict->addParameter(ParameterDef("rotation_range_end",
    00066                 "The end of a range of rotation angles to be assigned to emitted particles.", PT_REAL),
    00067                 &msRotationRangeEndCmd);
    00068         }
    00069     }
    00070
    00071     //-----------------------------------------------------------------------
    00072     void RotationAffector::_initParticle(Particle* pParticle)
    00073     {
    00074         pParticle->setRotation(
    00075             mRotationRangeStart +
    00076             (Math::UnitRandom() *
    00077                 (mRotationRangeEnd - mRotationRangeStart)));
    00078         pParticle->setRotationSpeed(
    00079             mRotationSpeedRangeStart +
    00080             (Math::UnitRandom() *
    00081                 (mRotationSpeedRangeEnd - mRotationSpeedRangeStart)));
    00082
    00083     }
    00084     //-----------------------------------------------------------------------
    00085     void RotationAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
    00086     {
    00087         ParticleIterator pi = pSystem->_getIterator();
    00088         Particle *p;
    00089         Real ds;
    00090
    00091         // Rotation adjustments by time
    00092         ds = timeElapsed;
    00093
    00094         Radian NewRotation;
    00095
    00096         while (!pi.end())
    00097         {
    00098             p = pi.getNext();
    00099
    00100             NewRotation = p->getRotation() + (ds * p->getRotationSpeed());
    00101             p->setRotation( NewRotation );
    00102         }
    00103
    00104     }
    00105     //-----------------------------------------------------------------------
    00106     const Radian& RotationAffector::getRotationSpeedRangeStart(void) const
    00107     {
    00108         return mRotationSpeedRangeStart;
    00109     }
    00110     //-----------------------------------------------------------------------
    00111     const Radian& RotationAffector::getRotationSpeedRangeEnd(void) const
    00112     {
    00113         return mRotationSpeedRangeEnd;
    00114     }
    00115     //-----------------------------------------------------------------------
    00116     void RotationAffector::setRotationSpeedRangeStart(const Radian& val)
    00117     {
    00118         mRotationSpeedRangeStart = val;
    00119     }
    00120     //-----------------------------------------------------------------------
    00121     void RotationAffector::setRotationSpeedRangeEnd(const Radian& val )
    00122     {
    00123         mRotationSpeedRangeEnd = val;
    00124     }
    00125     //-----------------------------------------------------------------------
    00126     const Radian& RotationAffector::getRotationRangeStart(void) const
    00127     {
    00128         return mRotationRangeStart;
    00129     }
    00130     //-----------------------------------------------------------------------
    00131     const Radian& RotationAffector::getRotationRangeEnd(void) const
    00132     {
    00133         return mRotationRangeEnd;
    00134     }
    00135     //-----------------------------------------------------------------------
    00136     void RotationAffector::setRotationRangeStart(const Radian& val)
    00137     {
    00138         mRotationRangeStart = val;
    00139     }
    00140     //-----------------------------------------------------------------------
    00141     void RotationAffector::setRotationRangeEnd(const Radian& val )
    00142     {
    00143         mRotationRangeEnd = val;
    00144     }
    00145     //-----------------------------------------------------------------------
    00146
    00147     //-----------------------------------------------------------------------
    00148     //-----------------------------------------------------------------------
    00149     // Command objects
    00150     //-----------------------------------------------------------------------
    00151     //-----------------------------------------------------------------------
    00152     String RotationAffector::CmdRotationSpeedRangeEnd::doGet(const void* target) const
    00153     {
    00154         return StringConverter::toString(
    00155             static_cast<const RotationAffector*>(target)->getRotationSpeedRangeEnd() );
    00156     }
    00157     void RotationAffector::CmdRotationSpeedRangeEnd::doSet(void* target, const String& val)
    00158     {
    00159         static_cast<RotationAffector*>(target)->setRotationSpeedRangeEnd(StringConverter::parseAngle(val));
    00160     }
    00161     //-----------------------------------------------------------------------
    00162     String RotationAffector::CmdRotationSpeedRangeStart::doGet(const void* target) const
    00163     {
    00164         return StringConverter::toString(
    00165             static_cast<const RotationAffector*>(target)->getRotationSpeedRangeStart() );
    00166     }
    00167     void RotationAffector::CmdRotationSpeedRangeStart::doSet(void* target, const String& val)
    00168     {
    00169         static_cast<RotationAffector*>(target)->setRotationSpeedRangeStart(StringConverter::parseAngle(val));
    00170     }
    00171
    00172     //-----------------------------------------------------------------------
    00173     String RotationAffector::CmdRotationRangeEnd::doGet(const void* target) const
    00174     {
    00175         return StringConverter::toString(
    00176             static_cast<const RotationAffector*>(target)->getRotationRangeEnd() );
    00177     }
    00178     void RotationAffector::CmdRotationRangeEnd::doSet(void* target, const String& val)
    00179     {
    00180         static_cast<RotationAffector*>(target)->setRotationRangeEnd(StringConverter::parseAngle(val));
    00181     }
    00182     //-----------------------------------------------------------------------
    00183     String RotationAffector::CmdRotationRangeStart::doGet(const void* target) const
    00184     {
    00185         return StringConverter::toString(
    00186             static_cast<const RotationAffector*>(target)->getRotationRangeStart() );
    00187     }
    00188     void RotationAffector::CmdRotationRangeStart::doSet(void* target, const String& val)
    00189     {
    00190         static_cast<RotationAffector*>(target)->setRotationRangeStart(StringConverter::parseAngle(val));
    00191     }
    00192 }
    00193
    00194
    00195

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:43 2004