[692] | 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-2005 The OGRE Team
|
---|
| 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 | */
|
---|
| 25 | #include "OgreLinearForceAffector.h"
|
---|
| 26 | #include "OgreParticleSystem.h"
|
---|
| 27 | #include "OgreParticle.h"
|
---|
| 28 | #include "OgreStringConverter.h"
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | namespace Ogre {
|
---|
| 32 |
|
---|
| 33 | // Instantiate statics
|
---|
| 34 | LinearForceAffector::CmdForceVector LinearForceAffector::msForceVectorCmd;
|
---|
| 35 | LinearForceAffector::CmdForceApp LinearForceAffector::msForceAppCmd;
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | //-----------------------------------------------------------------------
|
---|
| 39 | LinearForceAffector::LinearForceAffector(ParticleSystem* psys)
|
---|
| 40 | :ParticleAffector(psys)
|
---|
| 41 | {
|
---|
| 42 | mType = "LinearForce";
|
---|
| 43 |
|
---|
| 44 | // Default to gravity-like
|
---|
| 45 | mForceApplication = FA_ADD;
|
---|
| 46 | mForceVector.x = mForceVector.z = 0;
|
---|
| 47 | mForceVector.y = -100;
|
---|
| 48 |
|
---|
| 49 | // Set up parameters
|
---|
| 50 | if (createParamDictionary("LinearForceAffector"))
|
---|
| 51 | {
|
---|
| 52 | addBaseParameters();
|
---|
| 53 | // Add extra paramaters
|
---|
| 54 | ParamDictionary* dict = getParamDictionary();
|
---|
| 55 | dict->addParameter(ParameterDef("force_vector",
|
---|
| 56 | "The vector representing the force to apply.",
|
---|
| 57 | PT_VECTOR3),&msForceVectorCmd);
|
---|
| 58 | dict->addParameter(ParameterDef("force_application",
|
---|
| 59 | "How to apply the force vector to partices.",
|
---|
| 60 | PT_STRING),&msForceAppCmd);
|
---|
| 61 |
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 | //-----------------------------------------------------------------------
|
---|
| 66 | void LinearForceAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
|
---|
| 67 | {
|
---|
| 68 | ParticleIterator pi = pSystem->_getIterator();
|
---|
| 69 | Particle *p;
|
---|
| 70 |
|
---|
| 71 | Vector3 scaledVector;
|
---|
| 72 |
|
---|
| 73 | // Precalc scaled force for optimisation
|
---|
| 74 | if (mForceApplication == FA_ADD)
|
---|
| 75 | {
|
---|
| 76 | // Scale force by time
|
---|
| 77 | scaledVector = mForceVector * timeElapsed;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | while (!pi.end())
|
---|
| 81 | {
|
---|
| 82 | p = pi.getNext();
|
---|
| 83 | if (mForceApplication == FA_ADD)
|
---|
| 84 | {
|
---|
| 85 | p->direction += scaledVector;
|
---|
| 86 | }
|
---|
| 87 | else // FA_AVERAGE
|
---|
| 88 | {
|
---|
| 89 | p->direction = (p->direction + mForceVector) / 2;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 | //-----------------------------------------------------------------------
|
---|
| 95 | void LinearForceAffector::setForceVector(const Vector3& force)
|
---|
| 96 | {
|
---|
| 97 | mForceVector = force;
|
---|
| 98 | }
|
---|
| 99 | //-----------------------------------------------------------------------
|
---|
| 100 | void LinearForceAffector::setForceApplication(ForceApplication fa)
|
---|
| 101 | {
|
---|
| 102 | mForceApplication = fa;
|
---|
| 103 | }
|
---|
| 104 | //-----------------------------------------------------------------------
|
---|
| 105 | Vector3 LinearForceAffector::getForceVector(void) const
|
---|
| 106 | {
|
---|
| 107 | return mForceVector;
|
---|
| 108 | }
|
---|
| 109 | //-----------------------------------------------------------------------
|
---|
| 110 | LinearForceAffector::ForceApplication LinearForceAffector::getForceApplication(void) const
|
---|
| 111 | {
|
---|
| 112 | return mForceApplication;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | //-----------------------------------------------------------------------
|
---|
| 116 | //-----------------------------------------------------------------------
|
---|
| 117 | // Command objects
|
---|
| 118 | //-----------------------------------------------------------------------
|
---|
| 119 | //-----------------------------------------------------------------------
|
---|
| 120 | String LinearForceAffector::CmdForceVector::doGet(const void* target) const
|
---|
| 121 | {
|
---|
| 122 | return StringConverter::toString(
|
---|
| 123 | static_cast<const LinearForceAffector*>(target)->getForceVector() );
|
---|
| 124 | }
|
---|
| 125 | void LinearForceAffector::CmdForceVector::doSet(void* target, const String& val)
|
---|
| 126 | {
|
---|
| 127 | static_cast<LinearForceAffector*>(target)->setForceVector(
|
---|
| 128 | StringConverter::parseVector3(val));
|
---|
| 129 | }
|
---|
| 130 | //-----------------------------------------------------------------------
|
---|
| 131 | String LinearForceAffector::CmdForceApp::doGet(const void* target) const
|
---|
| 132 | {
|
---|
| 133 | ForceApplication app = static_cast<const LinearForceAffector*>(target)->getForceApplication();
|
---|
| 134 | switch(app)
|
---|
| 135 | {
|
---|
| 136 | case LinearForceAffector::FA_AVERAGE:
|
---|
| 137 | return "average";
|
---|
| 138 | break;
|
---|
| 139 | case LinearForceAffector::FA_ADD:
|
---|
| 140 | return "add";
|
---|
| 141 | break;
|
---|
| 142 | }
|
---|
| 143 | // Compiler nicety
|
---|
| 144 | return "";
|
---|
| 145 | }
|
---|
| 146 | void LinearForceAffector::CmdForceApp::doSet(void* target, const String& val)
|
---|
| 147 | {
|
---|
| 148 | if (val == "average")
|
---|
| 149 | {
|
---|
| 150 | static_cast<LinearForceAffector*>(target)->setForceApplication(FA_AVERAGE);
|
---|
| 151 | }
|
---|
| 152 | else if (val == "add")
|
---|
| 153 | {
|
---|
| 154 | static_cast<LinearForceAffector*>(target)->setForceApplication(FA_ADD);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | }
|
---|
| 160 |
|
---|