core/vgui/vgui_loader_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_loader_tableau.h
00002 #ifndef vgui_loader_tableau_h_
00003 #define vgui_loader_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau where the user can set the projection and modelview matrices.
00010 // \author Geoffrey Cross, Oxford RRG
00011 // \date   03 Nov 99
00012 //
00013 //  Contains classes  vgui_loader_tableau   vgui_loader_tableau_new
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   03-Nov-1999 Geoff Initial version.
00018 //   04-Jan-2000 fsm. added set_ortho(), thereby obsoleting
00019 //                           view_section and view_volume.
00020 //   05-Jan-2000 fsm. added set_identity(), thereby obsoleting
00021 //                           reset_matrix_state.
00022 //   14-Aug-2002 K.Y.McGaul - Changed to and added Doxygen style comments.
00023 //   01-OCT-2002 K.Y.McGaul - Moved vgui_load to vgui_loader_tableau.
00024 // \endverbatim
00025 
00026 #include <vnl/vnl_fwd.h>
00027 #include <vgui/vgui_loader_tableau_sptr.h>
00028 #include <vgui/vgui_wrapper_tableau.h>
00029 
00030 //: Tableau where the user can set the projection and modelview matrices.
00031 //
00032 //  Class vgui_loader_tableau is a tableau which (optionally) loads given values
00033 //  for the projection and modelview matrices before passing control to
00034 //  its child. This is typically used to initialize GL before rendering a
00035 //  scene.
00036 class vgui_loader_tableau : public vgui_wrapper_tableau
00037 {
00038  public:
00039 
00040   //: Constructor - don't use this, use vgui_loader_tableau_new.
00041   //  Takes the single child tableau as a parameter.
00042   vgui_loader_tableau(vgui_tableau_sptr const& child);
00043 
00044   //: Returns the type of this tableau ('vgui_loader_tableau').
00045   vcl_string type_name() const;
00046 
00047   //: Set the projection matrix to the given matrix.
00048   void set_projection(vnl_matrix_fixed<double,4,4> const &m);
00049 
00050   //: Set the modelview matrix to the given matrix.
00051   void set_modelview(vnl_matrix_fixed<double,4,4> const &m);
00052 
00053   //: Unset the projection matrix.
00054   void unset_projection();
00055 
00056   //: Unset the modelview matrix.
00057   void unset_modelview();
00058 
00059   //: Set projection and modalview matrices to the identity matrix.
00060   //  Calling this method is equivalent to calling set_projection(I) and
00061   //  set_modelview(I) with I an identity matrix.
00062   void set_identity();
00063 
00064   //: Set projection matrix to identity and modelview matrix using glOrtho().
00065   // These easy methods set the projection matrix to the identity and the
00066   // modelview matrix using glOrtho(). In each case, the coordinates given
00067   // are the desired coordinates of the viewport/render-volume corners.
00068   // Eg. to view an image which is w-by-h, one might use
00069   //   l.set_ortho(0,h, w,0);
00070   // unless one wants the image upside down.
00071   void set_ortho(float x1, float y1, // bottom, left
00072                  float x2, float y2);// top, right
00073 
00074   //: Set projection matrix to identity and modelview matrix using glOrtho().
00075   void set_ortho(float x1,float y1,float z1, // bottom, left hand, far corner.
00076                  float x2,float y2,float z2);// top, right hand, near corner.
00077 
00078   //: Default for a w-by-h image :
00079   void set_image(unsigned w, unsigned h) { set_ortho(0.f, float(h), float(w), 0.f); }
00080 
00081  protected:
00082   //: Destructor - called by vgui_loader_tableau_sptr.
00083   ~vgui_loader_tableau() { }
00084 
00085   bool handle( vgui_event const &e);
00086 
00087   bool projectionmatrixloaded;
00088   bool modelviewmatrixloaded;
00089 
00090   // note: for efficiency, these are pre-transformed, ie stored in GL format.
00091   double projectionmatrixt[16];
00092   double modelviewmatrixt[16];
00093 };
00094 
00095 //: Create a smart-pointer to a vgui_loader_tableau tableau.
00096 struct vgui_loader_tableau_new : public vgui_loader_tableau_sptr
00097 {
00098   typedef vgui_loader_tableau_sptr base;
00099 
00100   //: Constructor - takes the single child tableau as a parameter.
00101   vgui_loader_tableau_new(vgui_tableau_sptr const& child) : base(new vgui_loader_tableau(child)) { }
00102 };
00103 
00104 #endif // vgui_loader_tableau_h_