camera.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2004
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
00021 */
00022 
00023 #ifndef L3_CAMERA_INCLUDED
00024 #define L3_CAMERA_INCLUDED
00025 
00026 #include "../grinliz/glgeometry.h"
00027 #include "../grinliz/glpublisher.h"
00028 #include "worlddefine.h"
00029 
00030 namespace lilith3d
00031 {
00032 
00033 class Camera;
00034 class TimeClock;
00035 class TerrainMesh;
00036 
00037 
00038 class CameraListener : public grinliz::Listener< CameraListener >
00039 {
00040   public:
00041         virtual void CameraEvent( Camera* ) = 0;
00042 };
00043 
00057 class Camera
00058 {
00059   public:
00060         Camera();
00061 
00062         grinliz::Publisher< CameraListener > publish;
00063 
00067         void MoveCamera( float xVelocity, float yVelocity, float zVelocity );
00068         
00072         void MoveCameraAxial2D( float axialVelocity, float perpVelocity );
00073 
00077         void MoveCameraAxial3D( float axialVelocity );
00078 
00079         enum CameraAxis
00080         {
00081                 PITCH,
00082                 YAW             
00083         };
00084 
00086         void MoveCameraRotation( CameraAxis axis, float deltaRotation );
00087 
00089         void SetCameraRotation( float yaw, float pitch );
00090 
00092         void SetCamera( float x, float y, float z, float yaw, float pitch );
00093 
00095         void SetCameraPosition( float x, float y, float z ) {
00096                 SetCamera( x, y, z, CalcYaw(), CalcPitch() );
00097         }
00098 
00100         void PanCamera( float x, float y, float z,  float yaw, float pitch );
00101 
00103         void PanCamera( U32 millisec, float x, float y, float z,  float yaw, float pitch );
00104 
00106         const grinliz::Vector3F&        Eye()           {       return pos.loc; } 
00107 
00111         float CalcPitch();
00115         float CalcYaw();
00116 
00117         const grinliz::Matrix4& RotationMatrix()        { return pos.rot; }
00118 
00120         grinliz::Vector3F Direction() { grinliz::Vector3F dir = { pos.rot.x[0], pos.rot.x[4], pos.rot.x[8] }; return dir; }
00121 
00122         // Update the camera. Called by the engine.
00123         void DoTick( TimeClock* tc, TerrainMesh* tmesh );
00124         // Issue camera commands to OpenGl
00125         void Operate( float farPlaneDistance = FAR_PLANE_DISTANCE );
00126 
00127         void RotationToMatrix( float _yaw, float _pitch, grinliz::Matrix4* matrix );
00128 
00129   private:
00130 
00131         struct Position
00132         {
00133                 grinliz::Vector3F       loc;
00134                 grinliz::Matrix4        rot;
00135 
00136                 void Clamp();
00137         };
00138 
00139         struct Pan
00140         {
00141                 grinliz::Quaternion startQuat;
00142                 grinliz::Vector3F startLoc;
00143                 grinliz::Quaternion endQuat;
00144                 grinliz::Vector3F endLoc;
00145                 U32 startTime;
00146                 U32 endTime;
00147         };
00148 
00149         Position                pos;
00150         Pan                             pan;
00151         bool                    panning;
00152 };
00153 };      // namespace lilith3d
00154 
00155 #endif

Generated on Fri Mar 23 19:36:21 2007 for Lilith3D by  doxygen 1.5.1-p1