![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cParticle.cppGo 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/cParticle.h" 00026 00027 #include <GL/gl.h> 00028 00029 #include <iostream> 00030 using namespace std; 00031 00032 namespace n2l 00033 { 00034 const tFloat cParticle::DeathSizeThreashold = 0.01; 00035 00036 /* ************************************************************ */ 00037 cParticle::cParticle() : 00038 mPos( 0.0f,0.0f,0.0f ), 00039 mVelocity( 0.0f,0.0f,0.0f ), 00040 mSize( 1.0f,1.0f ), 00041 mGrowth( 0.0f,0.0f ), 00042 mStartColour( 1.0f,1.0f,1.0f,1.0f ), 00043 mEndColour( 0.0f,0.0f,0.0f,1.0f ), 00044 mColour(), 00045 mTimeAlive(0), 00046 mTimeToLive(0), 00047 mTexture(0) 00048 { 00049 } 00050 00051 /* ************************************************************ */ 00052 cParticle::cParticle( const tVector3f &iPos, 00053 const tVector3f &iVelocity, 00054 const tVector2f &iSize, 00055 const tVector2f &iGrowth, 00056 const cColour &iStartColour, 00057 const cColour &iEndColour, 00058 const tUint iTimeToLive, 00059 const cAutoPtr<const cGLTexture> &iTexture ) : 00060 mPos( iPos ), 00061 mVelocity( iVelocity ), 00062 mSize( iSize ), 00063 mGrowth( iGrowth ), 00064 mStartColour( iStartColour ), 00065 mEndColour( iEndColour ), 00066 mColour( iStartColour ), 00067 mTimeAlive(0), 00068 mTimeToLive( iTimeToLive ), 00069 mTexture( iTexture ) 00070 { 00071 } 00072 00073 /* ************************************************************ */ 00074 const tBool cParticle::alive() const 00075 { 00076 return (mTimeAlive<mTimeToLive && 00077 mSize.x()>DeathSizeThreashold && 00078 mSize.y()>DeathSizeThreashold); 00079 } 00080 00081 /* ************************************************************ */ 00082 void cParticle::update( const tFloat &iSeconds ) 00083 { 00084 mTimeAlive += tUint(iSeconds*1000.0f); 00085 00086 mPos += (mVelocity*iSeconds); 00087 mSize += (mGrowth*iSeconds); 00088 mBoundRadius = n2lMax(mSize.x(),mSize.y()); 00089 00090 mColour = mEndColour; 00091 mColour -= mStartColour; 00092 mColour *= mTimeAlive/tFloat(mTimeToLive); 00093 mColour += mStartColour; 00094 } 00095 00096 00097 /* ************************************************************ */ 00098 void cParticle::draw( const tVector3f &iHalfUpV, 00099 const tVector3f &iHalfRightV ) const 00100 { 00101 // Calculate positions 00102 tVector3f up( iHalfUpV ); 00103 tVector3f right( iHalfRightV ); 00104 00105 right *= mSize.x(); 00106 up *= mSize.y(); 00107 00108 tVector3f left = right; 00109 left *= -1.0f; 00110 00111 tVector3f down = up; 00112 down *= -1.0f; 00113 00114 tVector3f topRight(up+right); 00115 tVector3f topLeft(up+left); 00116 tVector3f bottomRight(down+right); 00117 tVector3f bottomLeft(down+left); 00118 00119 topRight += mPos; 00120 topLeft += mPos; 00121 bottomRight += mPos; 00122 bottomLeft += mPos; 00123 00124 mColour.glColor4fv(); 00125 glBegin( GL_TRIANGLE_STRIP ); 00126 glTexCoord2f( 1.0f, 1.0f ); 00127 topRight.glVertex3f(); 00128 glTexCoord2f( 0.0f, 1.0f ); 00129 topLeft.glVertex3f(); 00130 glTexCoord2f( 1.0f, 0.0f ); 00131 bottomRight.glVertex3f(); 00132 glTexCoord2f( 0.0f, 0.0f ); 00133 bottomLeft.glVertex3f(); 00134 glEnd(); 00135 } 00136 00137 /* ************************************************************ */ 00138 00139 /* ************************************************************ */ 00140 00141 /* ************************************************************ */ 00142 00143 } // namespace |