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

# ExCCamera.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: ExCCamera.cpp,v 1.12 2002/11/24 11:59:00 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCCamera.h"
    00025
    00026
    00027 ExCCamera::ExCCamera(void)
    00028 {
    00029 Guard(ExCCamera::ExCCamera(void))
    00030         m_AngleX=0;
    00031         m_AngleY=0;
    00032         m_AngleZ=0;
    00033         m_speed=0;
    00034         m_ZoomDefault=40;
    00035         m_Zoom=m_ZoomDefault;
    00036         m_ZoomMin=1;
    00037         m_ZoomMax=100;
    00038         m_ClipFar=100000000;
    00039         m_ClipNear=1;
    00040         SetName("ExCCamera");
    00041         SetType(typeid(this).name());
    00042 UnGuard
    00043 }
    00044
    00045 ExCCamera::~ExCCamera(void)
    00046 {
    00047 Guard(ExCCamera::~ExCCamera(void))
    00048 UnGuard
    00049 }
    00050
    00051 void ExCCamera::Draw(void)
    00052 {
    00053 Guard(ExCCamera::Draw(void))
    00054 //cout<<"Draw "<<m_ObjectName<<" ID:"<<m_ObjectId<<endl;
    00055         Process();
    00056
    00057         if(m_AngleX<0)m_AngleX=359;
    00058         if(m_AngleX>359)m_AngleX=0;
    00059         if(m_AngleY<0)m_AngleY=359;
    00060         if(m_AngleY>359)m_AngleY=0;
    00061         if(m_AngleZ<0)m_AngleZ=359;
    00062         if(m_AngleZ>359)m_AngleZ=0;
    00063
    00064         float cosY,cosP,cosR;
    00065         float sinY,sinP,sinR;
    00066
    00067         cosY=cosf(DegreesToRadians(m_AngleY));
    00068         cosP=cosf(DegreesToRadians(m_AngleX));
    00069         cosR=cosf(DegreesToRadians(m_AngleZ));
    00070
    00071         sinY=sinf(DegreesToRadians(m_AngleY));
    00072         sinP=sinf(DegreesToRadians(m_AngleX));
    00073         sinR=sinf(DegreesToRadians(m_AngleZ));
    00074
    00075         ExCVec3D fwd,side;
    00076
    00077         fwd.SetX(sinY*cosP);
    00078         fwd.SetY(sinP);
    00079         fwd.SetZ(cosP*-cosY);
    00080
    00081         m_Target=fwd+m_Position;
    00082
    00083
    00084         m_Up.SetX((-cosY*sinR)-(sinY*sinP*cosR));
    00085         m_Up.SetY(cosP*cosR);
    00086         m_Up.SetZ((-sinY*sinR)-(sinP*cosR*-cosY));
    00087
    00088    /*   char buff[255];
    00089         memset(buff,0,255);
    00090         sprintf(buff,"Camera position X:%f Y:%f Z:%f",m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
    00091         ExNihilo::WriteToScreen(30,540,buff);
    00092         memset(buff,0,255);
    00093         sprintf(buff,"Camera fwd X:%f Y:%f Z:%f",fwd.GetX(),fwd.GetY(),fwd.GetZ());
    00094         ExNihilo::WriteToScreen(30,560,buff);
    00095         memset(buff,0,255);
    00096         sprintf(buff,"Camera target X:%f Y:%f Z:%f",m_Target.GetX(),m_Target.GetY(),m_Target.GetZ());
    00097         ExNihilo::WriteToScreen(30,580,buff);
    00098         memset(buff,0,255);
    00099         sprintf(buff,"Camera angle X:%f Y:%f Z:%f",m_AngleX,m_AngleY,m_AngleZ);
    00100         ExNihilo::WriteToScreen(30,600,buff);
    00101  */
    00102         gluLookAt(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()
    00103                         ,m_Target.GetX(),m_Target.GetY(),m_Target.GetZ()
    00104                         ,m_Up.GetX(),m_Up.GetY(),m_Up.GetZ());
    00105
    00106         m_Position=m_Position+((m_Target-m_Position)*m_speed);
    00107
    00108 UnGuard
    00109 }
    00110
    00111 void ExCCamera::ResetZoom(void)
    00112 {
    00113 Guard(void ExCCamera::ResetZoom(void))
    00114         m_Zoom=m_ZoomDefault;
    00115 UnGuard
    00116 }
    00117
    00118 void ExCCamera::SetZoomDefault(float zoom)
    00119 {
    00120 Guard(void ExCCamera:: SetZoomDefault(float zoom))
    00121         if(zoom<m_ZoomMax&&zoom>m_ZoomMin)
    00122                 m_ZoomDefault=zoom;
    00123 UnGuard
    00124 }
    00125
    00126 void ExCCamera::ZoomIn(void)
    00127 {
    00128 Guard(void ExCCamera::ZoomIn(void))
    00129         m_Zoom--;
    00130         if(m_Zoom<=m_ZoomMin)m_Zoom=m_ZoomMin+1;
    00131 UnGuard
    00132 }
    00133
    00134 void ExCCamera::ZoomOut(void)
    00135 {
    00136 Guard(void ExCCamera::ZoomOut(void))
    00137         m_Zoom++;
    00138         if(m_Zoom>=m_ZoomMax)m_Zoom=m_ZoomMax-1;
    00139 UnGuard
    00140 }
    00141
    00142 void ExCCamera::ZoomIn(float zoom)
    00143 {
    00144 Guard(void ExCCamera::ZoomIn(float zoom))
    00145         m_Zoom=m_Zoom-zoom;
    00146         if(m_Zoom<=m_ZoomMin)m_Zoom=m_ZoomMin+1;
    00147 UnGuard
    00148 }
    00149
    00150 void ExCCamera::ZoomOut(float zoom)
    00151 {
    00152 Guard(void ExCCamera::ZoomOut(float zoom))
    00153         m_Zoom=m_Zoom+m_ZoomMax;
    00154         if(m_Zoom>=m_ZoomMax)m_Zoom=m_ZoomMax-1;
    00155 UnGuard
    00156 }
    00157
    00158 void ExCCamera::SetZoom(float zoom)
    00159 {
    00160 Guard(void ExCCamera::SetZoom(float zoom))
    00161 UnGuard
    00162 }
    00163
    00164 void ExCCamera::SetZoomMax(float zoom)
    00165 {
    00166 Guard(void ExCCamera::SetZoomMax(float zoom))
    00167 UnGuard
    00168 }
    00169
    00170 void ExCCamera::SetZoomMin(float zoom)
    00171 {
    00172 Guard(void ExCCamera::SetZoomMin(float zoom))
    00173 UnGuard
    00174 }
    00175
    00176 void ExCCamera::SetClipFar(float clip)
    00177 {
    00178         Guard(void ExCCamera::SetClipFar(float clip))
    00179         m_ClipFar=clip;
    00180         if(m_ClipFar<m_ClipNear)m_ClipFar=m_ClipNear+1;
    00181 UnGuard
    00182 }
    00183
    00184 void ExCCamera::SetClipNear(float clip)
    00185 {
    00186         Guard(void ExCCamera::SetClipNear(float clip))
    00187         m_ClipNear=clip;
    00188         if(m_ClipNear>m_ClipFar)m_ClipNear=m_ClipFar-1;
    00189 UnGuard
    00190 }
    00191
    00192 void ExCCamera::Process(void)
    00193 {
    00194 Guard(void ExCCamera::Process(void))
    00195         for(unsigned i=0;i<m_VecAction.size();i++)
    00196         {
    00197                 switch(m_VecAction.at(i))
    00198                 {
    00199                 case ROTATE_Z_UP:m_AngleZ++;break;
    00200                 case ROTATE_Y_UP:m_AngleY++;break;
    00201                 case ROTATE_X_UP:m_AngleX++;break;
    00202                 case ROTATE_Z_DOWN:m_AngleZ--;break;
    00203                 case ROTATE_Y_DOWN:m_AngleY--;break;
    00204                 case ROTATE_X_DOWN:m_AngleX--;break;
    00205                 case ZOOM_UP:ZoomOut();break;
    00206                 case ZOOM_DOWN:ZoomIn();break;
    00207                 case SPEED_UP:break;
    00208                 case SPEED_DOWN:break;
    00209                 }
    00210         }
    00211 UnGuard
    00212 }
    00213
    00214 void ExCCamera::StartAction(int Action)
    00215 {
    00216 Guard(void ExCCamera::StartAction(int Action))
    00217         m_VecAction.push_back(Action);
    00218 UnGuard
    00219 }
    00220
    00221 void ExCCamera::StopAction(int Action)
    00222 {
    00223 Guard(void ExCCamera::StopAction(int Action))
    00224         for(m_ItVecAction=m_VecAction.begin();m_ItVecAction!=m_VecAction.end();m_ItVecAction++)
    00225         {
    00226                 if(*m_ItVecAction==Action){m_VecAction.erase(m_ItVecAction);return;}
    00227         }
    00228 UnGuard
    00229 }