Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   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.7 2002/07/10 11:09:46 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=2000;
00039         m_ClipNear=1;
00040 
00041         m_vPosition.SetValue(0.0,0.0,1.0);
00042         m_vView.SetValue(0.0,1.0,0.5);
00043         m_vUpVector.SetValue(0.0,0.0,1.0);
00044 UnGuard
00045 }
00046 
00047 ExCCamera::~ExCCamera(void)
00048 {
00049 Guard(ExCCamera::~ExCCamera(void))
00050 UnGuard
00051 }
00052 
00053 void ExCCamera::Draw(void)
00054 {
00055 Guard(ExCCamera::Draw(void))
00056 //cout<<"Draw "<<m_ObjectName<<" ID:"<<m_ObjectId<<endl;
00057 
00058         if(m_AngleX<0)m_AngleX=359;
00059         if(m_AngleX>359)m_AngleX=0;
00060         if(m_AngleY<0)m_AngleY=359;
00061         if(m_AngleY>359)m_AngleY=0;
00062         if(m_AngleZ<0)m_AngleZ=359;
00063         if(m_AngleZ>359)m_AngleZ=0;
00064 
00065         ExCMatrix4x4 Matrice,Matr;
00066         //ExCVec3D VecX,VecY,VecZ,VecDir;
00067 
00068         ExQuaternion Quat;
00069         
00070         
00071         Quat.SetEuler(m_AngleX,m_AngleY,m_AngleZ);
00072         Matr=GetMatrixFromQuaternion(Quat);
00073         
00074         //Matr=GetMatrixFromEuler(m_AngleX,m_AngleY,m_AngleZ);
00075 
00076 
00077         //glLoadMatrixf(Matr.m_Matrix); 
00078         
00079         /*glRotatef(m_AngleX,1.0,0.0,0.0);
00080         glRotatef(m_AngleY,0.0,1.0,0.0);
00081         glLoadIdentity();
00082         glLoadMatrixf(Matr.m_Matrix);
00083         cout<<Matr;
00084         cout<<Quat;*/
00085         
00086         VecX.m_Vector[0]=Matr.m_Matrix[0];
00087         VecX.m_Vector[1]=Matr.m_Matrix[1];
00088         VecX.m_Vector[2]=Matr.m_Matrix[2];
00089         VecY.m_Vector[0]=Matr.m_Matrix[4];
00090         VecY.m_Vector[1]=Matr.m_Matrix[5];
00091         VecY.m_Vector[2]=Matr.m_Matrix[6];
00092         VecZ.m_Vector[0]=Matr.m_Matrix[8];
00093         VecZ.m_Vector[1]=Matr.m_Matrix[9];
00094         VecZ.m_Vector[2]=Matr.m_Matrix[10];
00095 
00096         VecDir.m_Vector[0]=VecX.GetVectorLenght();
00097         VecDir.m_Vector[1]=VecY.GetVectorLenght();
00098         VecDir.m_Vector[2]=VecZ.GetVectorLenght();
00099 
00100         //cout<<VecDir<<endl;
00101         //glGetFloatv(GL_MODELVIEW_MATRIX,
00102         
00103         //glTranslatef(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()); 
00104         if(m_speed!=0)
00105         {
00106                 for(int i=0;i<m_speed;i++)
00107                 {
00108                         GoToView(true);
00109                 }
00110         }else
00111         {
00112         m_Target.SetX((Cos[(int)m_AngleY]+m_Position.GetX()));
00113         m_Target.SetZ((Sin[(int)m_AngleY]+m_Position.GetZ()));
00114         m_Target.SetY((Sin[(int)m_AngleX]+m_Position.GetY()));
00115         }
00116         //glRotatef(m_AngleZ,0.0,0.0,1.0);
00117         gluLookAt(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ()
00118                         ,m_Target.GetX(),m_Target.GetY(),m_Target.GetZ()
00119                         ,0.0,1.0,0.0);
00120         
00121 UnGuard
00122 }
00123 
00124 void ExCCamera::GoToView(bool state)
00125 {
00126 Guard(void ExCCamera::GoToView(void))
00127         //bool GoodY=true; // not used
00128         m_Position=m_Target;
00129         m_Target.SetX((Cos[(int)m_AngleY]+m_Position.GetX()));
00130         m_Target.SetZ((Sin[(int)m_AngleY]+m_Position.GetZ()));
00131         m_Target.SetY((Sin[(int)m_AngleX]+m_Position.GetY()));
00132 
00133 UnGuard
00134 }
00135 
00136 void ExCCamera::ResetZoom(void)
00137 {
00138 Guard(void ExCCamera::ResetZoom(void))
00139         m_Zoom=m_ZoomDefault;
00140 UnGuard
00141 }
00142 
00143 void ExCCamera::SetZoomDefault(float zoom)
00144 {
00145 Guard(void ExCCamera:: SetZoomDefault(float zoom))
00146         if(zoom<m_ZoomMax&&zoom>m_ZoomMin)
00147                 m_ZoomDefault=zoom;
00148 UnGuard
00149 }
00150 
00151 void ExCCamera::ZoomIn(void)
00152 {
00153 Guard(void ExCCamera::ZoomIn(void))
00154         m_Zoom--;
00155         if(m_Zoom<=m_ZoomMin)m_Zoom=m_ZoomMin+1;
00156 UnGuard
00157 }
00158 
00159 void ExCCamera::ZoomOut(void)
00160 {
00161 Guard(void ExCCamera::ZoomOut(void))
00162         m_Zoom++;
00163         if(m_Zoom>=m_ZoomMax)m_Zoom=m_ZoomMax-1;
00164 UnGuard
00165 }
00166 
00167 void ExCCamera::ZoomIn(float zoom)
00168 {
00169 Guard(void ExCCamera::ZoomIn(float zoom))
00170         m_Zoom=m_Zoom-zoom;
00171         if(m_Zoom<=m_ZoomMin)m_Zoom=m_ZoomMin+1;
00172 UnGuard
00173 }
00174 
00175 void ExCCamera::ZoomOut(float zoom)
00176 {
00177 Guard(void ExCCamera::ZoomOut(float zoom))
00178         m_Zoom=m_Zoom+m_ZoomMax;
00179         if(m_Zoom>=m_ZoomMax)m_Zoom=m_ZoomMax-1;
00180 UnGuard
00181 }
00182 
00183 void ExCCamera::SetZoom(float zoom)
00184 {
00185 Guard(void ExCCamera::SetZoom(float zoom))
00186 UnGuard
00187 }
00188 
00189 void ExCCamera::SetZoomMax(float zoom)
00190 {
00191 Guard(void ExCCamera::SetZoomMax(float zoom))
00192 UnGuard
00193 }
00194 
00195 void ExCCamera::SetZoomMin(float zoom)
00196 {
00197 Guard(void ExCCamera::SetZoomMin(float zoom))
00198 UnGuard
00199 }
00200 
00201 void ExCCamera::SetClipFar(float clip)
00202 {
00203         Guard(void ExCCamera::SetClipFar(float clip))
00204         m_ClipFar=clip;
00205         if(m_ClipFar<m_ClipNear)m_ClipFar=m_ClipNear+1;
00206 UnGuard
00207 }
00208 
00209 void ExCCamera::SetClipNear(float clip)
00210 {
00211         Guard(void ExCCamera::SetClipNear(float clip))
00212         m_ClipNear=clip;
00213         if(m_ClipNear>m_ClipFar)m_ClipNear=m_ClipFar-1;
00214 UnGuard
00215 }
00216 
00217 void ExCCamera::RotateView(float X, float Y, float Z)
00218 {
00219 Guard(void ExCCamera::RotateView(float X, float Y, float Z))
00220         ExCVec3D vVector;                                                       // Vector for the position/view.
00221 
00222         // Get our view vVector (The direction we are facing)
00223         vVector.m_Vector[0] = m_vView.m_Vector[0] - m_vPosition.m_Vector[0];            // This gets the direction of the X     
00224         vVector.m_Vector[1] = m_vView.m_Vector[1] - m_vPosition.m_Vector[1];            // This gets the direction of the Y
00225         vVector.m_Vector[2]= m_vView.m_Vector[2] - m_vPosition.m_Vector[2];             // This gets the direction of the Z
00226 
00227         // If we pass in a negative X Y or Z, it will rotate the opposite way,
00228         // so we only need one function for a left and right , up or down rotation.
00229         // I suppose we could have one move function too, but I decided not too.
00230 
00231         if(X) {
00232                 m_vView.m_Vector[2] = (float)(m_vPosition.m_Vector[2] + sin(X)*vVector.m_Vector[1] + cos(X)*vVector.m_Vector[2]);
00233                 m_vView.m_Vector[1] = (float)(m_vPosition.m_Vector[1] + cos(X)*vVector.m_Vector[1] - sin(X)*vVector.m_Vector[2]);
00234         }
00235         if(Y) {
00236                 m_vView.m_Vector[2] = (float)(m_vPosition.m_Vector[2] + sin(Y)*vVector.m_Vector[0] + cos(Y)*vVector.m_Vector[2]);
00237                 m_vView.m_Vector[0] = (float)(m_vPosition.m_Vector[0] + cos(Y)*vVector.m_Vector[0] - sin(Y)*vVector.m_Vector[2]);
00238         }
00239         if(Z) {
00240                 m_vView.m_Vector[0] = (float)(m_vPosition.m_Vector[0] + sin(Z)*vVector.m_Vector[1] + cos(Z)*vVector.m_Vector[0]);               
00241                 m_vView.m_Vector[1] = (float)(m_vPosition.m_Vector[1] + cos(Z)*vVector.m_Vector[1] - sin(Z)*vVector.m_Vector[0]);
00242         }
00243 UnGuard
00244 }
00245 
00246 void ExCCamera::StrafeCamera(float speed)
00247 {
00248 Guard(void ExCCamera::StrafeCamera(float speed))
00249 
00250 UnGuard
00251 }
00252 
00253 void ExCCamera::MoveCamera(float speed)
00254 {
00255 Guard(void ExCCamera::MoveCamera(float speed))
00256         ExCVec3D vVector;                                       // Init a vVector for our view
00257 
00258         // Get our view vVector (The direciton we are facing)
00259         vVector.m_Vector[0] = m_vView.m_Vector[0] - m_vPosition.m_Vector[0];            // This gets the direction of the X     
00260         vVector.m_Vector[1] = m_vView.m_Vector[1] - m_vPosition.m_Vector[1];            // This gets the direction of the Y
00261         vVector.m_Vector[2] = m_vView.m_Vector[2] - m_vPosition.m_Vector[2];            // This gets the direction of the Z
00262 
00263         m_vPosition.m_Vector[0] += vVector.m_Vector[0] * speed;         // Add our acceleration to our position's X
00264         m_vPosition.m_Vector[2] += vVector.m_Vector[2] * speed;         // Add our acceleration to our position's Z
00265         m_vView.m_Vector[0] += vVector.m_Vector[0] * speed;                     // Add our acceleration to our view's X
00266         m_vView.m_Vector[2] += vVector.m_Vector[2] * speed;                     // Add our acceleration to our view's Z
00267 UnGuard
00268 }
00269 

Generated on Tue Aug 6 20:27:05 2002 for ExNihilo by doxygen1.2.17