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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/state (Version 11.3.0) and /externals/g4tools/include/tools/sg/state (Version 8.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_sg_state                            
  5 #define tools_sg_state                            
  6                                                   
  7 #include <string>                                 
  8                                                   
  9 #include "../lina/rotf"  //m_camera_orientatio    
 10 #include "../lina/mat4f"                          
 11 #include "../lina/vec3f"                          
 12 #include "../lina/vec4f"                          
 13 #include "../colorf"                              
 14                                                   
 15 #ifdef TOOLS_MEM                                  
 16 #include "../mem"                                 
 17 #include "../S_STRING"                            
 18 #endif                                            
 19                                                   
 20 #include "enums"                                  
 21                                                   
 22 namespace tools {                                 
 23 namespace sg {                                    
 24                                                   
 25 class state {                                     
 26 #ifdef TOOLS_MEM                                  
 27   TOOLS_SCLASS(tools::sg::state)                  
 28 #endif                                            
 29 public:                                           
 30   state()                                         
 31   //must be consistent with tools::sg::viewer:    
 32   :m_ww(0)                                        
 33   ,m_wh(0)                                        
 34                                                   
 35   ,m_GL_DEPTH_TEST(true)                          
 36   ,m_GL_LIGHTING(false)                           
 37   ,m_GL_CULL_FACE(true)                           
 38   ,m_GL_POLYGON_OFFSET_FILL(false)                
 39   ,m_GL_TEXTURE_2D(false)                         
 40   ,m_GL_POINT_SMOOTH(false)                       
 41   ,m_GL_LINE_SMOOTH(false)                        
 42   ,m_GL_BLEND(false)                              
 43                                                   
 44   ,m_use_gsto(false)                              
 45                                                   
 46   ,m_winding(winding_ccw)                         
 47   ,m_color(1,1,1,1)                               
 48   ,m_normal(0,0,1)                                
 49                                                   
 50   ,m_light(0)                                     
 51                                                   
 52   ,m_draw_type(sg::draw_filled)                   
 53   ,m_shade_model(sg::shade_flat)                  
 54                                                   
 55   ,m_line_width(1)                                
 56   ,m_line_pattern(sg::line_solid)                 
 57   ,m_point_size(1)                                
 58                                                   
 59   ,m_camera_ortho(true)                           
 60   ,m_camera_znear(1)                              
 61   ,m_camera_zfar(10)                              
 62   ,m_camera_position(vec3f(0,0,1))                
 63   ,m_camera_orientation(rotf(vec3f(0,0,1),0))     
 64   //,m_camera_near_height(0)                      
 65   ,m_camera_lrbt(0,0,0,0)                         
 66   {                                               
 67 #ifdef TOOLS_MEM                                  
 68     mem::increment(s_class().c_str());            
 69 #endif                                            
 70     //m_proj.set_identity();                      
 71     //m_model.set_identity();                     
 72   }                                               
 73   virtual ~state(){                               
 74 #ifdef TOOLS_MEM                                  
 75     mem::decrement(s_class().c_str());            
 76 #endif                                            
 77   }                                               
 78 public:                                           
 79   state(const state& a_from)                      
 80   :m_ww(a_from.m_ww)                              
 81   ,m_wh(a_from.m_wh)                              
 82                                                   
 83   ,m_proj(a_from.m_proj)                          
 84   ,m_model(a_from.m_model)                        
 85                                                   
 86   ,m_GL_DEPTH_TEST(a_from.m_GL_DEPTH_TEST)        
 87   ,m_GL_LIGHTING(a_from.m_GL_LIGHTING)            
 88   ,m_GL_CULL_FACE(a_from.m_GL_CULL_FACE)          
 89   ,m_GL_POLYGON_OFFSET_FILL(a_from.m_GL_POLYGO    
 90   ,m_GL_TEXTURE_2D(a_from.m_GL_TEXTURE_2D)        
 91   ,m_GL_POINT_SMOOTH(a_from.m_GL_POINT_SMOOTH)    
 92   ,m_GL_LINE_SMOOTH(a_from.m_GL_LINE_SMOOTH)      
 93   ,m_GL_BLEND(a_from.m_GL_BLEND)                  
 94                                                   
 95   ,m_use_gsto(a_from.m_use_gsto)                  
 96                                                   
 97   ,m_winding(a_from.m_winding)                    
 98   ,m_color(a_from.m_color)                        
 99   ,m_normal(a_from.m_normal)                      
100                                                   
101   ,m_light(a_from.m_light)                        
102                                                   
103   ,m_draw_type(a_from.m_draw_type)                
104   ,m_shade_model(a_from.m_shade_model)            
105                                                   
106   ,m_line_width(a_from.m_line_width)              
107   ,m_line_pattern(a_from.m_line_pattern)          
108   ,m_point_size(a_from.m_point_size)              
109                                                   
110   ,m_camera_ortho(a_from.m_camera_ortho)          
111   ,m_camera_znear(a_from.m_camera_znear)          
112   ,m_camera_zfar(a_from.m_camera_zfar)            
113   ,m_camera_position(a_from.m_camera_position)    
114   ,m_camera_orientation(a_from.m_camera_orient    
115   //,m_camera_near_height(a_from.m_camera_near    
116   ,m_camera_lrbt(a_from.m_camera_lrbt)            
117   {                                               
118 #ifdef TOOLS_MEM                                  
119     mem::increment(s_class().c_str());            
120 #endif                                            
121   }                                               
122   state& operator=(const state& a_from){          
123     m_ww = a_from.m_ww;                           
124     m_wh = a_from.m_wh;                           
125                                                   
126     m_proj = a_from.m_proj;                       
127     m_model = a_from.m_model;                     
128                                                   
129     m_GL_DEPTH_TEST = a_from.m_GL_DEPTH_TEST;     
130     m_GL_LIGHTING = a_from.m_GL_LIGHTING;         
131     m_GL_CULL_FACE = a_from.m_GL_CULL_FACE;       
132     m_GL_POLYGON_OFFSET_FILL = a_from.m_GL_POL    
133     m_GL_TEXTURE_2D = a_from.m_GL_TEXTURE_2D;     
134     m_GL_POINT_SMOOTH = a_from.m_GL_POINT_SMOO    
135     m_GL_LINE_SMOOTH = a_from.m_GL_LINE_SMOOTH    
136     m_GL_BLEND = a_from.m_GL_BLEND;               
137                                                   
138     m_use_gsto = a_from.m_use_gsto;               
139                                                   
140     m_winding = a_from.m_winding;                 
141     m_color = a_from.m_color;                     
142     m_normal = a_from.m_normal;                   
143                                                   
144     m_light = a_from.m_light;                     
145                                                   
146     m_draw_type = a_from.m_draw_type;             
147     m_shade_model = a_from.m_shade_model;         
148                                                   
149     m_line_width = a_from.m_line_width;           
150     m_line_pattern = a_from.m_line_pattern;       
151     m_point_size = a_from.m_point_size;           
152                                                   
153     m_camera_ortho = a_from.m_camera_ortho;       
154     m_camera_znear = a_from.m_camera_znear;       
155     m_camera_zfar = a_from.m_camera_zfar;         
156     m_camera_position = a_from.m_camera_positi    
157     m_camera_orientation = a_from.m_camera_ori    
158     //m_camera_near_height = a_from.m_camera_n    
159     m_camera_lrbt = a_from.m_camera_lrbt;         
160                                                   
161     return *this;                                 
162   }                                               
163 public:                                           
164   bool project_point(float& a_x,float& a_y,flo    
165     a_w = 1;                                      
166     m_model.mul_4f(a_x,a_y,a_z,a_w);              
167     m_proj.mul_4f(a_x,a_y,a_z,a_w);               
168     if(a_w==0.0F) return false;                   
169     a_x /= a_w;                                   
170     a_y /= a_w;                                   
171     a_z /= a_w;                                   
172     return true;                                  
173   }                                               
174                                                   
175   void screen2ndc(int a_x,int a_y, //signed be    
176                   float& a_wcx,float& a_wcy,fl    
177     // a proj point in near plane has (z,w) :     
178     //   ortho -1,1   -> z/w = -1    and xy in    
179     //   persp -n,n   -> z/w = -1    and xy in    
180                                                   
181     a_wcx = 2*(float(a_x)/float(m_ww)-0.5f); /    
182     a_wcy = 2*(float(a_y)/float(m_wh)-0.5f);      
183     a_wcz = -1;                                   
184                                                   
185     if(m_camera_ortho) {                          
186       a_wcw = 1;                                  
187     } else {                                      
188       float t = m_camera_znear;                   
189       a_wcx *= t;                                 
190       a_wcy *= t;                                 
191       a_wcz *= t;                                 
192       a_wcw = t;                                  
193     }                                             
194   }                                               
195                                                   
196   bool screen2wc(int a_x,int a_y, //signed bec    
197                  float& a_wcx,float& a_wcy,flo    
198     mat4f mtx = m_proj;                           
199     mtx.mul_mtx(m_model);                         
200     mat4f inv;                                    
201     if(!mtx.invert(inv)) {a_wcx = 0;a_wcy = 0;    
202     float w;                                      
203     screen2ndc(a_x,a_y,a_wcx,a_wcy,a_wcz,w);      
204     inv.mul_4f(a_wcx,a_wcy,a_wcz,w);              
205     if(w==0.0F) return false;                     
206     a_wcx /= w;                                   
207     a_wcy /= w;                                   
208     a_wcz /= w;                                   
209     return true;                                  
210   }                                               
211   bool screen2pwc(int a_x,int a_y, //signed be    
212                   float& a_wcx,float& a_wcy,fl    
213     mat4f mtx = m_proj;                           
214     //mtx.mul_mtx(m_model);                       
215     mat4f inv;                                    
216     if(!mtx.invert(inv)) {a_wcx = 0;a_wcy = 0;    
217     float w;                                      
218     screen2ndc(a_x,a_y,a_wcx,a_wcy,a_wcz,w);      
219     inv.mul_4f(a_wcx,a_wcy,a_wcz,w);              
220     if(w==0.0F) return false;                     
221     a_wcx /= w;                                   
222     a_wcy /= w;                                   
223     a_wcz /= w;                                   
224     return true;                                  
225   }                                               
226   void camera_proj_only(mat4f& a_mtx) const {     
227     float l = m_camera_lrbt[0];                   
228     float r = m_camera_lrbt[1];                   
229     float b = m_camera_lrbt[2];                   
230     float t = m_camera_lrbt[3];                   
231     float n = m_camera_znear;                     
232     float f = m_camera_zfar;                      
233     if(m_camera_ortho) {                          
234       a_mtx.set_ortho(l,r,b,t,n,f);               
235     } else {                                      
236       a_mtx.set_frustum(l,r,b,t,n,f);             
237     }                                             
238   }                                               
239                                                   
240 public:                                           
241   unsigned int m_ww;  //window width              
242   unsigned int m_wh;  //window height             
243                                                   
244   mat4f m_proj;                                   
245   mat4f m_model;                                  
246                                                   
247   bool m_GL_DEPTH_TEST;                           
248   bool m_GL_LIGHTING;                             
249   bool m_GL_CULL_FACE;                            
250   bool m_GL_POLYGON_OFFSET_FILL;                  
251   bool m_GL_TEXTURE_2D;                           
252   bool m_GL_POINT_SMOOTH;                         
253   bool m_GL_LINE_SMOOTH;                          
254   bool m_GL_BLEND;                                
255                                                   
256   bool m_use_gsto;                                
257                                                   
258   winding_type m_winding;                         
259   colorf m_color;                                 
260   vec3f m_normal;                                 
261                                                   
262   unsigned int m_light;                           
263                                                   
264   draw_type m_draw_type;                          
265   shade_type m_shade_model;                       
266                                                   
267   float m_line_width;                             
268   unsigned short m_line_pattern;                  
269   float m_point_size;                             
270                                                   
271   //camera (see base_camera::set_state()) :       
272   bool m_camera_ortho;                            
273   float m_camera_znear;                           
274   float m_camera_zfar;                            
275   vec3f m_camera_position;                        
276   rotf m_camera_orientation; //used by head_li    
277   //float m_camera_near_height;                   
278   vec4f m_camera_lrbt;                            
279 };                                                
280                                                   
281 }}                                                
282                                                   
283 #endif