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