Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

# ExCParticule.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExCParticule.cpp,v 1.25 2002/12/08 17:57:07 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCParticule.h"
    00025
    00026 ExCParticule::ExCParticule(void)
    00027 {
    00028 Guard(ExCParticule::ExCParticule(void))
    00029         m_LifeSpan=1000;
    00030         m_Size=0.6;
    00031         m_Weight=1;
    00032         m_Mass=1;
    00033         m_Type=PARTICULE_LINE;
    00034         m_ColorR=255;
    00035         m_ColorG=255;
    00036         m_ColorB=255;
    00037         m_Velocity.SetValue(0.0f,0.1f,0.0f);
    00038         m_Position.SetValue(0.0f,0.0f,0.0f);
    00039         m_Acceleration.SetValue(1.0f,1.0f,1.0f);
    00040         m_Gravity.SetValue(0.0f,0.0f,0.0f);
    00041         SetName("ExCParticule");
    00042         SetType(typeid(this).name());
    00043         m_Growth=100;//in %
    00044         m_CollisionSphere.m_Radius=m_Weight;
    00045
    00046         m_Rotation=5;
    00047
    00048         char *ext = (char*)glGetString( GL_EXTENSIONS );
    00049
    00050         if( strstr( ext, "GL_EXT_point_parameters" ) == NULL )
    00051         {
    00052                 std::cout<<"GL_EXT_point_parameters extension was not found"<<std::endl;
    00053                 return;
    00054         }
    00055         else
    00056         {
    00057         glPointParameterfEXT  = (PFNGLPOINTPARAMETERFEXTPROC)wglGetProcAddress("glPointParameterfEXT");
    00058         glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)wglGetProcAddress("glPointParameterfvEXT");
    00059
    00060                 if( !glPointParameterfEXT || !glPointParameterfvEXT )
    00061                 {
    00062                         std::cout<<"One or more GL_EXT_point_parameters functions were not found"<<std::endl;
    00063                         return;
    00064                 }
    00065         }
    00066
    00067     if( strstr( ext, "GL_NV_point_sprite" ) == NULL )
    00068         {
    00069                 std::cout<<"GL_NV_point_sprite extension was not found"<<std::endl;
    00070                 return;
    00071         }
    00072         else
    00073         {
    00074         glPointParameteriNV   = (PFNGLPOINTPARAMETERINVPROC)wglGetProcAddress("glPointParameteriNV");
    00075         glPointParameterivNV  = (PFNGLPOINTPARAMETERIVNVPROC)wglGetProcAddress("glPointParameterivNV");
    00076
    00077                 if( !glPointParameteriNV  || !glPointParameterivNV )
    00078                 {
    00079                         std::cout<<"One or more GL_NV_point_sprite functions were not found"<<std::endl;
    00080                         return;
    00081                 }
    00082         }
    00083 UnGuard
    00084 }
    00085 /*
    00086 ExCParticule::ExCParticule(const ExCParticule &Particule)
    00087 {
    00088 Guard(ExCParticule::ExCParticule(const ExCParticule &Particule))
    00089         m_LifeSpan=Particule.m_LifeSpan;
    00090         m_Size=Particule.m_Size;
    00091         m_Weight=Particule.m_Weight;
    00092         m_Mass=Particule.m_Mass;
    00093         m_Type=Particule.m_Type;
    00094         m_ColorR=Particule.m_ColorR;
    00095         m_ColorG=Particule.m_ColorG;
    00096         m_ColorB=Particule.m_ColorB;
    00097         m_Velocity=Particule.m_Velocity;
    00098         m_Position=Particule.m_Position;
    00099         m_Acceleration=Particule.m_Acceleration;
    00100         m_Gravity=Particule.m_Gravity;
    00101         m_Growth=Particule.m_Growth;//in %
    00102         SetName(Particule.m_ObjectName);
    00103         SetType(Particule.m_ObjectType);
    00104         m_VecPosition=Particule.m_VecPosition;
    00105         m_CollisionSphere.m_Radius=Particule.m_Weight;
    00106
    00107 UnGuard
    00108 }*/
    00109
    00110 ExCParticule::~ExCParticule(void)
    00111 {
    00112 Guard(ExCParticule::~ExCParticule(void))
    00113 UnGuard
    00114 }
    00115
    00116
    00117 void ExCParticule::SetParticuleType(int type)
    00118 {
    00119 Guard(void ExCParticule::SetParticuleType(int type))
    00120         m_Type=type;
    00121         if(m_Type>4)m_Type=1;
    00122 UnGuard
    00123 }
    00124
    00125
    00126 void ExCParticule::Draw(void)
    00127 {
    00128 Guard(void ExCParticule::Draw(void))
    00129
    00130         float final,pas,current;
    00131
    00132         float x,y,z,x1,y1,z1;
    00133         float GravityX,GravityY,GravityZ;
    00134         int TimeNow=(m_TotalLife-m_LifeSpan);
    00135
    00136         final=((float)m_Size/100)*m_Growth;
    00137         pas=(float)(final-m_Size)/m_TotalLife;
    00138         current=m_Size+(TimeNow*pas);
    00139
    00140         if(TimeNow>=m_TotalLife){return;}
    00141
    00142         float quadratic[] =  { 1.0f, 1.0f, 1.0f };
    00143         float maxSize = 0.0f;
    00144         ExCVec3D v1,v2,v3,v4,up,right,CollisionResult;
    00145         GLfloat viewMatrix[16];
    00146
    00147         switch(m_Type)
    00148         {
    00149         case PARTICULE_POINT:
    00150                 glPushMatrix();
    00151                         glTranslatef(m_Position.m_Vector[0],m_Position.m_Vector[1],m_Position.m_Vector[2]);
    00152                         m_Position=m_Position+m_Velocity;
    00153                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00154                         glBegin(GL_POINT);
    00155                                 glVertex3fv(m_Position.m_Vector);
    00156                         glEnd();
    00157                 glPopMatrix();
    00158                 break;
    00159
    00160         case PARTICULE_LINE:
    00161                 GravityX=((TimeNow*TimeNow)*(m_Gravity.m_Vector[0])/20);
    00162                 GravityY=((TimeNow*TimeNow)*(m_Gravity.m_Vector[1])/20);
    00163                 GravityZ=((TimeNow*TimeNow)*(m_Gravity.m_Vector[2])/20);
    00164
    00165                 x=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*TimeNow)-GravityX;
    00166                 y=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*TimeNow)-GravityY;
    00167                 z=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*TimeNow)-GravityZ;
    00168
    00169                 x1=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*(TimeNow+current))-GravityX;
    00170                 y1=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*(TimeNow+current))-GravityY;
    00171                 z1=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*(TimeNow+current))-GravityZ;
    00172
    00173                 glPushMatrix();
    00174                 //glPushAttrib(GL_ALL_ATTRIB_BITS);
    00175                         glTranslatef(x,y,z);
    00176                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00177                         glDisable(GL_LIGHTING);
    00178                         glEnable(GL_BLEND);
    00179                         glEnable(GL_ALPHA);
    00180                         glBlendFunc(GL_ONE,GL_ONE);
    00181                         glEnable(GL_ALPHA_TEST);
    00182                         glAlphaFunc(GL_GREATER,0);
    00183                         glLineWidth(2.0f);
    00184                         glBegin(GL_LINES);
    00185                                 glVertex3f(x,y,z);
    00186                                 glVertex3f(x1,y1,z1);
    00187                         glEnd();
    00188                 //glPopAttrib();
    00189                 glPopMatrix();
    00190                 break;
    00191
    00192         case PARTICULE_TEXTURE:
    00193                 glPushMatrix();
    00194                 //glPushAttrib(GL_ALL_ATTRIB_BITS);
    00195                         m_Position=m_VecPosition.at(TimeNow);
    00196                         //CollisionResult=ManagerCollision->OneTestCollision(this);
    00197                         //if(CollisionResult.GetX()!=0)
    00198                         //{
    00199                         //      glColor3f(1,0,0);
    00200                         //      m_Position=m_OldPosition;
    00201                         //}
    00202
    00203
    00204                         glTranslatef(m_Position.m_Vector[0],m_Position.m_Vector[1],m_Position.m_Vector[2]);
    00205                         m_CollisionSphere.m_Radius=current;
    00206                         glLineWidth(0.2);
    00207
    00208                         glMatrixMode(GL_TEXTURE);
    00209                                 glRotatef(m_Rotation,0,0,1);
    00210                                 m_Rotation+=m_Rotation;
    00211                         glMatrixMode(GL_MODELVIEW);
    00212
    00213                         //m_CollisionSphere.Draw();
    00214
    00215                         // Orienation of particule
    00216
    00217                         glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
    00218
    00219                         right.SetValue(viewMatrix[0],viewMatrix[4],viewMatrix[8]);
    00220                         up.SetValue(viewMatrix[1],viewMatrix[5],viewMatrix[9]);
    00221
    00222
    00223                         v1=m_Position+(right+up)*-current;
    00224                         v2=m_Position+(right-up)*current;
    00225                         v3=m_Position+(right+up)*current;
    00226                         v4=m_Position+(up-right)*current;
    00227
    00228                         glEnable(GL_BLEND);
    00229                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    00230                         glEnable(GL_TEXTURE_2D);
    00231                         glDisable(GL_LIGHTING);
    00232                         glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
    00233                         glBindTexture(GL_TEXTURE_2D, m_Texture);
    00234                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00235
    00236
    00237                         glBegin(GL_QUADS);
    00238                                 glTexCoord2f(0.0f, 0.0f); glVertex3fv(v1.m_Vector);
    00239                                 glTexCoord2f(1.0f, 0.0f); glVertex3fv(v2.m_Vector);
    00240                                 glTexCoord2f(1.0f, 1.0f); glVertex3fv(v3.m_Vector);
    00241                                 glTexCoord2f(0.0f, 1.0f); glVertex3fv(v4.m_Vector);
    00242                         glEnd();
    00243
    00244                 //glPopAttrib();
    00245                 glPopMatrix();
    00246
    00247                 glMatrixMode(GL_TEXTURE);
    00248                         glLoadIdentity();
    00249                 glMatrixMode(GL_MODELVIEW);
    00250
    00251                 break;
    00252
    00253         case PARTICULE_TEXTURE_NV:
    00254                 m_Position=m_VecPosition.at(TimeNow);
    00255                 glPushMatrix();
    00256                 glPushAttrib(GL_ALL_ATTRIB_BITS);
    00257                         glEnable( GL_BLEND );
    00258                         glBlendFunc( GL_SRC_ALPHA, GL_ONE );
    00259                         glEnable(GL_TEXTURE_2D);
    00260                         glDisable(GL_LIGHTING);
    00261                         glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
    00262                         //glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
    00263                         glBindTexture(GL_TEXTURE_2D, m_Texture);
    00264
    00265                         glPointParameterfvEXT( GL_DISTANCE_ATTENUATION_EXT, quadratic );
    00266
    00267                         // Query for the max point size supported by the hardware
    00268                         glGetFloatv( GL_POINT_SIZE_MAX_EXT, &maxSize );
    00269                         glPointSize( maxSize );
    00270
    00271                         glPointParameterfEXT( GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1.0f );
    00272
    00273                         glPointParameterfEXT( GL_POINT_SIZE_MIN_EXT, 1.0f );
    00274                         glPointParameterfEXT( GL_POINT_SIZE_MAX_EXT, 2.0f );
    00275
    00276                         // Specify point sprite texture coordinate replacement mode for each texture unit
    00277                         glTexEnvf( GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, GL_TRUE );
    00278
    00279         /*              glPointParameteriNV( GL_POINT_SPRITE_R_MODE_NV, GL_ZERO );
    00280                         glPointParameteriNV( GL_POINT_SPRITE_R_MODE_NV, GL_S );
    00281                         glPointParameteriNV( GL_POINT_SPRITE_R_MODE_NV, GL_R );
    00282 */
    00283                         glEnable( GL_POINT_SPRITE_NV );
    00284
    00285                         glBegin( GL_POINTS );
    00286                         {
    00287                                 glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00288                                 glVertex3fv(m_Position.m_Vector);
    00289                         }
    00290                         glEnd();
    00291                 glPopAttrib();
    00292                 glPopMatrix();
    00293                 break;
    00294         }
    00295         m_OldPosition=m_Position;
    00296 UnGuard
    00297 }
    00298
    00299 void ExCParticule::PrecalculeParticuleTrajectory(int start,int end)
    00300 {
    00301 Guard(void ExCParticule::PrecalculeParticuleTrajectory(int start,int end))
    00302         float GravityX,GravityY,GravityZ;
    00303         ExCVec3D Position;
    00304         for(int i=start;i<end;i++)
    00305         {
    00306                 GravityX=((i*i)*(m_Gravity.m_Vector[0])/2000);
    00307                 GravityY=((i*i)*(m_Gravity.m_Vector[1])/2000);
    00308                 GravityZ=((i*i)*(m_Gravity.m_Vector[2])/2000);
    00309
    00310                 Position.m_Vector[0]=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*i)-GravityX;
    00311                 Position.m_Vector[1]=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*i)-GravityY;
    00312                 Position.m_Vector[2]=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*i)-GravityZ;
    00313                 m_VecPosition.push_back(Position);
    00314         }
    00315 UnGuard
    00316 }
    00317
    00318 void ExCParticule::ApplyForceToParitcule(ExCVec3D force)
    00319 {
    00320 Guard(void ExCParticule::ApplyForceToParitcule(ExCVec3D force))
    00321
    00322 UnGuard
    00323 }
    00324
    00325 ExCVec3D ExCParticule::GetPositionNow(void)
    00326 {
    00327 Guard(ExCVec3D ExCParticule::GetPositionNow(void))
    00328
    00329 return m_VecPosition.at(m_TotalLife-m_LifeSpan);
    00330
    00331 UnGuard
    00332 }