Main Page Namespace List Class Hierarchy Alphabetical List Data Structures File List Namespace Members Data Fields Globals

# ExCCameraChase.cpp

Go to the documentation of this file.

    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_AngleAround=0;
    00033         m_AngleFromBase=4;
    00034         m_DistanceFromTarget=14.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         if(m_AngleX<0)m_AngleX=359;
    00048         if(m_AngleX>359)m_AngleX=0;
    00049         if(m_AngleY<0)m_AngleY=359;
    00050         if(m_AngleY>359)m_AngleY=0;
    00051         if(m_AngleZ<0)m_AngleZ=359;
    00052         if(m_AngleZ>359)m_AngleZ=0;
    00053
    00054         m_TargetPosition=ManagerModel->GetCurrentObject()->GetPosition();
    00055 //Le cote adjacent = cos(angle) * hypotenuse
    00056 //Le cote oppose = tan(angle) * hypotenuse
    00057         //m_Position.SetX(-(Cos[m_AngleFromBase]*m_DistanceFromTarget));
    00058         //m_Position.SetY(tan(m_AngleFromBase)*m_DistanceFromTarget);
    00059
    00060 /*      m_Position.SetX(-25);
    00061         m_Position.SetY(12);
    00062
    00063
    00064         m_Position.SetZ(-2.5f);
    00065
    00066         int tmp=m_Position.GetX()*Cos[(int)m_AngleX];
    00067         m_Position.SetZ(-25-tmp);
    00068         m_Position.SetX(tmp);
    00069
    00070
    00071
    00072         m_Position=m_Position+m_TargetPosition;
    00073
    00074
    00075         m_Target=ManagerModel->GetCurrentObject()->GetPosition();
    00076         //m_Target.SetZ(m_Target.GetZ()-2.5f);
    00077     gluLookAt(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()
    00078                         ,m_Target.GetX(),m_Target.GetY(),m_Target.GetZ()
    00079                         ,0.0,1.0,0.0);
    00080         m_Position.SetValue(0.0f,0.0f,0.0f);
    00081   */
    00082
    00083         float cosY,cosP,cosR;
    00084         float sinY,sinP,sinR;
    00085
    00086         cosY=cosf(DegreesToRadians(m_AngleY));
    00087         cosP=cosf(DegreesToRadians(m_AngleX));
    00088         cosR=cosf(DegreesToRadians(m_AngleZ));
    00089
    00090         sinY=sinf(DegreesToRadians(m_AngleY));
    00091         sinP=sinf(DegreesToRadians(m_AngleX));
    00092         sinR=sinf(DegreesToRadians(m_AngleZ));
    00093
    00094         ExCVec3D fwd,side;
    00095
    00096         fwd.SetX(sinY*cosP);
    00097         fwd.SetY(sinP);
    00098         fwd.SetZ(cosP*-cosY);
    00099
    00100         //m_Target=fwd+m_Position;
    00101
    00102
    00103         m_Target=fwd+ManagerModel->GetCurrentObject()->GetPosition();
    00104
    00105         m_Position.SetX(-25+m_Target.GetX());
    00106         m_Position.SetY(12+m_Target.GetY());
    00107
    00108         m_Up.SetX((-cosY*sinR)-(sinY*sinP*cosR));
    00109         m_Up.SetY(cosP*cosR);
    00110         m_Up.SetZ((-sinY*sinR)-(sinP*cosR*-cosY));
    00111
    00112         char buff[255];
    00113         memset(buff,0,255);
    00114         sprintf(buff,"Camera position X:%f Y:%f Z:%f",m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
    00115         ExNihilo::WriteToScreen(30,540,buff);
    00116         memset(buff,0,255);
    00117         sprintf(buff,"Camera fwd X:%f Y:%f Z:%f",fwd.GetX(),fwd.GetY(),fwd.GetZ());
    00118         ExNihilo::WriteToScreen(30,560,buff);
    00119         memset(buff,0,255);
    00120         sprintf(buff,"Camera target X:%f Y:%f Z:%f",m_Target.GetX(),m_Target.GetY(),m_Target.GetZ());
    00121         ExNihilo::WriteToScreen(30,580,buff);
    00122
    00123
    00124         gluLookAt(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()
    00125                         ,m_Target.GetX(),m_Target.GetY(),m_Target.GetZ()
    00126                         ,m_Up.GetX(),m_Up.GetY(),m_Up.GetZ());
    00127
    00128         //m_Position=m_Position+((m_Target-m_Position)*m_speed);
    00129
    00130 UnGuard
    00131 }