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

# ExCSDKParticule.cpp

Aller à la documentation de ce fichier.

    00001 #include "StdAfx.h"
    00002 #include "excsdkparticule.h"
    00003
    00004 ExCSDKParticule::ExCSDKParticule(void)
    00005 {
    00006         m_LifeSpan=1000;
    00007         m_Size=0.2;
    00008         m_Weight=1;
    00009         m_Mass=1;
    00010         m_Type=PARTICULE_LINE;
    00011         m_ColorR=255;
    00012         m_ColorG=255;
    00013         m_ColorB=255;
    00014         m_Velocity.SetValue(0.0f,0.1f,0.0f);
    00015         m_Position.SetValue(0.0f,0.0f,0.0f);
    00016         m_Acceleration.SetValue(1.0f,1.0f,1.0f);
    00017         m_Gravity.SetValue(0.0f,0.0f,0.0f);
    00018 }
    00019
    00020 ExCSDKParticule::~ExCSDKParticule(void)
    00021 {
    00022 }
    00023
    00024 void ExCSDKParticule::SetParticuleType(int type)
    00025 {
    00026         m_Type=type;
    00027         if(m_Type>3)m_Type=1;
    00028 }
    00029
    00030 void ExCSDKParticule::SetParticuleTexture(int texture)
    00031 {
    00032         m_Texture=texture;
    00033 }
    00034
    00035
    00036 void ExCSDKParticule::Draw(void)
    00037 {
    00038 /*      float x,y,z,x1,y1,z1;
    00039         float GravityX,GravityY,GravityZ;
    00040         int TimeNow=(m_TotalLife-m_LifeSpan);
    00041
    00042         GLfloat no_mat[]                        = {0.0f,0.0f,0.0f,1.0f};
    00043         GLfloat mat_ambient[]           = {0.7f,0.7f,0.7f,1.0f};
    00044         GLfloat mat_ambient_color[] = {0.8f,0.8f,0.2f,1.0f};
    00045         GLfloat mat_diffuse[]           = {0.1f,0.5f,0.8f,1.0f};
    00046         GLfloat mat_specular[]          = {1.0f,1.0f,1.0f,1.0f};
    00047         GLfloat no_shininess[]          = {0.0f};
    00048         GLfloat low_shininess[]         = {5.0f};
    00049         GLfloat high_shininess[]        = {100.0f};
    00050         GLfloat mat_emission[]          = {0.3f,0.2f,0.2f,0.0f};
    00051
    00052         switch(m_Type)
    00053         {
    00054         case PARTICULE_POINT:
    00055
    00056                 glPushMatrix();
    00057
    00058                         glTranslatef(m_Position.m_Vector[0],
    00059                                 m_Position.m_Vector[1],
    00060                                 m_Position.m_Vector[2]);
    00061                         m_Position=m_Position+m_Velocity;
    00062
    00063                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00064                                 glBegin(GL_POINT);
    00065                                         glVertex3fv(m_Position.m_Vector);
    00066                                 glEnd();
    00067                 glPopMatrix();
    00068                 break;
    00069
    00070         case PARTICULE_LINE:
    00071                 glPushMatrix();
    00072
    00073                 GravityX=((TimeNow*TimeNow)*(m_Gravity.m_Vector[0])/20);
    00074                 GravityY=((TimeNow*TimeNow)*(m_Gravity.m_Vector[1])/20);
    00075                 GravityZ=((TimeNow*TimeNow)*(m_Gravity.m_Vector[2])/20);
    00076
    00077                 x=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*TimeNow)-GravityX;
    00078                 y=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*TimeNow)-GravityY;
    00079                 z=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*TimeNow)-GravityZ;
    00080
    00081                 x1=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*(TimeNow+m_Size))-GravityX;
    00082                 y1=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*(TimeNow+m_Size))-GravityY;
    00083                 z1=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*(TimeNow+m_Size))-GravityZ;
    00084
    00085                 glTranslatef(x,y,z);
    00086                 glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00087
    00088                 glEnable(GL_BLEND);
    00089                 glEnable(GL_ALPHA);
    00090                 glBlendFunc(GL_ONE,GL_ONE);
    00091                 glEnable(GL_ALPHA_TEST);
    00092                 glAlphaFunc(GL_GREATER,0);
    00093                 glLineWidth(2.0f);
    00094                 //glEnable(GL_LIGHTING);
    00095
    00096                 glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,no_mat);
    00097                 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
    00098                 glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
    00099                 glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,high_shininess);
    00100                 glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,no_mat);
    00101
    00102                 glBegin(GL_LINES);
    00103                         glVertex3f(x,y,z);
    00104                         glVertex3f(x1,y1,z1);
    00105                 glEnd();
    00106                 glDisable(GL_LIGHTING);
    00107                 glDisable(GL_BLEND);
    00108                 glDisable(GL_ALPHA);
    00109                 glLineWidth(1.5);
    00110                 glPopMatrix();
    00111                 break;
    00112
    00113         case PARTICULE_TEXTURE:
    00114                 glPushMatrix();
    00115                 ExCVec3D position;
    00116                 if(TimeNow<m_TotalLife)
    00117                 {
    00118                         position=m_VecPosition.at(TimeNow);
    00119                         glTranslatef(position.m_Vector[0],position.m_Vector[1],position.m_Vector[2]);
    00120                         // Orienation of particule
    00121                         GLfloat viewMatrix[16];
    00122                         glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
    00123                         ExCVec3D right;
    00124                         ExCVec3D up;
    00125
    00126                         right.SetValue(viewMatrix[0],viewMatrix[4],viewMatrix[8]);
    00127                         up.SetValue(viewMatrix[1],viewMatrix[5],viewMatrix[9]);
    00128
    00129                         ExCVec3D v1,v2,v3,v4;
    00130                         v1=m_Position+(right+up)*-m_Size;
    00131                         v2=m_Position+(right-up)*m_Size;
    00132                         v3=m_Position+(right+up)*m_Size;
    00133                         v4=m_Position+(up-right)*m_Size;
    00134
    00135
    00136                         //DRAW PARTICULE
    00137                         glColor4ub(m_ColorR,m_ColorG,m_ColorB,m_Blending);
    00138                         glEnable(GL_BLEND);
    00139                         glEnable(GL_ALPHA);
    00140                         glEnable(GL_TEXTURE_2D);
    00141                         glBlendFunc(GL_ONE,GL_ONE);
    00142                         glEnable(GL_ALPHA_TEST);
    00143                         glAlphaFunc(GL_GREATER,0);
    00144                         glDisable(GL_LIGHTING);
    00145                         glBindTexture(GL_TEXTURE_2D,m_Texture);
    00146                         glBegin(GL_QUADS);
    00147                                 glTexCoord2f(0.0f, 0.0f); glVertex3fv(v1.m_Vector);
    00148                                 glTexCoord2f(1.0f, 0.0f); glVertex3fv(v2.m_Vector);
    00149                                 glTexCoord2f(1.0f, 1.0f); glVertex3fv(v3.m_Vector);
    00150                                 glTexCoord2f(0.0f, 1.0f); glVertex3fv(v4.m_Vector);
    00151                         glEnd();
    00152                         glDisable(GL_TEXTURE_2D);
    00153                         glDisable(GL_BLEND);
    00154                         glDisable(GL_ALPHA);
    00155                         glEnable(GL_LIGHTING);
    00156                 }
    00157                 glPopMatrix();
    00158                 break;
    00159         }*/
    00160 }
    00161
    00162 void ExCSDKParticule::PrecalculeParticuleTrajectory(int start,int end)
    00163 {
    00164         float GravityX,GravityY,GravityZ;
    00165         ExCVec3D Position;
    00166         for(int i=start;i<end;i++)
    00167         {
    00168                 GravityX=((i*i)*(m_Gravity.m_Vector[0])/2000);
    00169                 GravityY=((i*i)*(m_Gravity.m_Vector[1])/2000);
    00170                 GravityZ=((i*i)*(m_Gravity.m_Vector[2])/2000);
    00171
    00172                 Position.m_Vector[0]=m_Position.m_Vector[0]+(m_Velocity.m_Vector[0]*i)-GravityX;
    00173                 Position.m_Vector[1]=m_Position.m_Vector[1]+(m_Velocity.m_Vector[1]*i)-GravityY;
    00174                 Position.m_Vector[2]=m_Position.m_Vector[2]+(m_Velocity.m_Vector[2]*i)-GravityZ;
    00175                 m_VecPosition.push_back(Position);
    00176         }
    00177 }
    00178
    00179 void ExCSDKParticule::ApplyForceToParitcule(ExCVec3D force)
    00180 {
    00181 }