Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/matrix_action is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_matrix_action
0005 #define tools_sg_matrix_action
0006 
0007 #include "win_action"
0008 
0009 #include "../lina/mat4f"
0010 #include "states"
0011 
0012 namespace tools {
0013 namespace sg {
0014 
0015 class matrix_action : public win_action,public states {
0016   TOOLS_ACTION(matrix_action,tools::sg::matrix_action,win_action)
0017 public:
0018   matrix_action(std::ostream& a_out,unsigned int a_ww,unsigned int a_wh)
0019   :parent(a_out,a_ww,a_wh)
0020   ,states(a_ww,a_wh)
0021   ,m_cur(0)
0022   ,m_landscape(true)
0023   {
0024     m_projs.resize(5);
0025     m_models.resize(5);
0026     reset();
0027     m_identity.set_identity();
0028   }
0029   virtual ~matrix_action(){}
0030 public:
0031   matrix_action(const matrix_action& a_from)
0032   :parent(a_from)
0033   ,states(a_from)
0034   ,m_projs(a_from.m_projs)
0035   ,m_models(a_from.m_models)
0036   ,m_cur(a_from.m_cur)
0037   ,m_landscape(a_from.m_landscape)
0038   {
0039     m_identity.set_identity();
0040   }
0041   matrix_action& operator=(const matrix_action& a_from){
0042     parent::operator=(a_from);
0043     states::operator=(a_from);
0044     m_projs = a_from.m_projs;
0045     m_models = a_from.m_models;
0046     m_cur = a_from.m_cur;
0047     m_landscape = a_from.m_landscape;
0048     return *this;
0049   }
0050 public:
0051   void push_matrices() {
0052     if((m_cur+1)>=(int)m_projs.size()) {
0053       m_projs.resize(m_projs.size()+5);
0054       m_models.resize(m_models.size()+5);
0055     }
0056     m_cur++;
0057     m_projs[m_cur].set_matrix(m_projs[m_cur-1]);
0058     m_models[m_cur].set_matrix(m_models[m_cur-1]);
0059   }
0060 
0061   //WARNING : in the three below methods, there is no
0062   //          protection against m_cur<0 being zero here.
0063   void pop_matrices() {
0064     m_cur--;
0065   }
0066   mat4f& projection_matrix() {return m_projs[m_cur];}
0067   mat4f& model_matrix() {return m_models[m_cur];}
0068 
0069   bool end() const {return m_cur==0?true:false;}
0070   int cur() const {return m_cur;}
0071 
0072   bool project_point(float& a_x,float& a_y,float& a_z,float& a_w) {
0073     a_w = 1;
0074     model_matrix().mul_4f(a_x,a_y,a_z,a_w);
0075     projection_matrix().mul_4f(a_x,a_y,a_z,a_w);
0076     if(a_w==0.0F) return false;
0077     a_x /= a_w;
0078     a_y /= a_w;
0079     a_z /= a_w;
0080     return true;
0081   }
0082 
0083   void model_point(float& a_x,float& a_y,float& a_z,float& a_w) {
0084     a_w = 1;
0085     model_matrix().mul_4f(a_x,a_y,a_z,a_w);
0086   }
0087 
0088   // for marker rendering :
0089   void projected_origin(float& a_x,float& a_y,float& a_z) {
0090     a_x = 0;
0091     a_y = 0;
0092     a_z = 0;
0093     float w;
0094     project_point(a_x,a_y,a_z,w); //if render : in [-1,1][-1,1]
0095   }
0096 
0097 protected:
0098   void reset() {
0099     m_cur = 0;
0100     if(m_landscape) {
0101       m_projs[m_cur].set_identity();
0102     } else {
0103       m_projs[m_cur].set_matrix(0,-1,0,0,
0104                                 1, 0,0,0,
0105                                 0, 0,1,0,
0106                                 0, 0,0,1);
0107     }
0108     m_models[m_cur].set_identity();
0109     sg::state& _state = state();
0110     _state.m_proj = m_projs[m_cur];
0111     _state.m_model = m_models[m_cur];
0112   }
0113 protected:
0114   std::vector<mat4f> m_projs;
0115   std::vector<mat4f> m_models;
0116   int m_cur;
0117   mat4f m_identity;
0118 private:
0119   bool m_landscape; //false not yet ready.
0120 };
0121 
0122 }}
0123 
0124 #endif