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

# ExManagerCollision.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: ExManagerCollision.cpp,v 1.5 2002/09/22 15:54:02 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExManagerCollision.h"
    00025
    00026 bool ExManagerCollision::m_flag = false;
    00027 ExManagerCollision* ExManagerCollision::m_instance = NULL;
    00028
    00029 ExManagerCollision* ExManagerCollision::CreateSingleton(void){
    00030 Guard(ExManagerCollision* ExManagerCollision::CreateSingleton(void))
    00031         if(!m_flag)
    00032         {
    00033                 m_flag = true; // We are creating the error log now, so set flag to true
    00034                 m_instance = new ExManagerCollision; // Create the error log
    00035         }else
    00036         {
    00037                 std::cout<<"Error singleton already created"<<std::endl;
    00038         }
    00039         return m_instance;
    00040 UnGuard
    00041 }
    00042
    00043 ExManagerCollision::ExManagerCollision(void)
    00044 {
    00045 }
    00046
    00047 ExManagerCollision::~ExManagerCollision(void)
    00048 {
    00049 }
    00050
    00051 void ExManagerCollision::Reset(void)
    00052 {
    00053 }
    00054
    00055 void ExManagerCollision::Reload(void)
    00056 {
    00057 }
    00058
    00059 void ExManagerCollision::ResolveCollision(void)
    00060 {
    00061 Guard(void ExManagerCollision::ResolveCollision(void))
    00062         //i=0 comparer i avec i+1....i+nombre elem
    00063         //i=1 ...
    00064         //i=nombre elem quit
    00065         ExCVec3D Nev,CurrentVec;
    00066         ExCModel *CurrentModel,*ModelToCompare;
    00067         float lowlestradius;
    00068         bool Collision;
    00069         for(unsigned int i=0;i<ManagerModel->GetNumberObject();i++)
    00070         {
    00071                 CurrentModel=ManagerModel->GetCurrentObject();
    00072                 Collision=false;
    00073                 for(unsigned int j=i+1;j<ManagerModel->GetNumberObject();j++)
    00074                 {
    00075                         ManagerModel->NextObject();
    00076                         ModelToCompare=ManagerModel->GetCurrentObject();
    00077                         ModelToCompare->ResetCollisionCouter();
    00078                         ModelToCompare->GetCollisionGizmo()->SetColor(ExCVec3D(1.0f,1.0f,1.0f));
    00079                         //CHECK COLLISION TYPE BOX/BOX SPHERE/SPHERE SPHERE/BOX...
    00080                         //SPHERE/SPHERE
    00081                         if(strcmp(ModelToCompare->GetCollisionGizmo()->GetType().data(),"class ExCGizmoSphere *")==0
    00082                                 &&strcmp(CurrentModel->GetCollisionGizmo()->GetType().data(),"class ExCGizmoSphere *")==0)//sphere with sphere
    00083                         {
    00084
    00085                                 if(ModelToCompare->m_SphereRadius<CurrentModel->m_SphereRadius)
    00086                                 {
    00087                                         lowlestradius=ModelToCompare->m_SphereRadius;
    00088                                 }else{
    00089                                         lowlestradius=CurrentModel->m_SphereRadius;
    00090                                 }
    00091                                 Nev=ModelToCompare->GetPosition()-CurrentModel->GetPosition();
    00092                                 if(Nev.GetX()<lowlestradius&&Nev.GetX()>-lowlestradius)
    00093                                 {
    00094                                         if(Nev.GetZ()<lowlestradius&&Nev.GetZ()>-lowlestradius)
    00095                                         {
    00096                                                 std::cout<<CurrentModel->GetName()<<" Collision SPHERE/SPHERE with "<<ModelToCompare->GetName()<<std::endl;
    00097                                                 if(Nev.GetY()<lowlestradius&&Nev.GetY()>-lowlestradius)
    00098                                                 {
    00099                                                         ExCVec3D tmpvel,tmptrgt;
    00100                                                         tmpvel=CurrentModel->GetVelocity()+ModelToCompare->GetVelocity();
    00101                                                         tmptrgt=CurrentModel->GetTarget()+ModelToCompare->GetTarget();
    00102
    00103                                                         CurrentModel->SetVelocity(tmpvel/2);
    00104                                                         CurrentModel->SetTarget(tmptrgt/2);
    00105                                                         ModelToCompare->SetVelocity(tmpvel/2);
    00106                                                         ModelToCompare->SetTarget(tmptrgt/2);
    00107                                                         CurrentModel->GetCollisionGizmo()->SetColor(ExCVec3D(1.0f,0.0f,0.0f));
    00108                                                         ModelToCompare->GetCollisionGizmo()->SetColor(ExCVec3D(0.0f,1.0f,0.0f));
    00109                                                         Collision=true;
    00110                                                         CurrentModel->IncreaseCollisionCouter();
    00111                                                         ModelToCompare->IncreaseCollisionCouter();
    00112
    00113                                                 }
    00114                                         }
    00115                                 }
    00116                         }
    00117                         //SPHERE/RECTANGLE
    00118                         if(strcmp(ModelToCompare->GetCollisionGizmo()->GetType().data(),"class ExCGizmoSphere *")==0
    00119                                 &&strcmp(CurrentModel->GetCollisionGizmo()->GetType().data(),"class ExCGizmoRectangle*")==0)//sphere with sphere
    00120                         {
    00121                         //      std::cout<<CurrentModel->GetName()<<" Collision SPHERE/RECTANGLE with "<<ModelToCompare->GetName()<<std::endl;
    00122                         }
    00123                         //RECTANGLE/SPHERE
    00124                         if(strcmp(ModelToCompare->GetCollisionGizmo()->GetType().data(),"class ExCGizmoRectangle *")==0
    00125                                 &&strcmp(CurrentModel->GetCollisionGizmo()->GetType().data(),"class ExCGizmoSphere *")==0)//sphere with sphere
    00126                         {
    00127                         //      std::cout<<CurrentModel->GetName()<<" Collision RECTANGLE/SPHERE with "<<ModelToCompare->GetName()<<std::endl;
    00128                         }
    00129                         //RECTANGLE/RECTANGLE
    00130                         if(strcmp(ModelToCompare->GetCollisionGizmo()->GetType().data(),"class ExCGizmoRectangle *")==0
    00131                                 &&strcmp(CurrentModel->GetCollisionGizmo()->GetType().data(),"class ExCGizmoRectangle *")==0)//sphere with sphere
    00132                         {
    00133                         //      std::cout<<CurrentModel->GetName()<<" Collision RECTANGLE/RECTANGLE with "<<ModelToCompare->GetName()<<std::endl;
    00134                         }
    00135                 }
    00136                 if(!Collision)
    00137                 {
    00138                         //CurrentModel->GetCollisionGizmo()->SetColor(ExCVec3D(1.0f,1.0f,1.0f));
    00139                 }
    00140                 ManagerModel->NextObject();
    00141         }
    00142 UnGuard
    00143 }
    00144
    00145 void ExManagerCollision::Clear(void)
    00146 {
    00147
    00148 }