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