00001 00011 /*************************************************************************** 00012 * Copyright (C) 2007 by Jan Koci * 00013 * honza.koci@email.cz * 00014 * http://kengine.sourceforge.net/tutorial/ 00015 * * 00016 * This program is free software; you can redistribute it and/or modify * 00017 * it under the terms of the GNU General Public License as published by * 00018 * the Free Software Foundation; either version 2 of the License, or * 00019 * (at your option) any later version. * 00020 * * 00021 * This program is distributed in the hope that it will be useful, * 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00024 * GNU General Public License for more details. * 00025 * * 00026 * You should have received a copy of the GNU General Public License * 00027 * along with this program; if not, write to the * 00028 * Free Software Foundation, Inc., * 00029 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00030 ***************************************************************************/ 00031 00032 #pragma once 00033 00034 #include "../Control/K3dMouse.h" 00035 #include "../Control/K3dKeyMap.h" 00036 #include "../GLRenderer/K3dOpenGL.h" 00037 #include "../MathCore/K3dVector3.h" 00038 #include "../MathCore/K3dMatrix.h" 00039 #include "../MathCore/K3dQuaternion.h" 00040 #include "../System/K3dTimer.h" 00041 #include "../System/Worker/K3dVector3Work.h" 00042 00043 00044 enum ECameraView 00045 { 00046 K_CAM_FIRST_PERSON=0, 00047 K_CAM_SPECTATE, 00048 K_CAM_DESCENT 00049 }; 00050 00051 class K3dCamera 00052 { 00053 K3dGameData *m_pGameData; 00054 K3dVector3Work *m_pVector3Work; 00055 K3dVector3Obj m_kPosition; 00056 K3dVector3Obj m_kForward; 00057 K3dVector3Obj m_kUp; 00058 K3dVector3Obj m_kRight; 00059 K3dVector3Obj m_kView; 00060 K3dMatrix m_kMatrix; 00061 K3dMatrix m_kPrevMatrix; 00062 K3dMatrix m_kRotMatrix; 00063 bool m_bIsMouseMove; 00064 ECameraView m_eCamView; 00065 K3dVector3Obj m_kAngle; 00066 float m_fSpeed; 00067 float m_fSpeedAccel; 00068 00069 00070 void Move ( const float _fSpeed ); 00071 void Init(); 00072 void SetStrafeDirection(); 00073 00074 public: 00075 K3dCamera ( K3dGameData *_pGameData ); 00076 ~K3dCamera(); 00077 00079 ECameraView &GetCameraView() 00080 { 00081 return m_eCamView; 00082 } 00083 00085 float &GetCameraSpeed() 00086 { 00087 return m_fSpeedAccel; 00088 } 00089 00091 K3dVector3Obj &GetCameraPos() 00092 { 00093 return m_kPosition; 00094 } 00095 00097 K3dVector3Obj &GetCameraRot() 00098 { 00099 return m_kAngle; 00100 } 00101 00103 bool &GetIsMouseMove() 00104 { 00105 return m_bIsMouseMove; 00106 } 00107 00108 K3dVector3Obj& GetPosition(); 00109 const K3dVector3Obj& GetPosition() const; 00110 K3dVector3Obj& GetForward(); 00111 const K3dVector3Obj& GetForward() const; 00112 K3dVector3Obj& GetView() 00113 { 00114 return m_kView; 00115 } 00116 const K3dVector3Obj& GetView() const 00117 { 00118 return m_kView; 00119 } 00120 K3dMatrix& GetMatrix(); 00121 const K3dMatrix& GetMatrix() const; 00122 K3dMatrix& GetRotMatrix(); 00123 const K3dMatrix& GetRotMatrix() const; 00124 K3dMatrix& GetPrevMatrix(); 00125 const K3dMatrix& GetPrevMatrix() const; 00126 K3dVector3Obj& GetUp(); 00127 const K3dVector3Obj &GetUp() const; 00128 K3dVector3Obj& GetRight(); 00129 const K3dVector3Obj &GetRight() const; 00130 00131 void UpdateCamera(); 00132 void Look(); 00133 void GoForward(); 00134 void GoBackward(); 00135 void GoUp(); 00136 void GoDown(); 00137 void StrafeLeft(); 00138 void StrafeRight(); 00139 void TurnLeft(); 00140 void TurnRight(); 00141 void TurnUp(); 00142 void TurnDown(); 00143 void LurchLeft(); 00144 void LurchRight(); 00145 void MouseRotate(); 00146 void RestrictCamView(); 00147 void ChangeMatrix(); 00148 };