Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Camera.h

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020     
00021     $Id: Camera.h,v 1.8 2002/02/16 12:41:39 tksuoran Exp $
00022 */
00023 
00024 
00025 #ifndef TEDDY__SCENES__CAMERA__H
00026 #define TEDDY__SCENES__CAMERA__H
00027 
00028 
00029 #include "Teddy/Maths/Vector.h"
00030 #include "Teddy/Maths/Vector2.h"
00031 #include "Teddy/Maths/Rect.h"
00032 #include "Teddy/Maths/Plane.h"
00033 #include "Teddy/Models/Model.h"
00034 #include "Teddy/SysSupport/Types.h"
00035 
00036 
00037 //  Forward declarations
00038 namespace Teddy {
00039     namespace PhysicalComponents { class Projection; };
00040 };
00041 
00042 
00043 namespace Teddy  {
00044 namespace Scenes {
00045 
00046 
00047 class Scene;
00048 
00049 
00050 #define MSD 32 
00051 
00052 
00060 class Camera : public Teddy::Models::Model {
00061 public:
00062     Camera( const std::string &name, Teddy::Scenes::Scene *scene );
00063 
00064     Teddy::Models::Model        *pick        ( Teddy::PhysicalComponents::Projection *p, const Teddy::Maths::TVector2<int> &pos );
00065     virtual void  projectScene( Teddy::PhysicalComponents::Projection *p );
00066 
00067     void     setMirrorX          ( const bool mirror_x );
00068     void     setNearFar          ( const float near_clip, const float far_clip );
00069     double   getNear             ();
00070     double   getFar              ();
00071     void     setFov              ( const float fov );
00072     float    getFov              () const;
00073     void     modFov              ( const float mod );
00074     void     setScene            ( Teddy::Scenes::Scene *scene );
00075     Scene   *getScene            () const;
00076     void     updatePlanes        ();
00077     bool     cull                ( const Teddy::Models::Model &mi );
00078 
00079     Teddy::Maths::Matrix           getFrustumMatrix    ( const float left, const float right, const float bottom, const float top, const float nearval, const float farval ) const;
00080     Teddy::Maths::Matrix           getPerspectiveMatrix( const float fovy, const float aspect, const float zNear,  const float zFar ) const;
00081     Teddy::Maths::Matrix           getPickMatrix       ( const Teddy::Maths::TVector2<int> &pos, const Teddy::Maths::TVector2<int> &size, const Teddy::Maths::TRect<int> &viewport ) const;
00082     Teddy::Maths::TVector4<float>  projectVector       ( const Teddy::Maths::TVector4<float> &v ) const;
00083 
00084     void     doProjection        ( Teddy::PhysicalComponents::Projection *p, const bool load_matrix = true );
00085     void     doCamera            ( Teddy::PhysicalComponents::Projection *p, const bool load_matrix = true );
00086     void     doObjectMatrix      ( Teddy::PhysicalComponents::Projection *p, const Teddy::Maths::Matrix &m, const bool load_matrix = true );
00087     void     pushObjectMatrix    ();
00088     void     popObjectMatrix     ();
00089 
00090     void     updateFrustum       ();
00091     bool     cullPoint           ( const Teddy::Maths::TVector<float> &v ) const;
00092     bool     cullSphere          ( const Teddy::Maths::TVector<float> &v, const float radius ) const;
00093     bool     cullAABox           ( const Teddy::Maths::TVector<float> &pos, const Teddy::Maths::TVector<float> &size );
00094 
00095 #if 0
00096 public:
00097     int         debug_index;
00098     double      debug_double[32][6];
00099     Vector      debug_vector[32];
00100     Matrix      debug_matrix[32];
00101 #endif
00102 
00103 protected:
00104     Teddy::Scenes::Scene                  *scene;                   
00105     Teddy::PhysicalComponents::Projection *active_projection;       
00106     Teddy::Maths::Matrix                   to_screen_s_matrix;      
00107     Teddy::Maths::Matrix                   view_matrix;             
00108     Teddy::Maths::Matrix                   projection_matrix;       
00109     Teddy::Maths::Matrix                   model_view_matrix[MSD];  
00110     Teddy::Maths::TRect<int>               rect;
00111     Teddy::Maths::Plane                    view_plane[6];           
00112     int                                    model_view_matrix_sp;    
00113     double                                 near_clip;               
00114     double                                 far_clip;                
00115     double                                 fov;                     
00116     float                                  frustum[6][4];           // Holds The Current Frustum Plane Equations
00117     bool                                   mirror_x;                
00118     bool                                   projection_dirty;        
00119 };
00120 
00121 
00122 };  //  namespace Scenes
00123 };  //  namespace Teddy
00124 
00125 
00126 #endif  //  TEDDY__SCENES__CAMERA_H
00127