AaronCameron.net
Not Left, nor right. Just correct.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 04:06pm
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cLineEmitter.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2003  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "particles/cLineEmitter.h"
00026 #include "particles/cParticle.h"
00027 #include "particles/cParticleSystem.h"
00028 
00029 namespace n2l
00030 {
00031 
00032     /* ************************************************************ */
00033     cLineEmitter::cLineEmitter() :
00034         mParentSystem(0),
00035         mEmissionPerSecond( 100.0f ),
00036         mRemainder(0)
00037     {
00038         mLinePos[0] = tVector3f(0.0f,0.0f,0.0f);
00039         mLinePos[1] = tVector3f(1.0f,1.0f,1.0f);
00040 
00041         mVelocityRange[0] = tVector3f( -1.0f, -1.0f, -1.0f );
00042         mVelocityRange[1] = tVector3f( 1.0f, 1.0f, 1.0f );
00043 
00044         mSizeRange[0] = tVector2f( 0.5, 0.5 );
00045         mSizeRange[1] = tVector2f( 0.25, 0.25 );
00046 
00047         mGrowthRange[0] = tVector2f( -0.25, -0.25 );
00048         mGrowthRange[1] = tVector2f( -0.25, -0.25 );
00049 
00050         mStartColour = cColour( 0.8,0.8,0.8 );
00051         mEndColour = cColour( 0.8,0.8,0.8 );
00052 
00053         mTimeToLive = 6000;
00054     }
00055 
00056 
00057     /* ************************************************************ */
00058     cLineEmitter::~cLineEmitter()
00059     {
00060     }
00061 
00062 
00063     /* ************************************************************ */
00064     void cLineEmitter::update( const tUint iTimePassed )
00065     {
00066         if (!mParentSystem)
00067             throw cBadDataUseException( "cLineEmitter::update",
00068                                         "No parent system to emit into" );
00069         updateInto( iTimePassed, *mParentSystem );
00070 
00071     }
00072 
00073     /* ************************************************************ */
00074     void cLineEmitter::updateInto( const tUint iTimePassed,
00075         cParticleSystem &ioSystem )
00076     {
00077         static const cAutoPtr<const cGLTexture> NoTexture(0);
00078         //      cout << "Update: " << iTimePassed << " passed with " << mRemainder << " oustanding, ";
00079 
00080         // Add to the time already passed
00081         mRemainder += iTimePassed;
00082         
00083         // Find out how many emissions we have in that timeframe
00084         const tUint Emissions = tUint(mRemainder/1000.0f * mEmissionPerSecond);
00085 //      cout << "Dropping " << Emissions << " emissions" << endl;
00086         
00087         // Drop the emissions from the outstanding balance
00088         mRemainder -= tUint(Emissions*(1000.0f/mEmissionPerSecond));
00089         
00090         // Emit whatever we should
00091         for (tUint i=0; i<Emissions; ++i) {
00092             tVector3f newPos( (mLinePos[1]-mLinePos[0])*(n2l::random(100000)/100000.0f) );
00093             newPos += mLinePos[0];
00094             tVector3f newVelo( mVelocityRange[1]-mVelocityRange[0] );
00095             newVelo *= tVector3f(   (n2l::random(10000)/10000.0f),
00096                                     (n2l::random(10000)/10000.0f),
00097                                     (n2l::random(10000)/10000.0f) );
00098             newVelo += mVelocityRange[0];
00099 
00100             tVector2f newSize( mSizeRange[1]-mSizeRange[0] );
00101             newSize *= tVector2f(   (n2l::random(10000)/10000.0f),
00102                                     (n2l::random(10000)/10000.0f) );
00103             newSize += mSizeRange[0];
00104 
00105             // Missing stuff here
00106             
00107             
00108             ioSystem.addParticle(   cParticle(  newPos, newVelo, newSize,
00109                 mGrowthRange[0],
00110                 mStartColour, mEndColour,
00111                 mTimeToLive,
00112                 (mTextures.empty()?NoTexture:mTextures[n2l::random(mTextures.size())]) ) );
00113         } // for each emission
00114     }
00115 
00116 
00117     /* ************************************************************ */
00118     void cLineEmitter::parentSystem( cParticleSystem * const i_ioSystem )
00119     {
00120         mParentSystem = i_ioSystem;
00121     }
00122 
00123 
00124     /* ************************************************************ */
00125     void cLineEmitter::line( const tVector3f & iPosA, const tVector3f & iPosB )
00126     {
00127         mLinePos[0] = iPosA;
00128         mLinePos[1] = iPosB;
00129     }
00130 
00131 
00132     /* ************************************************************ */
00133     void cLineEmitter::addTexture( const cAutoPtr<const cGLTexture> i_iTexture )
00134     {
00135         mTextures.push_back(i_iTexture);
00136     }
00137 
00138 
00139     /* ************************************************************ */
00140     void cLineEmitter::emissionPerSecond( const tFloat iEmissionPerSecond )
00141     {
00142         mEmissionPerSecond = iEmissionPerSecond;
00143     }
00144 
00145     /* ************************************************************ */
00146     void cLineEmitter::size( const tVector2f & iSizeA, const tVector2f & iSizeB )
00147     {
00148         mSizeRange[0] = iSizeA;
00149         mSizeRange[1] = iSizeB;
00150     }
00151 
00152     /* ************************************************************ */
00153     void cLineEmitter::velocity(    const tVector3f & iVelocityA,
00154                                     const tVector3f & iVelocityB )
00155     {
00156         mVelocityRange[0] = iVelocityA;
00157         mVelocityRange[1] = iVelocityB;
00158     }
00159 
00160     /* ************************************************************ */
00161     void cLineEmitter::startEndColours( const cColour & iStartColour,
00162                                         const cColour & iEndColour )
00163     {
00164         mStartColour = iStartColour;
00165         mEndColour = iEndColour;
00166     }
00167 
00168     /* ************************************************************ */
00169     void cLineEmitter::growth(  const tVector2f & iGrowthA,
00170                                 const tVector2f & iGrowthB )
00171     {
00172         mGrowthRange[0] = iGrowthA;
00173         mGrowthRange[1] = iGrowthB;
00174     }
00175 
00176     /* ************************************************************ */
00177     void cLineEmitter::timeToLive( const tUint iTTL )
00178     {
00179         mTimeToLive = iTTL;
00180     }
00181 
00182     /* ************************************************************ */
00183     cParticleSystem * const cLineEmitter::parentSystem()
00184     {
00185         return mParentSystem;
00186     }
00187 
00188 
00189 } // namespace
©2012 Aaron Cameron