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

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

Généré le Tue Oct 28 12:43:30 2003 pour ExNihilo par doxygen 1.3.4