core/vgui/vgui_matrix_state.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_matrix_state.h
00002 #ifndef vgui_matrix_state_h_
00003 #define vgui_matrix_state_h_
00004 //:
00005 // \file
00006 // \author  fsm
00007 // \brief   Stores and retrieves the current projection and modelview matrices.
00008 //
00009 //  Contains class vgui_matrix_state
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   AWF Renamed store, and made it save and restore on
00014 //       construction/destruction.
00015 //   FSM Renamed method names for consistency with projection_inspector.
00016 // \endverbatim
00017 
00018 #include <vcl_iosfwd.h>
00019 #include <vgui/vgui_gl.h>
00020 #include <vnl/vnl_fwd.h>
00021 
00022 //: Stores and retrieves the current projection and modelview matrices.
00023 //
00024 // vgui_matrix_state stores the current OpenGL projection and modelview
00025 // matrices when save() is called. The matrices are restored to these values
00026 // on the next call to restore(). Normally, the constructor calls save() and
00027 // the destructor calls restore(), but this can be overridden.
00028 //
00029 // vgui_matrix_state also has various static convenience methods for GL matrix
00030 // handling.
00031 class vgui_matrix_state
00032 {
00033   // NB : matrices stored in column (fortran) order.
00034   double P[16]; // projection
00035   double M[16]; // modelview
00036   bool restore_on_destroy;
00037 
00038  public:
00039   vgui_matrix_state(bool save_now_restore_on_destroy = true);
00040   ~vgui_matrix_state();
00041 
00042   void save();
00043   void restore() const;
00044   void print(vcl_ostream& );
00045 
00046   // set
00047   static void identity_gl_matrices(); // set both matrices to the identity.
00048   static void clear_gl_matrices();    // set both matrices to zero.
00049   static void zero_out_gl_matrices() { clear_gl_matrices(); }
00050 
00051   // query
00052   static bool gl_matrices_are_cleared();
00053   static vnl_matrix_fixed<double,4,4> projection_matrix();
00054   static vnl_matrix_fixed<double,4,4> modelview_matrix();
00055   static vnl_matrix_fixed<double,4,4> total_transformation();
00056 
00057   // Projection matrices
00058   static void premultiply(vnl_matrix_fixed<double,4,4> const &,GLenum );
00059   static void premultiply_projection(vnl_matrix_fixed<double,4,4> const &M) { premultiply(M,GL_PROJECTION); }
00060   static void premultiply_modelview (vnl_matrix_fixed<double,4,4> const &M) { premultiply(M,GL_MODELVIEW); }
00061 
00062   static void postmultiply(const vnl_matrix_fixed<double,4,4> &M,GLenum matrix);
00063   static void postmultiply_projection(vnl_matrix_fixed<double,4,4> const &M) { postmultiply(M,GL_PROJECTION); }
00064   static void postmultiply_modelview (vnl_matrix_fixed<double,4,4> const &M) { postmultiply(M,GL_MODELVIEW); }
00065 };
00066 
00067 #endif // vgui_matrix_state_h_