00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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];
00117 bool mirror_x;
00118 bool projection_dirty;
00119 };
00120
00121
00122 };
00123 };
00124
00125
00126 #endif // TEDDY__SCENES__CAMERA_H
00127