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 UnGuard
    00045 }
    00046
    00047 ExCParticule::~ExCParticule(void)
    00048 {
    00049 Guard(ExCParticule::~ExCParticule(void))
    00050 UnGuard
    00051 }
    00052
    00053
    00054 void ExCParticule::SetParticuleType(int type)
    00055 {
    00056 Guard(void ExCParticule::SetParticuleType(int type))
    00057         m_Type=type;
    00058         if(m_Type>3)m_Type=1;
    00059 UnGuard
    00060 }
    00061
    00062
    00063 void ExCParticule::Draw(void)
    00064 {
    00065 Guard(void ExCParticule::Draw(void))
    00066         float final,pas,current;
    00067
    00068         float x,y,z,x1,y1,z1;
    00069         float GravityX,GravityY,GravityZ;
    00070         int TimeNow=(m_TotalLife-m_LifeSpan);
    00071
    00072         final=((float)m_Size/100)*m_Growth;
    00073         pas=(float)(final-m_Size)/m_TotalLife;
    00074         current=m_Size+(TimeNow*pas);
    00075
    00076         if(TimeNow>=m_TotalLife){return;}
    00077
    00078         switch(m_Type)
    00079         {
    00080         case PARTICULE_POINT:
    00081                 glPushMatrix();
    00082                         glTranslatef(m_Position.m_Vector[0],m_Position.m_Vector[1],m_Position.m_Vector[2]);
    00083                         m_Position=m_Position+m_Velocity;
    00084                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00085                         glBegin(GL_POINT);
    00086                                 glVertex3fv(m_Position.m_Vector);
    00087                         glEnd();
    00088                 glPopMatrix();
    00089                 break;
    00090
    00091         case PARTICULE_LINE:
    00092                 GravityX=((TimeNow*TimeNow)*(m_Gravity.m_Vector[0])/20);
    00093                 GravityY=((TimeNow*TimeNow)*(m_Gravity.m_Vector[1])/20);
    00094                 GravityZ=((TimeNow*TimeNow)*(m_Gravity.m_Vector[2])/20);
    00095
    00096                 x=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*TimeNow)-GravityX;
    00097                 y=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*TimeNow)-GravityY;
    00098                 z=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*TimeNow)-GravityZ;
    00099
    00100                 x1=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*(TimeNow+current))-GravityX;
    00101                 y1=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*(TimeNow+current))-GravityY;
    00102                 z1=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*(TimeNow+current))-GravityZ;
    00103
    00104                 glPushMatrix();
    00105                 glPushAttrib(GL_ALL_ATTRIB_BITS);
    00106                         glTranslatef(x,y,z);
    00107                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00108                         glDisable(GL_LIGHTING);
    00109                         glEnable(GL_BLEND);
    00110                         glEnable(GL_ALPHA);
    00111                         glBlendFunc(GL_ONE,GL_ONE);
    00112                         glEnable(GL_ALPHA_TEST);
    00113                         glAlphaFunc(GL_GREATER,0);
    00114                         glLineWidth(2.0f);
    00115                         glBegin(GL_LINES);
    00116                                 glVertex3f(x,y,z);
    00117                                 glVertex3f(x1,y1,z1);
    00118                         glEnd();
    00119                 glPopAttrib();
    00120                 glPopMatrix();
    00121                 break;
    00122
    00123         case PARTICULE_TEXTURE:
    00124                 glPushMatrix();
    00125                 glPushAttrib(GL_ALL_ATTRIB_BITS);
    00126                         ExCVec3D position;
    00127
    00128                         position=m_VecPosition.at(TimeNow);
    00129                         glTranslatef(position.m_Vector[0],position.m_Vector[1],position.m_Vector[2]);
    00130                         // Orienation of particule
    00131                         GLfloat viewMatrix[16];
    00132                         glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
    00133                         ExCVec3D right;
    00134                         ExCVec3D up;
    00135
    00136                         right.SetValue(viewMatrix[0],viewMatrix[4],viewMatrix[8]);
    00137                         up.SetValue(viewMatrix[1],viewMatrix[5],viewMatrix[9]);
    00138
    00139                         ExCVec3D v1,v2,v3,v4;
    00140                         v1=m_Position+(right+up)*-current;
    00141                         v2=m_Position+(right-up)*current;
    00142                         v3=m_Position+(right+up)*current;
    00143                         v4=m_Position+(up-right)*current;
    00144
    00145                         glEnable(GL_BLEND);
    00146                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    00147                         glEnable(GL_TEXTURE_2D);
    00148                         glDisable(GL_LIGHTING);
    00149                         glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
    00150                         glBindTexture(GL_TEXTURE_2D, m_Texture);
    00151                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00152                         glBegin(GL_QUADS);
    00153                                 glTexCoord2f(0.0f, 0.0f); glVertex3fv(v1.m_Vector);
    00154                                 glTexCoord2f(1.0f, 0.0f); glVertex3fv(v2.m_Vector);
    00155                                 glTexCoord2f(1.0f, 1.0f); glVertex3fv(v3.m_Vector);
    00156                                 glTexCoord2f(0.0f, 1.0f); glVertex3fv(v4.m_Vector);
    00157                         glEnd();
    00158
    00159                 glPopAttrib();
    00160                 glPopMatrix();
    00161                 break;
    00162         }
    00163
    00164 UnGuard
    00165 }
    00166
    00167 void ExCParticule::PrecalculeParticuleTrajectory(int start,int end)
    00168 {
    00169 Guard(void ExCParticule::PrecalculeParticuleTrajectory(int start,int end))
    00170         float GravityX,GravityY,GravityZ;
    00171         ExCVec3D Position;
    00172         for(int i=start;i<end;i++)
    00173         {
    00174                 GravityX=((i*i)*(m_Gravity.m_Vector[0])/2000);
    00175                 GravityY=((i*i)*(m_Gravity.m_Vector[1])/2000);
    00176                 GravityZ=((i*i)*(m_Gravity.m_Vector[2])/2000);
    00177
    00178                 Position.m_Vector[0]=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*i)-GravityX;
    00179                 Position.m_Vector[1]=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*i)-GravityY;
    00180                 Position.m_Vector[2]=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*i)-GravityZ;
    00181                 m_VecPosition.push_back(Position);
    00182         }
    00183 UnGuard
    00184 }
    00185
    00186 void ExCParticule::ApplyForceToParitcule(ExCVec3D force)
    00187 {
    00188 Guard(void ExCParticule::ApplyForceToParitcule(ExCVec3D force))
    00189
    00190 UnGuard
    00191 }