Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/state 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_state
0005 #define tools_sg_state
0006 
0007 #include <string>
0008 
0009 #include "../lina/rotf"  //m_camera_orientation
0010 #include "../lina/mat4f"
0011 #include "../lina/vec3f"
0012 #include "../lina/vec4f"
0013 #include "../colorf"
0014 
0015 #ifdef TOOLS_MEM
0016 #include "../mem"
0017 #include "../S_STRING"
0018 #endif
0019 
0020 #include "enums"
0021 
0022 namespace tools {
0023 namespace sg {
0024 
0025 class state {
0026 #ifdef TOOLS_MEM
0027   TOOLS_SCLASS(tools::sg::state)
0028 #endif
0029 public:
0030   state()
0031   //must be consistent with tools::sg::viewer::render.
0032   :m_ww(0)
0033   ,m_wh(0)
0034 
0035   ,m_GL_DEPTH_TEST(true)
0036   ,m_GL_LIGHTING(false)
0037   ,m_GL_CULL_FACE(true)
0038   ,m_GL_POLYGON_OFFSET_FILL(false)
0039   ,m_GL_TEXTURE_2D(false)
0040   ,m_GL_POINT_SMOOTH(false)
0041   ,m_GL_LINE_SMOOTH(false)
0042   ,m_GL_BLEND(false)
0043 
0044   ,m_use_gsto(false)
0045 
0046   ,m_winding(winding_ccw)
0047   ,m_color(1,1,1,1)
0048   ,m_normal(0,0,1)
0049 
0050   ,m_light(0)
0051 
0052   ,m_draw_type(sg::draw_filled)
0053   ,m_shade_model(sg::shade_flat)
0054 
0055   ,m_line_width(1)
0056   ,m_line_pattern(sg::line_solid)
0057   ,m_point_size(1)
0058 
0059   ,m_camera_ortho(true)
0060   ,m_camera_znear(1)
0061   ,m_camera_zfar(10)
0062   ,m_camera_position(vec3f(0,0,1))
0063   ,m_camera_orientation(rotf(vec3f(0,0,1),0))
0064   //,m_camera_near_height(0)
0065   ,m_camera_lrbt(0,0,0,0)
0066   {
0067 #ifdef TOOLS_MEM
0068     mem::increment(s_class().c_str());
0069 #endif
0070     //m_proj.set_identity();
0071     //m_model.set_identity();
0072   }
0073   virtual ~state(){
0074 #ifdef TOOLS_MEM
0075     mem::decrement(s_class().c_str());
0076 #endif
0077   }
0078 public:
0079   state(const state& a_from)
0080   :m_ww(a_from.m_ww)
0081   ,m_wh(a_from.m_wh)
0082 
0083   ,m_proj(a_from.m_proj)
0084   ,m_model(a_from.m_model)
0085 
0086   ,m_GL_DEPTH_TEST(a_from.m_GL_DEPTH_TEST)
0087   ,m_GL_LIGHTING(a_from.m_GL_LIGHTING)
0088   ,m_GL_CULL_FACE(a_from.m_GL_CULL_FACE)
0089   ,m_GL_POLYGON_OFFSET_FILL(a_from.m_GL_POLYGON_OFFSET_FILL)
0090   ,m_GL_TEXTURE_2D(a_from.m_GL_TEXTURE_2D)
0091   ,m_GL_POINT_SMOOTH(a_from.m_GL_POINT_SMOOTH)
0092   ,m_GL_LINE_SMOOTH(a_from.m_GL_LINE_SMOOTH)
0093   ,m_GL_BLEND(a_from.m_GL_BLEND)
0094 
0095   ,m_use_gsto(a_from.m_use_gsto)
0096 
0097   ,m_winding(a_from.m_winding)
0098   ,m_color(a_from.m_color)
0099   ,m_normal(a_from.m_normal)
0100 
0101   ,m_light(a_from.m_light)
0102 
0103   ,m_draw_type(a_from.m_draw_type)
0104   ,m_shade_model(a_from.m_shade_model)
0105 
0106   ,m_line_width(a_from.m_line_width)
0107   ,m_line_pattern(a_from.m_line_pattern)
0108   ,m_point_size(a_from.m_point_size)
0109 
0110   ,m_camera_ortho(a_from.m_camera_ortho)
0111   ,m_camera_znear(a_from.m_camera_znear)
0112   ,m_camera_zfar(a_from.m_camera_zfar)
0113   ,m_camera_position(a_from.m_camera_position)
0114   ,m_camera_orientation(a_from.m_camera_orientation)
0115   //,m_camera_near_height(a_from.m_camera_near_height)
0116   ,m_camera_lrbt(a_from.m_camera_lrbt)
0117   {
0118 #ifdef TOOLS_MEM
0119     mem::increment(s_class().c_str());
0120 #endif
0121   }
0122   state& operator=(const state& a_from){
0123     m_ww = a_from.m_ww;
0124     m_wh = a_from.m_wh;
0125 
0126     m_proj = a_from.m_proj;
0127     m_model = a_from.m_model;
0128 
0129     m_GL_DEPTH_TEST = a_from.m_GL_DEPTH_TEST;
0130     m_GL_LIGHTING = a_from.m_GL_LIGHTING;
0131     m_GL_CULL_FACE = a_from.m_GL_CULL_FACE;
0132     m_GL_POLYGON_OFFSET_FILL = a_from.m_GL_POLYGON_OFFSET_FILL;
0133     m_GL_TEXTURE_2D = a_from.m_GL_TEXTURE_2D;
0134     m_GL_POINT_SMOOTH = a_from.m_GL_POINT_SMOOTH;
0135     m_GL_LINE_SMOOTH = a_from.m_GL_LINE_SMOOTH;
0136     m_GL_BLEND = a_from.m_GL_BLEND;
0137 
0138     m_use_gsto = a_from.m_use_gsto;
0139 
0140     m_winding = a_from.m_winding;
0141     m_color = a_from.m_color;
0142     m_normal = a_from.m_normal;
0143 
0144     m_light = a_from.m_light;
0145 
0146     m_draw_type = a_from.m_draw_type;
0147     m_shade_model = a_from.m_shade_model;
0148 
0149     m_line_width = a_from.m_line_width;
0150     m_line_pattern = a_from.m_line_pattern;
0151     m_point_size = a_from.m_point_size;
0152 
0153     m_camera_ortho = a_from.m_camera_ortho;
0154     m_camera_znear = a_from.m_camera_znear;
0155     m_camera_zfar = a_from.m_camera_zfar;
0156     m_camera_position = a_from.m_camera_position;
0157     m_camera_orientation = a_from.m_camera_orientation;
0158     //m_camera_near_height = a_from.m_camera_near_height;
0159     m_camera_lrbt = a_from.m_camera_lrbt;
0160 
0161     return *this;
0162   }
0163 public:
0164   bool project_point(float& a_x,float& a_y,float& a_z,float& a_w) const {
0165     a_w = 1;
0166     m_model.mul_4f(a_x,a_y,a_z,a_w);
0167     m_proj.mul_4f(a_x,a_y,a_z,a_w);
0168     if(a_w==0.0F) return false;
0169     a_x /= a_w;
0170     a_y /= a_w;
0171     a_z /= a_w;
0172     return true;
0173   }
0174 
0175   void screen2ndc(int a_x,int a_y, //signed because of wall.
0176                   float& a_wcx,float& a_wcy,float& a_wcz,float& a_wcw) const {
0177     // a proj point in near plane has (z,w) :
0178     //   ortho -1,1   -> z/w = -1    and xy in [-1,1][-1,1]
0179     //   persp -n,n   -> z/w = -1    and xy in [-n,n][-n,n]
0180 
0181     a_wcx = 2*(float(a_x)/float(m_ww)-0.5f); //in [-1,1]
0182     a_wcy = 2*(float(a_y)/float(m_wh)-0.5f);
0183     a_wcz = -1;
0184 
0185     if(m_camera_ortho) {
0186       a_wcw = 1;
0187     } else {
0188       float t = m_camera_znear;
0189       a_wcx *= t;
0190       a_wcy *= t;
0191       a_wcz *= t;
0192       a_wcw = t;
0193     }
0194   }
0195 
0196   bool screen2wc(int a_x,int a_y, //signed because of wall.
0197                  float& a_wcx,float& a_wcy,float& a_wcz) const {
0198     mat4f mtx = m_proj;
0199     mtx.mul_mtx(m_model);
0200     mat4f inv;
0201     if(!mtx.invert(inv)) {a_wcx = 0;a_wcy = 0;a_wcz = 0;return false;}
0202     float w;
0203     screen2ndc(a_x,a_y,a_wcx,a_wcy,a_wcz,w);
0204     inv.mul_4f(a_wcx,a_wcy,a_wcz,w);
0205     if(w==0.0F) return false;
0206     a_wcx /= w;
0207     a_wcy /= w;
0208     a_wcz /= w;
0209     return true;
0210   }
0211   bool screen2pwc(int a_x,int a_y, //signed because of wall.
0212                   float& a_wcx,float& a_wcy,float& a_wcz) const {
0213     mat4f mtx = m_proj;
0214     //mtx.mul_mtx(m_model);
0215     mat4f inv;
0216     if(!mtx.invert(inv)) {a_wcx = 0;a_wcy = 0;a_wcz = 0;return false;}
0217     float w;
0218     screen2ndc(a_x,a_y,a_wcx,a_wcy,a_wcz,w);
0219     inv.mul_4f(a_wcx,a_wcy,a_wcz,w);
0220     if(w==0.0F) return false;
0221     a_wcx /= w;
0222     a_wcy /= w;
0223     a_wcz /= w;
0224     return true;
0225   }
0226   void camera_proj_only(mat4f& a_mtx) const {
0227     float l = m_camera_lrbt[0];
0228     float r = m_camera_lrbt[1];
0229     float b = m_camera_lrbt[2];
0230     float t = m_camera_lrbt[3];
0231     float n = m_camera_znear;
0232     float f = m_camera_zfar;
0233     if(m_camera_ortho) {
0234       a_mtx.set_ortho(l,r,b,t,n,f);
0235     } else {
0236       a_mtx.set_frustum(l,r,b,t,n,f);
0237     }
0238   }
0239 
0240 public:
0241   unsigned int m_ww;  //window width
0242   unsigned int m_wh;  //window height
0243 
0244   mat4f m_proj;
0245   mat4f m_model;
0246 
0247   bool m_GL_DEPTH_TEST;
0248   bool m_GL_LIGHTING;
0249   bool m_GL_CULL_FACE;
0250   bool m_GL_POLYGON_OFFSET_FILL;
0251   bool m_GL_TEXTURE_2D;
0252   bool m_GL_POINT_SMOOTH;
0253   bool m_GL_LINE_SMOOTH;
0254   bool m_GL_BLEND;
0255 
0256   bool m_use_gsto;
0257 
0258   winding_type m_winding;
0259   colorf m_color;
0260   vec3f m_normal;
0261 
0262   unsigned int m_light;
0263 
0264   draw_type m_draw_type;
0265   shade_type m_shade_model;
0266 
0267   float m_line_width;
0268   unsigned short m_line_pattern;
0269   float m_point_size;
0270 
0271   //camera (see base_camera::set_state()) :
0272   bool m_camera_ortho;
0273   float m_camera_znear;
0274   float m_camera_zfar;
0275   vec3f m_camera_position;
0276   rotf m_camera_orientation; //used by head_light
0277   //float m_camera_near_height;
0278   vec4f m_camera_lrbt;
0279 };
0280 
0281 }}
0282 
0283 #endif