1 /***************************************************************************** 2 * $LastChangedDate: 2011-04-09 21:58:06 -0400 (Sat, 09 Apr 2011) $ 3 * @file 4 * @author Jim E. Brooks http://www.palomino3d.org 5 * @brief View class. 6 *//* 7 * LEGAL: COPYRIGHT (C) 2008 JIM E. BROOKS 8 * THIS SOURCE CODE IS RELEASED UNDER THE TERMS 9 * OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2). 10 *****************************************************************************/ 11 12 #ifndef VIEW_VIEW_HH 13 #define VIEW_VIEW_HH 1 14 15 #include "gfx/module.hh" 16 #include "gfx/graphics.hh" 17 #include "gfx/rgba.hh" 18 using namespace gfx; 19 #include "graph/module.hh" 20 using namespace graph; 21 #include "object/module.hh" 22 using namespace object; 23 #include "view/viewpoint.hh" 24 using namespace view; 25 #if ! DOXYGEN 26 namespace osg { class Camera; } 27 #endif 28 29 namespace view { 30 31 //////////////////////////////////////////////////////////////////////////////// 32 /// @brief View class (data struct). 33 /// 34 /// View defines both a 2D viewport and 3D viewpoint. 35 /// The order of rendering Views is the same order Views were attached to Window. 36 /// 37 /// OSG: 38 /// The View class abstracts osg::Camera (not osg::View). 39 /// osg::Camera defines the modelview matrix and viewport 40 /// which is what this View class is supposed to abstract. 41 /// 42 class View : public Shared 43 { 44 PREVENT_COPYING(View) 45 public: 46 View( const bool enable, 47 const Rect<int>& rect, 48 shptr<Viewpoint> viewpoint, 49 RefPtr<osg::Camera> camera = new osg::Camera ); 50 virtual ~View(); 51 52 // Enablement: 53 void Enable( const bool enable = true ); IfEnabled(void)54 bool IfEnabled( void ) { return mEnabled; } 55 CLASS_METHOD void EnableObjectInMainView( Object& object, const bool enableInMainView = true ); 56 57 // View matrix, viewpoint: GetViewMatrix(void)58 const Matrix& GetViewMatrix( void ) { return mViewMatrix; } // modelview 59 void SetViewMatrix( const Matrix& matrix ); // modelview 60 void ComputeViewMatrix( void ); // (for Window) 61 WorldVertex GetPosition( void ); 62 void SetViewpoint( shptr<Viewpoint> viewpoint ); 63 void LookAt( const Vector3& target, const Vector3& viewpoint ); 64 65 // Transformation, projection: TransformWorld2Eye(const WorldVertex & wv)66 EyeVertex TransformWorld2Eye( const WorldVertex& wv ) 67 { CHECK_TYPESIG(this,TYPESIG_VIEW); 68 return wv * mViewMatrix; } // transform world --> eye 69 Vector2 Project( const WorldVertex& wv ); 70 bool IF_Z_FACING( const WorldVertex& wv ); 71 72 // Dimensions: 73 void SetRect( const Rect<int>& rect ); GetRect(void)74 Rect<int> GetRect( void ) 75 { CHECK_TYPESIG(this,TYPESIG_VIEW); 76 return mRect; } 77 // Sprite support: 78 Degree GetRollDegree( void ); 79 80 // Misc: SetOutlineColor(const RGBA outlineColor)81 void SetOutlineColor( const RGBA outlineColor ) 82 { CHECK_TYPESIG(this,TYPESIG_VIEW); 83 mOutlineColor = outlineColor; } GetOutlineColor(void)84 RGBA GetOutlineColor( void ) 85 { CHECK_TYPESIG(this,TYPESIG_VIEW); 86 return mOutlineColor; } 87 88 // OSG (LIMITED USE): OsgGetCamera(void)89 RefPtr<osg::Camera> OsgGetCamera( void ) 90 { CHECK_TYPESIG(this,TYPESIG_VIEW); 91 return mCamera; } 92 // Data: 93 private: 94 bool mEnabled; ///< if false, not rendered 95 Rect<int> mRect; ///< will change by reshape event 96 shptr<Viewpoint> mViewpoint; ///< computes view matrix 97 RefPtr<osg::Camera> mCamera; ///< correlates to OpenGL modelview matrix 98 Matrix mViewMatrix; ///< modelview matrix 99 Matrix mProjectionMatrix; ///< 3D --> 2D projection 100 bool mComputedViewMatrix; ///< if ComputeViewMatrix() was ever called 101 Degree mRollDegree; ///< supports Sprites 102 RGBA mOutlineColor; ///< outline is draw around 2D viewpoint 103 public: 104 DECLARE_TYPESIG(TYPESIG_VIEW) 105 }; 106 107 } // namespace view 108 109 #endif // VIEW_VIEW_HH 110