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

# ExCCameraFlight.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
    00021  *
    00022  */
    00023
    00024 #include "ExCCameraFlight.h"
    00025
    00026
    00027 ExCCameraFlight::ExCCameraFlight()
    00028 {
    00029 Guard(ExCCameraFlight::ExCCameraFlight())
    00030         SetName("ExCCameraFlight");
    00031         SetType(typeid(this).name());
    00032 UnGuard
    00033 }
    00034
    00035 ExCCameraFlight::~ExCCameraFlight()
    00036 {
    00037 Guard(ExCCameraFlight::~ExCCameraFlight())
    00038
    00039 UnGuard
    00040 }
    00041
    00042 void ExCCameraFlight::Draw(void)
    00043 {
    00044 Guard(ExCCameraFlight::Draw(void))
    00045         Process();
    00046         if(m_Angle.GetX()<0)m_Angle.SetX(359);
    00047         if(m_Angle.GetX()>359)m_Angle.SetX(0);
    00048         if(m_Angle.GetY()<0)m_Angle.SetY(359);
    00049         if(m_Angle.GetY()>359)m_Angle.SetY(0);
    00050         if(m_Angle.GetZ()<0)m_Angle.SetZ(359);
    00051         if(m_Angle.GetZ()>359)m_Angle.SetZ(0);
    00052
    00053         //315/45
    00054         if(m_Angle.GetZ()>45&&m_Angle.GetZ()<180)m_Angle.SetZ(45);
    00055         if(m_Angle.GetZ()>180&&m_Angle.GetZ()<315)m_Angle.SetZ(315);
    00056
    00057         float cosY,cosP,cosR;
    00058         float sinY,sinP,sinR;
    00059
    00060         cosY=cosf(DegreesToRadians(m_Angle.GetY()));
    00061         cosP=cosf(DegreesToRadians(m_Angle.GetX()));
    00062         cosR=cosf(DegreesToRadians(m_Angle.GetZ()));
    00063
    00064         sinY=sinf(DegreesToRadians(m_Angle.GetY()));
    00065         sinP=sinf(DegreesToRadians(m_Angle.GetX()));
    00066         sinR=sinf(DegreesToRadians(m_Angle.GetZ()));
    00067
    00068         fwd.SetX(sinY*cosP);
    00069         fwd.SetY(sinP);
    00070         fwd.SetZ(cosP*-cosY);
    00071
    00072         m_Target=fwd+m_Position;
    00073
    00074
    00075         m_Up.SetX((-cosY*sinR)-(sinY*sinP*cosR));
    00076         m_Up.SetY(cosP*cosR);
    00077         m_Up.SetZ((-sinY*sinR)-(sinP*cosR*-cosY));
    00078
    00079         gluLookAt(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()
    00080                 ,m_Target.GetX(),m_Target.GetY(),m_Target.GetZ()
    00081                 ,m_Up.GetX(),m_Up.GetY(),m_Up.GetZ());
    00082
    00083         m_Position=m_Position+((m_Target-m_Position)*m_speed);
    00084         //DrawCameraInfo();
    00085 UnGuard
    00086 }
    00087
    00088 void ExCCameraFlight::Process(void)
    00089 {
    00090 Guard(void ExCCameraFlight::Process(void))
    00091         bool    rotate=false;
    00092         for(unsigned i=0;i<m_VecAction.size();i++)
    00093         {
    00094                 switch(m_VecAction.at(i))
    00095                 {
    00096                 case ROTATE_Z_UP:;break;
    00097                 case ROTATE_Y_UP:m_Angle.IncY();m_Angle.DecZ();rotate=true;break;
    00098                 case ROTATE_X_UP:m_Angle.IncX();break;
    00099                 case ROTATE_Z_DOWN:break;
    00100                 case ROTATE_Y_DOWN:m_Angle.DecY();m_Angle.IncZ();rotate=true;break;
    00101                 case ROTATE_X_DOWN:m_Angle.DecX();break;
    00102                 case ZOOM_UP:ZoomOut();break;
    00103                 case ZOOM_DOWN:ZoomIn();break;
    00104                 case SPEED_UP:break;
    00105                 case SPEED_DOWN:break;
    00106                 }
    00107         }
    00108         //nothing happen angle z go to zero
    00109         if(!rotate)
    00110         {
    00111                 if (m_Angle.GetZ()>0&&m_Angle.GetZ()<180&&m_Angle.GetZ()!=0) {m_Angle.DecZ();}
    00112                 if (m_Angle.GetZ()>180&&m_Angle.GetZ()<359&&m_Angle.GetZ()!=0) {m_Angle.IncZ();}
    00113         }
    00114 UnGuard
    00115 }