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

# ExCModelMD2.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: ExCModelMD2.cpp,v 1.11 2002/12/13 11:45:03 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCModelMD2.h"
    00025 //---------------------------------------------------------------
    00026 ExCModelMD2::ExCModelMD2(void)
    00027 {
    00028 Guard(ExCModelMD2::ExCModelMD2(void))
    00029         ExCModel::ExCModel();
    00030         SetName("ExCModelMD2");
    00031         SetType(typeid(this).name());
    00032         m_CurrentFrames=2;
    00033         m_NextFrame=3;
    00034         m_InterpolationPourcentage=0.1f;
    00035         m_Interpolation=m_InterpolationPourcentage;
    00036         m_Transition=false;
    00037         StartAction("IDLE");
    00038         m_speed=10;
    00039         count=0;
    00040         m_SphereRadius=9;
    00041         m_ShowCollisionSphere=false;
    00042         //m_Gravity.SetValue(0.0f,-9.81f,0.0f);
    00043         m_Velocity.SetValue(0.0f,0.0f,0.0f);
    00044         m_CollisionGizmo= new ExCGizmoSphere;
    00045         m_CollisionGizmo->SetVisibleState(false);
    00046         m_CollisionCounter=0;
    00047 UnGuard
    00048 }
    00049 /*
    00050 ExCModelMD2::ExCModelMD2(const ExCModelMD2& copy)
    00051 {
    00052 Guard(ExCModelMD2::ExCModelMD2(const ExCModelMD2& copy))
    00053         m_CurrentFrames=copy.m_CurrentFrames;
    00054         m_NextFrame=copy.m_NextFrame;
    00055         m_InterpolationPourcentage=copy.m_InterpolationPourcentage;
    00056         m_Interpolation=copy.m_Interpolation;
    00057         m_Transition=copy.m_Transition;
    00058         m_speed=copy.m_speed;
    00059
    00060         m_VecSkin=copy.m_VecSkin;
    00061         m_VecTexture=copy.m_VecTexture;
    00062         m_VecTriangle=copy.m_VecTriangle;
    00063         m_VecVertex=copy.m_VecVertex;
    00064 UnGuard
    00065 }*/
    00066
    00067 ExCModelMD2::~ExCModelMD2(void)
    00068 {
    00069 Guard(ExCModelMD2::~ExCModelMD2(void))
    00070 UnGuard
    00071 }
    00072
    00073 ExCAction ExCModelMD2::InputAction(ExCAction Action)
    00074 {
    00075         //std::cout<<"MODEL"<<Action;
    00076         switch(Action.m_Action)
    00077         {
    00078         case NEXT_FRAME:
    00079                         NextFrame();
    00080                         break;
    00081                 case PREVIOUS_FRAME:
    00082                         break;
    00083                 case SET_CURENT_FRAME:
    00084                         break;
    00085                 case START_ACTION:
    00086                         StartAction(Action.m_Param);
    00087                         break;
    00088                 case STOP_ACTION:
    00089                         StopAction(Action.m_Param);
    00090                         break;
    00091                 case TURN_LEFT:
    00092                         StartAction("TURN_LEFT");
    00093                         break;
    00094                 case TURN_RIGHT:
    00095                         StartAction("TURN_RIGHT");
    00096                 case LOOK_UP:
    00097                         StartAction(Action.m_Param);
    00098                         break;
    00099                 case LOOK_DOWN:
    00100                         StartAction(Action.m_Param);
    00101                         break;
    00102                 case MODEL_SET_POS_X:
    00103                         m_Position.SetX(atof(Action.m_Param.data()));
    00104                         break;
    00105                 case MODEL_SET_POS_Y:
    00106                         m_Position.SetY(atof(Action.m_Param.data()));
    00107                         break;
    00108                 case MODEL_SET_POS_Z:
    00109                         m_Position.SetZ(atof(Action.m_Param.data()));
    00110                         break;
    00111                 case MODEL_SET_ANGLE_X:
    00112             m_Angle.SetX(atof(Action.m_Param.data()));
    00113                         break;
    00114                 case MODEL_SET_ANGLE_Y:
    00115                         m_Angle.SetY(atof(Action.m_Param.data()));
    00116                         break;
    00117                 case MODEL_SET_ANGLE_Z:
    00118                         m_Angle.SetZ(atof(Action.m_Param.data()));
    00119                         break;
    00120                 case MODEL_START_ROTATE_Y_DOWN:
    00121                         StartAction("TURN_RIGHT");
    00122                         break;
    00123                 case MODEL_STOP_ROTATE_Y_DOWN:
    00124                         StopAction("TURN_RIGHT");
    00125                         if(!IsAction("RUN")){StartAction("IDLE");}
    00126                         break;
    00127                 case MODEL_START_ROTATE_Y_UP:
    00128                         StartAction("TURN_LEFT");
    00129                         break;
    00130                 case MODEL_STOP_ROTATE_Y_UP:
    00131                         StopAction("TURN_LEFT");
    00132                         if(!IsAction("RUN")){StartAction("IDLE");}
    00133                         break;
    00134                 case MODEL_START_ROTATE_Z_DOWN:
    00135                         StartAction("LOOK_UP");
    00136                         break;
    00137                 case MODEL_STOP_ROTATE_Z_DOWN:
    00138                         StopAction("LOOK_UP");
    00139                         break;
    00140                 case MODEL_START_ROTATE_Z_UP:
    00141                         StartAction("LOOK_DOWN");
    00142                         break;
    00143                 case MODEL_STOP_ROTATE_Z_UP:
    00144                         StopAction("LOOK_DOWN");
    00145                         break;
    00146                 case MODEL_START_ROTATE_X_DOWN:
    00147                         StartAction("X_DOWN");
    00148                         break;
    00149                 case MODEL_STOP_ROTATE_X_DOWN:
    00150                         StopAction("X_DOWN");
    00151                         break;
    00152                 case MODEL_START_ROTATE_X_UP:
    00153                         StartAction("X_UP");
    00154                         break;
    00155                 case MODEL_STOP_ROTATE_X_UP:
    00156                         StopAction("X_UP");
    00157                         break;
    00158                 case MODEL_START_MOVE_FORWARD:
    00159                         StartAction("RUN");
    00160                         m_Acceleration=m_Acceleration+0.01;
    00161                         break;
    00162                 case MODEL_STOP_MOVE_FORWARD:
    00163                         StopAction("RUN");
    00164                         StartAction("IDLE");
    00165                         m_Acceleration.SetValue(0.0f,0.0f,0.0f);
    00166                         m_Velocity.SetValue(0.0f,0.0f,0.0f);
    00167                         break;
    00168                 case MODEL_JUMP:
    00169                         StartAction("JUMP");
    00170                         break;
    00171                 case MODEL_SET_ACTION:
    00172             break;
    00173                 case MODEL_STOP_ALL:
    00174                         m_VecAction.clear();
    00175                         m_Velocity.SetValue(0.0f,0.0f,0.0f);
    00176                         m_Acceleration.SetValue(0.0f,0.0f,0.0f);
    00177                         break;
    00178                 case MODEL_SHOW_COLLISION_SPHERE:
    00179                         if(m_ShowCollisionSphere){m_ShowCollisionSphere=false;}
    00180                         else{m_ShowCollisionSphere=true;}
    00181
    00182                         break;
    00183                 case MODEL_START_STRAFE_LEFT:
    00184                         StartAction("STRAFE_LEFT");
    00185                         break;
    00186                 case MODEL_STOP_STRAFE_LEFT     :
    00187                         StopAction("STRAFE_LEFT");
    00188                         break;
    00189                 case MODEL_START_STRAFE_RIGHT:
    00190                         StartAction("STRAFE_RIGHT");
    00191                         break;
    00192                 case MODEL_STOP_STREFA_RIGHT:
    00193                         StopAction("STRAFE_RIGHT");
    00194                         break;
    00195         }
    00196         return NOTHING;
    00197 }
    00198
    00199 void ExCModelMD2::Process(std::string Action)
    00200 {
    00201 Guard(void ExCModelMD2::Process(std::string Action))
    00202         if(m_Angle.GetX()<0)m_Angle.SetX(359);
    00203         if(m_Angle.GetX()>359)m_Angle.SetX(0);
    00204         if(m_Angle.GetY()<0)m_Angle.SetY(359);
    00205         if(m_Angle.GetY()>359)m_Angle.SetY(0);
    00206         if(m_Angle.GetZ()<0)m_Angle.SetZ(359);
    00207         if(m_Angle.GetZ()>359)m_Angle.SetZ(0);
    00208         //process action
    00209         if(Action=="RUN")
    00210         {
    00211                 //m_Position=m_Target;
    00212                 //return;
    00213                 //m_Velocity.SetX(0.01f);
    00214         }
    00215         if(Action=="STRAFE_LEFT")
    00216         {
    00217                 float angle;
    00218                 angle=m_Angle.GetY()+90;
    00219                 if(angle>360)angle=angle-360;
    00220                 m_Position=m_Position+ExCVec3D(Cos[(int)angle],0.0f,Sin[(int)angle]);
    00221                 return;
    00222         }
    00223         if(Action=="STRAFE_RIGHT")
    00224         {
    00225                 float angle;
    00226                 angle=m_Angle.GetY()+90;
    00227                 if(angle>360)angle=angle-360;
    00228                 m_Position=m_Position-ExCVec3D(Cos[(int)angle],0.0f,Sin[(int)angle]);
    00229                 return;
    00230         }
    00231
    00232         if(Action=="TURN_LEFT"){m_Angle.DecY(2);return;}
    00233         if(Action=="TURN_RIGHT"){m_Angle.IncY(2);return;}
    00234         if(Action=="LOOK_UP"){m_Angle.IncZ(2);return;}
    00235         if(Action=="LOOK_DOWN"){m_Angle.DecZ(2);return;}
    00236         if(Action=="X_UP"){m_Angle.IncX(2);return;}
    00237         if(Action=="X_DOWN"){m_Angle.DecX(2);return;}
    00238         if(Action=="JUMP")
    00239         {
    00240                 if(m_CurrentFrames=72)
    00241                 {
    00242                         StopAction("JUMP");
    00243                         if(!IsAction("RUN")){StartAction("IDLE");}
    00244                 }
    00245         }
    00246 UnGuard
    00247 }
    00248 void ExCModelMD2::ProcessAllAction(void)
    00249 {
    00250 Guard(void ExCModelMD2::ProcessAllAction(void))
    00251         for(unsigned int i=0;i< m_VecAction.size();i++)
    00252         {
    00253                 Process(m_VecAction.at(i));
    00254         }
    00255 UnGuard
    00256 }
    00257
    00258 void ExCModelMD2::StopAction(std::string         Action)
    00259 {
    00260 Guard(void ExCModelMD2::StopAction(std::string   Action))
    00261         for(m_IVecAction= m_VecAction.begin();m_IVecAction!= m_VecAction.end();m_IVecAction++)
    00262         {
    00263                 if(strcmp(m_IVecAction->data(),Action.data())==0)
    00264                 {
    00265                         m_VecAction.erase(m_IVecAction);
    00266                         return;
    00267                 }
    00268         }
    00269 UnGuard
    00270 }
    00271
    00272 bool ExCModelMD2::IsAction(std::string Action)
    00273 {
    00274 Guard(bool ExCModelMD2::IsAction(std::string Action))
    00275         for(m_IVecAction= m_VecAction.begin();m_IVecAction!= m_VecAction.end();m_IVecAction++)
    00276         {
    00277                 if(strcmp(m_IVecAction->data(),Action.data())==0)
    00278                 {
    00279                         return true;
    00280                 }
    00281         }
    00282         return false;
    00283 UnGuard
    00284 }
    00285 void ExCModelMD2::StartAction(std::string        Action)
    00286 {
    00287 Guard(void ExCModelMD2::StartAction(std::string  Action))
    00288         m_VecAction.push_back(Action);
    00289         m_CurrentAction=Action;
    00290         if(m_CurrentAction=="RUN")
    00291         {
    00292                 m_KeyFrameStartAction=40;
    00293                 m_KeyFrameStopAction=46;
    00294         }
    00295         if(m_CurrentAction=="ATTACK")
    00296         {
    00297                 m_KeyFrameStartAction=47;
    00298                 m_KeyFrameStopAction=60;
    00299         }
    00300         if(m_CurrentAction=="CROUCH")
    00301         {
    00302                 m_KeyFrameStartAction=136;
    00303                 m_KeyFrameStopAction=154;
    00304         }
    00305         if(m_CurrentAction=="JUMP")
    00306         {
    00307                 m_KeyFrameStartAction=67;
    00308                 m_KeyFrameStopAction=73;
    00309         }
    00310         if(m_CurrentAction=="IDLE")
    00311         {
    00312                 m_KeyFrameStartAction=1;
    00313                 m_KeyFrameStopAction=39;
    00314         }
    00315         if(m_CurrentAction=="FULL")
    00316         {
    00317                 m_KeyFrameStartAction=113;
    00318                 m_KeyFrameStopAction=125;
    00319
    00320         }
    00321         if(m_CurrentAction=="TURN_LEFT")
    00322         {
    00323                 m_KeyFrameStartAction=41;
    00324                 m_KeyFrameStopAction=46;
    00325     }
    00326         if(m_CurrentAction=="TURN_RIGHT")
    00327         {
    00328                 m_KeyFrameStartAction=41;
    00329                 m_KeyFrameStopAction=46;
    00330         }
    00331         if(m_CurrentAction=="LOOK_UP")
    00332         {
    00333                 m_KeyFrameStartAction=1;
    00334                 m_KeyFrameStopAction=39;
    00335     }
    00336         if(m_CurrentAction=="LOOK_DOWN")
    00337         {
    00338                 m_KeyFrameStartAction=1;
    00339                 m_KeyFrameStopAction=39;
    00340         }
    00341         if(m_CurrentAction=="FULL")
    00342         {
    00343                 m_KeyFrameStartAction=1;
    00344                 m_KeyFrameStopAction=198;
    00345         }
    00346         if(m_CurrentAction=="NONE")
    00347         {
    00348                 m_KeyFrameStartAction=1;
    00349                 m_KeyFrameStopAction=1;
    00350         }
    00351         m_Transition=true;
    00352         m_CurrentFrames=m_KeyFrameStartAction;
    00353 UnGuard
    00354 }
    00355
    00356
    00357
    00358 void ExCModelMD2::Draw(void)
    00359 {
    00360 Guard(void ExCModelMD2::Draw(void))
    00361         double CurrentTime;
    00362         if(!m_Visible)return;
    00363         //ExCModel::Draw();
    00364         ExCVec3D VecAB,VecBC,VecCA;
    00365         int FrameToDraw,FrameToInterpol;
    00366         CurrentTime=glutGet(GLUT_ELAPSED_TIME);
    00367         if(CurrentTime>m_LastTime+m_speed)
    00368         {
    00369
    00370                 if(m_Transition)
    00371                 {
    00372                         m_Interpolation+=m_InterpolationPourcentage;
    00373                         if(m_Interpolation>1)//check if we go to next frame
    00374                         {
    00375                                 m_Interpolation=m_InterpolationPourcentage;
    00376                                 m_CurrentFrames++;
    00377                                 m_NextFrame=m_CurrentFrames+1;
    00378                                 if(m_NextFrame>m_KeyFrameStopAction)m_NextFrame=m_KeyFrameStartAction;
    00379                                 if(m_CurrentFrames>m_KeyFrameStopAction)
    00380                                 {
    00381                                         m_CurrentFrames=m_KeyFrameStartAction;
    00382                                         m_NextFrame=m_CurrentFrames+1;
    00383                                 }
    00384                         }
    00385                 }
    00386                 m_LastTime=CurrentTime;
    00387         }
    00388         FrameToDraw=m_numVertices*m_CurrentFrames;
    00389         FrameToInterpol=m_numVertices*m_NextFrame;
    00390         ProcessAllAction();
    00391 //check if camera can see object
    00392         ExCFrustum Frustrum;
    00393         Frustrum.CalculateFrustum();
    00394         if(!Frustrum.SphereInFrustum(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ(),m_CollisionSphere.m_Radius))
    00395         {
    00396                 return;
    00397         }
    00398
    00399         TabVertices= new float[m_numTriangles*9];
    00400         for(int i = 0; i < m_numTriangles; i++)
    00401         {
    00402                 //----------------
    00403                 //Vertex coord
    00404                 //----------------
    00405                 VecAB.SetX(m_VecVertex.at(m_VecTriangle.at(i).first.GetX()+FrameToDraw).GetX());
    00406                 VecAB.SetY(m_VecVertex.at(m_VecTriangle.at(i).first.GetX()+FrameToDraw).GetY());
    00407                 VecAB.SetZ(m_VecVertex.at(m_VecTriangle.at(i).first.GetX()+FrameToDraw).GetZ());
    00408
    00409                 VecBC.SetX(m_VecVertex.at(m_VecTriangle.at(i).first.GetY()+FrameToDraw).GetX());
    00410                 VecBC.SetY(m_VecVertex.at(m_VecTriangle.at(i).first.GetY()+FrameToDraw).GetY());
    00411                 VecBC.SetZ(m_VecVertex.at(m_VecTriangle.at(i).first.GetY()+FrameToDraw).GetZ());
    00412
    00413                 VecCA.SetX(m_VecVertex.at(m_VecTriangle.at(i).first.GetZ()+FrameToDraw).GetX());
    00414                 VecCA.SetY(m_VecVertex.at(m_VecTriangle.at(i).first.GetZ()+FrameToDraw).GetY());
    00415                 VecCA.SetZ(m_VecVertex.at(m_VecTriangle.at(i).first.GetZ()+FrameToDraw).GetZ());
    00416
    00417                 //--------------
    00418                 //interpolation
    00419                 //--------------
    00420                 if(m_Transition)
    00421                 {
    00422                         ExCVec3D VecABN,VecBCN,VecCAN;
    00423
    00424                         VecABN.SetX(m_VecVertex.at(m_VecTriangle.at(i).first.GetX()+FrameToInterpol).GetX());
    00425                         VecABN.SetY(m_VecVertex.at(m_VecTriangle.at(i).first.GetX()+FrameToInterpol).GetY());
    00426                         VecABN.SetZ(m_VecVertex.at(m_VecTriangle.at(i).first.GetX()+FrameToInterpol).GetZ());
    00427
    00428                         VecBCN.SetX(m_VecVertex.at(m_VecTriangle.at(i).first.GetY()+FrameToInterpol).GetX());
    00429                         VecBCN.SetY(m_VecVertex.at(m_VecTriangle.at(i).first.GetY()+FrameToInterpol).GetY());
    00430                         VecBCN.SetZ(m_VecVertex.at(m_VecTriangle.at(i).first.GetY()+FrameToInterpol).GetZ());
    00431
    00432                         VecCAN.SetX(m_VecVertex.at(m_VecTriangle.at(i).first.GetZ()+FrameToInterpol).GetX());
    00433                         VecCAN.SetY(m_VecVertex.at(m_VecTriangle.at(i).first.GetZ()+FrameToInterpol).GetY());
    00434                         VecCAN.SetZ(m_VecVertex.at(m_VecTriangle.at(i).first.GetZ()+FrameToInterpol).GetZ());
    00435
    00436                         VecAB=VecAB+((VecABN-VecAB)*m_Interpolation);
    00437                         VecBC=VecBC+((VecBCN-VecBC)*m_Interpolation);
    00438                         VecCA=VecCA+((VecCAN-VecCA)*m_Interpolation);
    00439                 }
    00440                 //--------------
    00441                 //Build array with new vertex data
    00442                 //--------------
    00443                         TabVertices[0+i*9]=VecBC.GetX();
    00444                         TabVertices[1+i*9]=VecBC.GetY();
    00445                         TabVertices[2+i*9]=VecBC.GetZ();
    00446                         TabVertices[3+i*9]=VecAB.GetX();
    00447                         TabVertices[4+i*9]=VecAB.GetY();
    00448                         TabVertices[5+i*9]=VecAB.GetZ();
    00449                         TabVertices[6+i*9]=VecCA.GetX();
    00450                         TabVertices[7+i*9]=VecCA.GetY();
    00451                         TabVertices[8+i*9]=VecCA.GetZ();
    00452         }
    00453         //----------------------------
    00454         //Apply mouvement modification
    00455         //----------------------------
    00456         glPushMatrix();
    00457         ExCModel::Draw();
    00458         //ShowInfo();
    00459         //--------------
    00460         //Draw Model with array
    00461         //--------------
    00462         glRotatef(-90,1,0,0);
    00463
    00464         //m_CollisionSphere.SetPosition(m_Position);
    00465         //if(m_ShowCollisionSphere)m_CollisionSphere.Draw();
    00466         m_CollisionGizmo->SetPosition(m_Position);
    00467         m_CollisionGizmo->Draw();
    00468
    00469
    00470         //stock in vidoe memory
    00471         PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
    00472         PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
    00473         PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
    00474
    00475         glBindBufferARB = (PFNGLBINDBUFFERARBPROC)
    00476                 wglGetProcAddress("glBindBufferARB");
    00477         glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)
    00478                 wglGetProcAddress("glGenBuffersARB");
    00479         glBufferDataARB = (PFNGLBUFFERDATAARBPROC)
    00480                 wglGetProcAddress("glBufferDataARB");
    00481
    00482
    00483
    00484         glColor3f(1,1,1);
    00485         /*      glPushMatrix();
    00486                         glDisable(GL_LIGHTING);
    00487                         ManagerTexture->SetTexture(0,m_Skin);
    00488                         glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
    00489                         ManagerTexture->SetTexture(1,"Model/OgreDOT3");
    00490                         glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
    00491                         glEnableClientState(GL_VERTEX_ARRAY);
    00492                         GLuint buffer = 0;
    00493                         glGenBuffersARB(1, &buffer);
    00494                         glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
    00495                         glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(TabVertices), TabVertices, GL_STATIC_DRAW_ARB);
    00496
    00497                         glVertexPointer(3,GL_FLOAT,0,TabVertices);
    00498                         glDrawArrays( GL_TRIANGLES, 0, m_numTriangles*3 );
    00499                         ManagerTexture->ResetMultitexture();
    00500                 glPopMatrix();
    00501         */
    00502         glPushMatrix();
    00503                 glDisable(GL_LIGHTING);
    00504                 ManagerTexture->SetTexture(0,m_Skin);
    00505         /*
    00506                 // RGB
    00507                 glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
    00508
    00509                 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
    00510                 glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_TEXTURE);
    00511                 glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SRC_COLOR);
    00512                 glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_PREVIOUS_EXT);
    00513                 glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SRC_COLOR);
    00514
    00515                 // alpha
    00516                 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_EXT,GL_REPLACE);
    00517                 glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_TEXTURE);
    00518                 glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_SRC_ALPHA);
    00519
    00520 */
    00521         //      glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
    00522         //      ManagerTexture->SetTexture(1,"Model/droidDOT3");
    00523 /*              // RGB
    00524                 glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
    00525                 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_REPLACE);
    00526                 glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PREVIOUS_EXT);
    00527                 glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SRC_COLOR);
    00528
    00529                 // alpha
    00530                 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_EXT,GL_ADD_SIGNED_EXT);
    00531                 glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_TEXTURE);
    00532                 glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_ONE_MINUS_SRC_ALPHA);
    00533                 glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_EXT,GL_PREVIOUS_EXT);
    00534                 glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA_EXT,GL_SRC_ALPHA);
    00535
    00536                 glEnable(GL_BLEND);
    00537
    00538                 // src * srcAlpha + 0
    00539                 glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
    00540 */
    00541
    00542                 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
    00543         glEnableClientState(GL_VERTEX_ARRAY);
    00544                 GLuint buffer = 0;
    00545                 glGenBuffersARB(1, &buffer);
    00546                 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
    00547                 glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(TabVertices), TabVertices, GL_STATIC_DRAW_ARB);
    00548
    00549                 glVertexPointer(3,GL_FLOAT,0,TabVertices);
    00550
    00551
    00552                 glDrawArrays( GL_TRIANGLES, 0, m_numTriangles*3 );
    00553
    00554         //      glDisable(GL_BLEND);
    00555
    00556                 ManagerTexture->ResetMultitexture();
    00557         glPopMatrix();
    00558         //--------------------------------------
    00559         glPopMatrix();
    00560         glDisable(GL_TEXTURE_2D);
    00561         m_OldPosition=m_Position;
    00562         delete TabVertices;
    00563
    00564 UnGuard
    00565 }
    00566
    00567
    00568
    00569
    00570 bool ExCModelMD2::Load(std::string FileName)
    00571 {
    00572 Guard(bool ExCModelMD2::Load(std::string FileName))
    00573         int i,j;
    00574         FILE *filePtr;                          // file pointer
    00575     int fileLen;                            // length of model file
    00576     char *buffer;                           // file buffer
    00577
    00578     modelHeader_t *modelHeader;             // model header
    00579         frame_t *frame;                              // frame data
    00580         stIndex_t *stPtr;                       // texture data
    00581          mesh_t *bufIndexPtr;          // index variables
    00582         m_Skin=ExNihilo::ExtracValueFromSring(FileName,"../Data/Modeles/",".md2");
    00583         m_Skin="Model/"+m_Skin;
    00584
    00585         ManagerTexture->Load(m_Skin);
    00586
    00587
    00588
    00589     filePtr = fopen(FileName.data(), "rb");
    00590     if (filePtr == NULL)
    00591         {
    00592                 throw ExCExpFileNotFound();
    00593                 return false;
    00594         }
    00595
    00596
    00597          // find length of file
    00598      fseek(filePtr, 0, SEEK_END);
    00599      fileLen = ftell(filePtr);
    00600      fseek(filePtr, 0, SEEK_SET);
    00601
    00602      // read entire file into buffer
    00603      buffer = new char [fileLen+1];
    00604      fread(buffer, sizeof(char), fileLen, filePtr);
    00605
    00606          modelHeader = (modelHeader_t*)buffer;
    00607
    00608 /*       std::ofstream logscale;
    00609          std::ofstream logfp;
    00610          std::ofstream logtranslate;
    00611          std::ofstream logfile;
    00612          std::ofstream logHeader;
    00613          std::ofstream logTextureCoord;
    00614
    00615          logscale.open("logscale.txt",std::ios::out);
    00616          logfp.open("logfp.txt",std::ios::out);
    00617          logtranslate.open("logtranslate.txt",std::ios::out);
    00618          logfile.open("logfile.txt",std::ios::out);
    00619          logHeader.open("logHeader.txt",std::ios::out);
    00620          logTextureCoord.open("logTextureCoord.txt",std::ios::out);
    00621 */
    00622
    00623         m_magic=modelHeader->ident;
    00624         m_version=modelHeader->version;                                         // The version number of the file (Must be 8)
    00625         m_skinWidth=modelHeader->skinwidth;                                     // The skin width in pixels
    00626         m_skinHeight=modelHeader->skinheight;                           // The skin height in pixels
    00627         m_frameSize=modelHeader->framesize;                                     // The size in bytes the frames are
    00628         m_numSkins=modelHeader->numSkins;                                       // The number of skins associated with the model
    00629         m_numVertices=modelHeader->numXYZ;                              // The number of vertices (constant for each frame)
    00630         m_numTexCoords=modelHeader->numST;                      // The number of texture coordinates
    00631         m_numTriangles=modelHeader->numTris;                    // The number of faces (polygons)
    00632         m_numGlCommands=modelHeader->numGLcmds;                 // The number of gl commands
    00633         m_numFrames=modelHeader->numFrames;                                     // The number of animation frames
    00634         m_offsetSkins=modelHeader->offsetSkins;                         // The offset in the file for the skin data
    00635         m_offsetTexCoords=modelHeader->offsetST;                // The offset in the file for the texture data
    00636         m_offsetTriangles=modelHeader->offsetTris;              // The offset in the file for the face data
    00637         m_offsetFrames=modelHeader->offsetFrames;                       // The offset in the file for the frames data
    00638         m_offsetGlCommands=modelHeader->offsetGLcmds;   // The offset in the file for the gl commands data
    00639         m_offsetEnd=modelHeader->offsetEnd;                                     // The end of the file offset
    00640
    00641 /*      std::cout<<"This is used to identify the file: "<<m_magic<<std::endl;
    00642         std::cout<<"The version number of the file (Musbe 8):"<<m_version<<std::endl;
    00643         std::cout<<"The skin width in pixels:"<<m_skinWidth<<std::endl;
    00644         std::cout<<"The skin heighin pixels:"<<m_skinHeight<<std::endl;
    00645         std::cout<<"The size in bytes the frames are:"<<m_frameSize<<std::endl;
    00646         std::cout<<"The number of skins associated with the model:"<<m_numSkins<<std::endl;
    00647         std::cout<<"The number of vertices (constan for each frame):"<<m_numVertices<<std::endl;
    00648         std::cout<<"The number of texture coordinates:"<<m_numTexCoords<<std::endl;
    00649         std::cout<<"The number of faces (polygons):"<<m_numTriangles<<std::endl;
    00650         std::cout<<"The number of gl commands:"<<m_numGlCommands<<std::endl;
    00651         std::cout<<"The number of animation frames:"<<m_numFrames<<std::endl;
    00652         std::cout<<"The offset in the file for the skin data:"<<m_offsetSkins<<std::endl;
    00653         std::cout<<"The offset in the file for the texture data:"<<m_offsetTexCoords<<std::endl;
    00654         std::cout<<"The offset in the file for the face data:"<<m_offsetTriangles<<std::endl;
    00655         std::cout<<"The offset in the file for the frames data:"<<m_offsetFrames<<std::endl;
    00656         std::cout<<"The offset in the file for the gl commands data:"<<m_offsetGlCommands<<std::endl;
    00657         std::cout<<"The end of the file offset:"<<m_offsetEnd<<std::endl;
    00658 */
    00659         //-----------------------------------------------
    00660         //read all skin
    00661         //-----------------------------------------------
    00662         char mybuff[65];
    00663         std::string BuffSkin;
    00664     fseek(filePtr, m_offsetSkins, SEEK_SET);
    00665         for(i = 0;i<m_numSkins;++i)
    00666         {
    00667                 fread(&mybuff,sizeof(char),64, filePtr);
    00668                 BuffSkin=mybuff;
    00669                 //std::cout<<BuffSkin<<std::endl;
    00670                 m_VecSkin.push_back(BuffSkin);
    00671         }
    00672         //-----------------------------------------------
    00673         //read vertex  data
    00674         //-----------------------------------------------
    00675          ExCVec3D Vec3D;
    00676          for (j = 0; j < m_numFrames; j++)
    00677      {
    00678           frame = (frame_t*)&buffer[m_offsetFrames+ m_frameSize * j];
    00679           for (i = 0; i < m_numVertices; i++)
    00680           {
    00681                                 Vec3D.SetX(frame->scale[0] * frame->fp[i].v[0] + frame->translate[0]);
    00682                                 Vec3D.SetY(frame->scale[1] * frame->fp[i].v[1] + frame->translate[1]);
    00683                                 Vec3D.SetZ(frame->scale[2] * frame->fp[i].v[2] + frame->translate[2]);
    00684                                 Vec3D=Vec3D/3;
    00685                                 m_VecVertex.push_back(Vec3D);
    00686
    00687         /*                      logscale<<"X:"<<frame->scale[0]<<" Y:"<<frame->scale[1]<<" Z:"<<frame->scale[2]<<std::endl;
    00688                                 logfp<<"X:"<<frame->fp[i].v[0]<<" Y:"<<frame->fp[i].v[1]<<" Z:"<<frame->fp[i].v[2]<<std::endl;
    00689                                 logtranslate<<"X:"<<frame->translate[0]<<" Y:"<<frame->translate[1]<<" Z:"<<frame->translate[2]<<std::endl;
    00690                                 logfile<<"vec :"<<i<<" "<<Vec3D<<std::endl;*/
    00691           }
    00692                   //logfile<<"------------------------------------------------------------------"<<std::endl;
    00693      }
    00694         //-----------------------------------------------
    00695         //read triangles data
    00696         //-----------------------------------------------
    00697         fseek(filePtr, m_offsetTriangles, SEEK_SET);
    00698         short AB,BC,CA,TAB,TBC,TCA;
    00699         ExCVec3D VertexNum,TexturNum;
    00700         /*std::ofstream logTri;
    00701         logTri.open("logTri.txt",std::ios::out);
    00702         */
    00703
    00704      // point to triangle indexes in buffer
    00705     bufIndexPtr = (mesh_t*)&buffer[modelHeader->offsetTris];
    00706         // create a mesh (triangle) list
    00707      for (j = 0; j < m_numFrames; j++)
    00708      {
    00709           // for all triangles in each frame
    00710           for(i = 0; i < m_numTriangles; i++)
    00711           {
    00712                AB = bufIndexPtr[i].meshIndex[0];
    00713                BC = bufIndexPtr[i].meshIndex[1];
    00714                CA = bufIndexPtr[i].meshIndex[2];
    00715                TAB = bufIndexPtr[i].stIndex[0];
    00716                TBC = bufIndexPtr[i].stIndex[1];
    00717                TCA = bufIndexPtr[i].stIndex[2];
    00718
    00719                         VertexNum.SetValue(AB,BC,CA);
    00720                         TexturNum.SetValue(TAB,TBC,TCA);
    00721                         std::pair<ExCVec3D,ExCVec3D> tmp(VertexNum,TexturNum);
    00722                         m_VecTriangle.push_back(tmp);
    00723                 //      logTri<<"AB:"<<AB<<" BC:"<<BC<<" CA:"<<CA<<std::endl;
    00724                 //      logTri<<"TAB:"<<TAB<<" TBC:"<<TBC<<" TCA:"<<TCA<<std::endl;
    00725           }
    00726      }
    00727         //-----------------------------------------------
    00728         //read texture coord  data
    00729         //-----------------------------------------------
    00730         std::vector<ExCVec2D>           *VecTexture;
    00731         VecTexture= new std::vector<ExCVec2D>;
    00732         stPtr = (stIndex_t*)&buffer[m_offsetTexCoords];
    00733         for (i = 0; i < m_numTexCoords; i++)
    00734         {
    00735                 VecTexture->push_back(ExCVec2D(((float)stPtr[i].s / (float)m_skinWidth),((float)stPtr[i].t / (float)m_skinHeight)));
    00736         }
    00737         //------------------------------
    00738         //Build Texture Array
    00739         //------------------------------
    00740         TabTextures= new float[m_numTriangles*6];
    00741         for(i = 0; i < m_numTriangles; i++)
    00742         {
    00743                 TabTextures[0+i*6]=VecTexture->at(m_VecTriangle.at(i).second.GetY()).GetX();
    00744                 TabTextures[1+i*6]=VecTexture->at(m_VecTriangle.at(i).second.GetY()).GetY();
    00745                 TabTextures[2+i*6]=VecTexture->at(m_VecTriangle.at(i).second.GetX()).GetX();
    00746                 TabTextures[3+i*6]=VecTexture->at(m_VecTriangle.at(i).second.GetX()).GetY();
    00747                 TabTextures[4+i*6]=VecTexture->at(m_VecTriangle.at(i).second.GetZ()).GetX();
    00748                 TabTextures[5+i*6]=VecTexture->at(m_VecTriangle.at(i).second.GetZ()).GetY();
    00749         }
    00750         /*for(i = 0; i < m_numTriangles; i++)
    00751         {
    00752                 std::cout<<TabTextures[0+i*6]<<std::endl;
    00753                 std::cout<<TabTextures[1+i*6]<<std::endl;
    00754                 std::cout<<TabTextures[2+i*6]<<std::endl;
    00755                 std::cout<<TabTextures[3+i*6]<<std::endl;
    00756                 std::cout<<TabTextures[4+i*6]<<std::endl;
    00757                 std::cout<<TabTextures[5+i*6]<<std::endl;
    00758         }
    00759         std::cout<<"i:"<<i<<std::endl;*/
    00760         delete VecTexture;
    00761         delete buffer;
    00762         BuildSphere();
    00763         return true;
    00764 UnGuard
    00765 }
    00766 void ExCModelMD2::BuildSphere(void)
    00767 {
    00768 Guard(void ExCModelMD2::BuildSphere(void))
    00769         //look for sphere radisu
    00770         m_CollisionSphere.m_Radius=m_SphereRadius;
    00771 UnGuard
    00772 }
    00773 void ExCModelMD2::ShowInfo(void)
    00774 {
    00775 Guard(void ExCModelMD2::ShowInfo(void))
    00776
    00777         char *CIdName;
    00778         char *CPosition;
    00779         char *CVelocity;
    00780         char *CAcceleration;
    00781         char *CGravity;
    00782         char *CLife;
    00783         char *CAngle;
    00784         char *CTarget;
    00785
    00786         CIdName= new char[strlen("Name : Id:")+strlen(GetName().data())+7];
    00787         sprintf(CIdName,"Name :%s Id:%ld",GetName().data(),GetId());
    00788         ExNihilo::WriteToScreen(650,20,CIdName);
    00789
    00790         CPosition= new char[strlen("Position X: Y: Z:")+30];
    00791         sprintf(CPosition,"Position X:%f Y:%f Z:%f",m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
    00792         ExNihilo::WriteToScreen(650,35,CPosition);
    00793
    00794         CVelocity= new char[strlen("Velocity X: Y: Z:")+30];
    00795         sprintf(CVelocity,"Velocity X:%f Y:%f Z:%f",m_Velocity.GetX(),m_Velocity.GetY(),m_Velocity.GetZ());
    00796         ExNihilo::WriteToScreen(650,50,CVelocity);
    00797
    00798         CGravity= new char[strlen("Gravity X: Y: Z:")+30];
    00799         sprintf(CGravity,"Gravity X:%f Y:%f Z:%f",m_Gravity.GetX(),m_Gravity.GetY(),m_Gravity.GetZ());
    00800         ExNihilo::WriteToScreen(650,65,CGravity);
    00801
    00802         CAcceleration= new char[strlen("Acceleration X: Y: Z:")+30];
    00803         sprintf(CAcceleration,"Acceleration X:%f Y:%f Z:%f",m_Acceleration.GetX(),m_Acceleration.GetY(),m_Acceleration.GetZ());
    00804         ExNihilo::WriteToScreen(650,80,CAcceleration);
    00805
    00806         CTarget= new char[strlen("Target X: Y: Z:")+30];
    00807         sprintf(CTarget,"Target X:%f Y:%f Z:%f",m_Target.GetX(),m_Target.GetY(),m_Target.GetZ());
    00808         ExNihilo::WriteToScreen(650,95,CTarget);
    00809
    00810         CAngle= new char[strlen("Angle X: Y: Z:")+30];
    00811         sprintf(CAngle,"Angle X:%f Y:%f Z:%f",m_Angle.GetX(),m_Angle.GetY(),m_Angle.GetZ());
    00812         ExNihilo::WriteToScreen(650,110,CAngle);
    00813
    00814         CLife= new char[strlen("Life :")+10];
    00815         sprintf(CLife,"Life :%f",m_Life);
    00816         ExNihilo::WriteToScreen(650,125,CLife);
    00817
    00818         delete CIdName;
    00819         delete CPosition;
    00820         delete CVelocity;
    00821         delete CAcceleration;
    00822         delete CGravity;
    00823         delete CLife;
    00824         delete CAngle;
    00825         delete CTarget;
    00826 UnGuard
    00827 }