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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/sg/matrix_action (Version 11.3.0) and /externals/g4tools/include/tools/sg/matrix_action (Version 11.1.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_sg_matrix_action                      4 #ifndef tools_sg_matrix_action
  5 #define tools_sg_matrix_action                      5 #define tools_sg_matrix_action
  6                                                     6 
  7 #include "win_action"                               7 #include "win_action"
  8                                                     8 
  9 #include "../lina/mat4f"                            9 #include "../lina/mat4f"
 10 #include "states"                                  10 #include "states"
 11                                                    11 
 12 namespace tools {                                  12 namespace tools {
 13 namespace sg {                                     13 namespace sg {
 14                                                    14 
 15 class matrix_action : public win_action,public     15 class matrix_action : public win_action,public states {
 16   TOOLS_ACTION(matrix_action,tools::sg::matrix     16   TOOLS_ACTION(matrix_action,tools::sg::matrix_action,win_action)
 17 public:                                            17 public:
 18   matrix_action(std::ostream& a_out,unsigned i     18   matrix_action(std::ostream& a_out,unsigned int a_ww,unsigned int a_wh)
 19   :parent(a_out,a_ww,a_wh)                         19   :parent(a_out,a_ww,a_wh)
 20   ,states(a_ww,a_wh)                               20   ,states(a_ww,a_wh)
 21   ,m_cur(0)                                        21   ,m_cur(0)
 22   ,m_landscape(true)                               22   ,m_landscape(true)
 23   {                                                23   {
 24     m_projs.resize(5);                             24     m_projs.resize(5);
 25     m_models.resize(5);                            25     m_models.resize(5);
 26     reset();                                       26     reset();
 27     m_identity.set_identity();                     27     m_identity.set_identity();
 28   }                                                28   }
 29   virtual ~matrix_action(){}                       29   virtual ~matrix_action(){}
 30 public:                                            30 public:
 31   matrix_action(const matrix_action& a_from)       31   matrix_action(const matrix_action& a_from)
 32   :parent(a_from)                                  32   :parent(a_from)
 33   ,states(a_from)                                  33   ,states(a_from)
 34   ,m_projs(a_from.m_projs)                         34   ,m_projs(a_from.m_projs)
 35   ,m_models(a_from.m_models)                       35   ,m_models(a_from.m_models)
 36   ,m_cur(a_from.m_cur)                             36   ,m_cur(a_from.m_cur)
 37   ,m_landscape(a_from.m_landscape)                 37   ,m_landscape(a_from.m_landscape)
 38   {                                                38   {
 39     m_identity.set_identity();                     39     m_identity.set_identity();
 40   }                                                40   }
 41   matrix_action& operator=(const matrix_action     41   matrix_action& operator=(const matrix_action& a_from){
 42     parent::operator=(a_from);                     42     parent::operator=(a_from);
 43     states::operator=(a_from);                     43     states::operator=(a_from);
 44     m_projs = a_from.m_projs;                      44     m_projs = a_from.m_projs;
 45     m_models = a_from.m_models;                    45     m_models = a_from.m_models;
 46     m_cur = a_from.m_cur;                          46     m_cur = a_from.m_cur;
 47     m_landscape = a_from.m_landscape;              47     m_landscape = a_from.m_landscape;
 48     return *this;                                  48     return *this;
 49   }                                                49   }
 50 public:                                            50 public:
 51   void push_matrices() {                           51   void push_matrices() {
 52     if((m_cur+1)>=(int)m_projs.size()) {           52     if((m_cur+1)>=(int)m_projs.size()) {
 53       m_projs.resize(m_projs.size()+5);            53       m_projs.resize(m_projs.size()+5);
 54       m_models.resize(m_models.size()+5);          54       m_models.resize(m_models.size()+5);
 55     }                                              55     }
 56     m_cur++;                                       56     m_cur++;
 57     m_projs[m_cur].set_matrix(m_projs[m_cur-1]     57     m_projs[m_cur].set_matrix(m_projs[m_cur-1]);
 58     m_models[m_cur].set_matrix(m_models[m_cur-     58     m_models[m_cur].set_matrix(m_models[m_cur-1]);
 59 //OPTIMIZATION : in fact the two lines below a     59 //OPTIMIZATION : in fact the two lines below are not needed !
 60 //    m_state.m_proj = m_projs[m_cur];             60 //    m_state.m_proj = m_projs[m_cur];
 61 //    m_state.m_model = m_models[m_cur];           61 //    m_state.m_model = m_models[m_cur];
 62   }                                                62   }
 63                                                    63 
 64   //WARNING : in the three below methods, ther     64   //WARNING : in the three below methods, there is no
 65   //          protection against m_cur<0 being     65   //          protection against m_cur<0 being zero here.
 66   void pop_matrices() {                            66   void pop_matrices() {
 67     m_cur--;                                       67     m_cur--;
 68 //OPTIMIZATION : in fact the two lines below a     68 //OPTIMIZATION : in fact the two lines below are not needed !
 69 //    m_state.m_proj = m_projs[m_cur];             69 //    m_state.m_proj = m_projs[m_cur];
 70 //    m_state.m_model = m_models[m_cur];           70 //    m_state.m_model = m_models[m_cur];
 71   }                                                71   }
 72   mat4f& projection_matrix() {return m_projs[m     72   mat4f& projection_matrix() {return m_projs[m_cur];}
 73   mat4f& model_matrix() {return m_models[m_cur     73   mat4f& model_matrix() {return m_models[m_cur];}
 74                                                    74 
 75   bool end() const {return m_cur==0?true:false     75   bool end() const {return m_cur==0?true:false;}
 76   int cur() const {return m_cur;}                  76   int cur() const {return m_cur;}
 77                                                    77 
 78   bool project_point(float& a_x,float& a_y,flo     78   bool project_point(float& a_x,float& a_y,float& a_z,float& a_w) {
 79     a_w = 1;                                       79     a_w = 1;
 80     model_matrix().mul_4f(a_x,a_y,a_z,a_w);        80     model_matrix().mul_4f(a_x,a_y,a_z,a_w);
 81     projection_matrix().mul_4f(a_x,a_y,a_z,a_w     81     projection_matrix().mul_4f(a_x,a_y,a_z,a_w);
 82     if(a_w==0.0F) return false;                    82     if(a_w==0.0F) return false;
 83     a_x /= a_w;                                    83     a_x /= a_w;
 84     a_y /= a_w;                                    84     a_y /= a_w;
 85     a_z /= a_w;                                    85     a_z /= a_w;
 86     return true;                                   86     return true;
 87   }                                                87   }
 88                                                    88 
 89 //  bool project_normal(float& a_x,float& a_y,     89 //  bool project_normal(float& a_x,float& a_y,float& a_z) {
 90 //    model_matrix().mul_dir_3f(a_x,a_y,a_z);      90 //    model_matrix().mul_dir_3f(a_x,a_y,a_z);
 91 //    projection_matrix().mul_dir_3f(a_x,a_y,a     91 //    projection_matrix().mul_dir_3f(a_x,a_y,a_z);
 92 //    return true;                                 92 //    return true;
 93 //  }                                              93 //  }
 94                                                    94 
 95   void model_point(float& a_x,float& a_y,float     95   void model_point(float& a_x,float& a_y,float& a_z,float& a_w) {
 96     a_w = 1;                                       96     a_w = 1;
 97     model_matrix().mul_4f(a_x,a_y,a_z,a_w);        97     model_matrix().mul_4f(a_x,a_y,a_z,a_w);
 98   }                                                98   }
 99                                                    99 
100   // for marker rendering :                       100   // for marker rendering :
101   void projected_origin(float& a_x,float& a_y,    101   void projected_origin(float& a_x,float& a_y,float& a_z) {
102     a_x = 0;                                      102     a_x = 0;
103     a_y = 0;                                      103     a_y = 0;
104     a_z = 0;                                      104     a_z = 0;
105     float w;                                      105     float w;
106     project_point(a_x,a_y,a_z,w); //if render     106     project_point(a_x,a_y,a_z,w); //if render : in [-1,1][-1,1]
107   }                                               107   }
108                                                   108 
109 protected:                                        109 protected:
110   void reset() {                                  110   void reset() {
111     m_cur = 0;                                    111     m_cur = 0;
112     if(m_landscape) {                             112     if(m_landscape) {
113       m_projs[m_cur].set_identity();              113       m_projs[m_cur].set_identity();
114     } else {                                      114     } else {
115       m_projs[m_cur].set_matrix(0,-1,0,0,         115       m_projs[m_cur].set_matrix(0,-1,0,0,
116                                 1, 0,0,0,         116                                 1, 0,0,0,
117                                 0, 0,1,0,         117                                 0, 0,1,0,
118                                 0, 0,0,1);        118                                 0, 0,0,1);
119     }                                             119     }
120     m_models[m_cur].set_identity();               120     m_models[m_cur].set_identity();
121     sg::state& _state = state();                  121     sg::state& _state = state();
122     _state.m_proj = m_projs[m_cur];               122     _state.m_proj = m_projs[m_cur];
123     _state.m_model = m_models[m_cur];             123     _state.m_model = m_models[m_cur];
124   }                                               124   }
125 protected:                                        125 protected:
126   std::vector<mat4f> m_projs;                     126   std::vector<mat4f> m_projs;
127   std::vector<mat4f> m_models;                    127   std::vector<mat4f> m_models;
128   int m_cur;                                      128   int m_cur;
129   mat4f m_identity;                               129   mat4f m_identity;
130 private:                                          130 private:
131   bool m_landscape; //false not yet ready.        131   bool m_landscape; //false not yet ready.
132 };                                                132 };
133                                                   133 
134 }}                                                134 }}
135                                                   135 
136 #endif                                            136 #endif