[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 "OgreDirectionRandomiserAffector.h" |
---|
| 30 | #include "OgreParticleSystem.h" |
---|
| 31 | #include "OgreParticle.h" |
---|
| 32 | #include "OgreStringConverter.h" |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | namespace Ogre { |
---|
| 36 | |
---|
| 37 | // Instantiate statics |
---|
| 38 | DirectionRandomiserAffector::CmdRandomness DirectionRandomiserAffector::msRandomnessCmd; |
---|
| 39 | DirectionRandomiserAffector::CmdScope DirectionRandomiserAffector::msScopeCmd; |
---|
| 40 | DirectionRandomiserAffector::CmdKeepVelocity DirectionRandomiserAffector::msKeepVelocityCmd; |
---|
| 41 | |
---|
| 42 | //----------------------------------------------------------------------- |
---|
| 43 | DirectionRandomiserAffector::DirectionRandomiserAffector(ParticleSystem* psys) |
---|
| 44 | : ParticleAffector(psys) |
---|
| 45 | { |
---|
| 46 | mType = "DirectionRandomiser"; |
---|
| 47 | |
---|
| 48 | // defaults |
---|
| 49 | mRandomness = 1.0; |
---|
| 50 | mScope = 1.0; |
---|
| 51 | mKeepVelocity = false; |
---|
| 52 | |
---|
| 53 | // Set up parameters |
---|
| 54 | if (createParamDictionary("DirectionRandomiserAffector")) |
---|
| 55 | { |
---|
| 56 | addBaseParameters(); |
---|
| 57 | // Add extra paramaters |
---|
| 58 | ParamDictionary* dict = getParamDictionary(); |
---|
| 59 | dict->addParameter(ParameterDef("randomness", |
---|
| 60 | "The amount of randomness (chaos) to apply to the particle movement.", |
---|
| 61 | PT_REAL), &msRandomnessCmd); |
---|
| 62 | dict->addParameter(ParameterDef("scope", |
---|
| 63 | "The percentage of particles which is affected.", |
---|
| 64 | PT_REAL), &msScopeCmd); |
---|
| 65 | dict->addParameter(ParameterDef("keep_velocity", |
---|
| 66 | "Detemines whether the velocity of the particles is changed.", |
---|
| 67 | PT_BOOL), &msKeepVelocityCmd); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | //----------------------------------------------------------------------- |
---|
| 71 | void DirectionRandomiserAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed) |
---|
| 72 | { |
---|
| 73 | ParticleIterator pi = pSystem->_getIterator(); |
---|
| 74 | Particle *p; |
---|
| 75 | Real length; |
---|
| 76 | |
---|
| 77 | while (!pi.end()) |
---|
| 78 | { |
---|
| 79 | p = pi.getNext(); |
---|
| 80 | if (mScope > Math::UnitRandom()) |
---|
| 81 | { |
---|
| 82 | if (!p->direction.isZeroLength()) |
---|
| 83 | { |
---|
| 84 | if (mKeepVelocity) |
---|
| 85 | { |
---|
| 86 | length = p->direction.length(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | p->direction += Vector3(Math::RangeRandom(-mRandomness, mRandomness) * timeElapsed, |
---|
| 90 | Math::RangeRandom(-mRandomness, mRandomness) * timeElapsed, |
---|
| 91 | Math::RangeRandom(-mRandomness, mRandomness) * timeElapsed); |
---|
| 92 | |
---|
| 93 | if (mKeepVelocity) |
---|
| 94 | { |
---|
| 95 | p->direction *= length / p->direction.length(); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | //----------------------------------------------------------------------- |
---|
| 102 | void DirectionRandomiserAffector::setRandomness(Real force) |
---|
| 103 | { |
---|
| 104 | mRandomness = force; |
---|
| 105 | } |
---|
| 106 | //----------------------------------------------------------------------- |
---|
| 107 | void DirectionRandomiserAffector::setScope(Real scope) |
---|
| 108 | { |
---|
| 109 | mScope = scope; |
---|
| 110 | } |
---|
| 111 | //----------------------------------------------------------------------- |
---|
| 112 | void DirectionRandomiserAffector::setKeepVelocity(bool keepVelocity) |
---|
| 113 | { |
---|
| 114 | mKeepVelocity = keepVelocity; |
---|
| 115 | } |
---|
| 116 | //----------------------------------------------------------------------- |
---|
| 117 | Real DirectionRandomiserAffector::getRandomness(void) const |
---|
| 118 | { |
---|
| 119 | return mRandomness; |
---|
| 120 | } |
---|
| 121 | //----------------------------------------------------------------------- |
---|
| 122 | Real DirectionRandomiserAffector::getScope(void) const |
---|
| 123 | { |
---|
| 124 | return mScope; |
---|
| 125 | } |
---|
| 126 | //----------------------------------------------------------------------- |
---|
| 127 | bool DirectionRandomiserAffector::getKeepVelocity(void) const |
---|
| 128 | { |
---|
| 129 | return mKeepVelocity; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | //----------------------------------------------------------------------- |
---|
| 133 | //----------------------------------------------------------------------- |
---|
| 134 | // Command objects |
---|
| 135 | //----------------------------------------------------------------------- |
---|
| 136 | //----------------------------------------------------------------------- |
---|
| 137 | String DirectionRandomiserAffector::CmdRandomness::doGet(const void* target) const |
---|
| 138 | { |
---|
| 139 | return StringConverter::toString( |
---|
| 140 | static_cast<const DirectionRandomiserAffector*>(target)->getRandomness() ); |
---|
| 141 | } |
---|
| 142 | void DirectionRandomiserAffector::CmdRandomness::doSet(void* target, const String& val) |
---|
| 143 | { |
---|
| 144 | static_cast<DirectionRandomiserAffector*>(target)->setRandomness(StringConverter::parseReal(val)); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | String DirectionRandomiserAffector::CmdScope::doGet(const void* target) const |
---|
| 148 | { |
---|
| 149 | return StringConverter::toString( |
---|
| 150 | static_cast<const DirectionRandomiserAffector*>(target)->getScope() ); |
---|
| 151 | } |
---|
| 152 | void DirectionRandomiserAffector::CmdScope::doSet(void* target, const String& val) |
---|
| 153 | { |
---|
| 154 | static_cast<DirectionRandomiserAffector*>(target)->setScope(StringConverter::parseReal(val)); |
---|
| 155 | } |
---|
| 156 | String DirectionRandomiserAffector::CmdKeepVelocity::doGet(const void* target) const |
---|
| 157 | { |
---|
| 158 | return StringConverter::toString( |
---|
| 159 | static_cast<const DirectionRandomiserAffector*>(target)->getKeepVelocity() ); |
---|
| 160 | } |
---|
| 161 | void DirectionRandomiserAffector::CmdKeepVelocity::doSet(void* target, const String& val) |
---|
| 162 | { |
---|
| 163 | static_cast<DirectionRandomiserAffector*>(target)->setKeepVelocity(StringConverter::parseBool(val)); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | } |
---|