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

# ExCCameraChase.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: ExCCameraChase.cpp,v 1.5 2002/09/03 00:00:02 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCCameraChase.h"
    00025
    00026
    00027 ExCCameraChase::ExCCameraChase()
    00028 {
    00029 Guard(ExCCameraChase::ExCCameraChase())
    00030         SetName("ExCCameraChase");
    00031         SetType(typeid(this).name());
    00032         m_DistanceFromTarget=80.0f;
    00033         m_AngleAroundTarget=180;
    00034         m_CameraHeight=0.0f;
    00035 UnGuard
    00036 }
    00037
    00038 ExCCameraChase::~ExCCameraChase()
    00039 {
    00040 Guard(ExCCameraChase::~ExCCameraChase())
    00041 UnGuard
    00042 }
    00043
    00044 void ExCCameraChase::Draw(void)
    00045 {
    00046 Guard(void ExCCameraChase::Draw(void))
    00047         ExCVec3D fwd;
    00048         float TargetAngleY,TargetAngleZ;
    00049         //Test if there is one object
    00050         if(ManagerModel->GetCurrentObject()>0)
    00051         {
    00052                 m_Target=fwd+ManagerModel->GetCurrentObject()->GetPosition();
    00053                 m_Target.IncY(25);
    00054                 TargetAngleY=ManagerModel->GetCurrentObject()->GetAngleY();
    00055                 TargetAngleZ=ManagerModel->GetCurrentObject()->GetAngleZ();
    00056         }else //Transform the cam into free cam
    00057         {
    00058                 ExCCamera::Draw();
    00059                 return;
    00060         }
    00061         Process();
    00062
    00063         if(m_Angle.GetX()<0)m_Angle.SetX(359);
    00064         if(m_Angle.GetX()>359)m_Angle.SetX(0);
    00065         if(m_Angle.GetY()<0)m_Angle.SetY(359);
    00066         if(m_Angle.GetY()>359)m_Angle.SetY(0);
    00067         if(m_Angle.GetZ()<0)m_Angle.SetZ(359);
    00068         if(m_Angle.GetZ()>359)m_Angle.SetZ(0);
    00069
    00070         float cosY,cosP,cosR;
    00071         float sinY,sinP,sinR;
    00072
    00073         cosY=cosf(DegreesToRadians(GetAngleY()));
    00074         cosP=cosf(DegreesToRadians(GetAngleX()));
    00075         cosR=cosf(DegreesToRadians(GetAngleZ()));
    00076
    00077         sinY=sinf(DegreesToRadians(GetAngleY()));
    00078         sinP=sinf(DegreesToRadians(GetAngleX()));
    00079         sinR=sinf(DegreesToRadians(GetAngleZ()));
    00080
    00081         fwd.SetX(sinY*cosP);
    00082         fwd.SetY(sinP);
    00083         fwd.SetZ(cosP*-cosY);
    00084
    00085         m_Position.SetX(cosf(DegreesToRadians(TargetAngleY+m_AngleAroundTarget))*m_DistanceFromTarget);
    00086         m_Position.SetY(m_CameraHeight);
    00087         m_Position.SetZ(sinf(DegreesToRadians(TargetAngleY+m_AngleAroundTarget))*m_DistanceFromTarget);
    00088
    00089         m_Position=m_Position+m_Target;
    00090
    00091         m_Up.SetX((-cosY*sinR)-(sinY*sinP*cosR));
    00092         m_Up.SetY(cosP*cosR);
    00093         m_Up.SetZ((-sinY*sinR)-(sinP*cosR*-cosY));
    00094
    00095         gluLookAt(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()
    00096                         ,m_Target.GetX(),m_Target.GetY(),m_Target.GetZ()
    00097                         ,m_Up.GetX(),m_Up.GetY(),m_Up.GetZ());
    00098
    00099 UnGuard
    00100 }
    00101
    00102 void ExCCameraChase::Process(void)
    00103 {
    00104 Guard(void ExCCameraChase::Process(void))
    00105         for(unsigned i=0;i<m_VecAction.size();i++)
    00106         {
    00107                 switch(m_VecAction.at(i))
    00108                 {
    00109                 case ANGLE_AROUND_TARGET_UP:
    00110                         m_AngleAroundTarget=m_AngleAroundTarget+0.5;
    00111                         break;
    00112                 case ANGLE_AROUND_TARGET_DOWN:
    00113                         m_AngleAroundTarget=m_AngleAroundTarget-0.5;
    00114                         break;
    00115                 case DISTANCE_FROM_TARGET_UP:m_DistanceFromTarget++;break;
    00116                 case DISTANCE_FROM_TARGET_DOWN:m_DistanceFromTarget--;break;
    00117                 case HEIGHT_FROM_TARGET_UP:m_CameraHeight++;break;
    00118                 case HEIGHT_FROM_TARGET_DOWN:m_CameraHeight--;break;
    00119                 default:ExCCamera::Process();
    00120                 }
    00121         }
    00122 UnGuard
    00123 }