Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_gstos_add 5 #define tools_sg_gstos_add 6 7 #include "../vmanip" 8 #include "../vdata" 9 #include "../glprims" 10 #include "../lina/mat4f" 11 12 namespace tools { 13 namespace sg { 14 15 class gstos_add { 16 public: 17 gstos_add(){} 18 virtual ~gstos_add(){} 19 public: 20 gstos_add(const gstos_add&) {} 21 gstos_add& operator=(const gstos_add&){retur 22 public: 23 void clear() {m_xyzs.clear();m_nms.clear();} 24 25 void add_points(size_t a_floatn,const float* 26 append(m_xyzs,a_floatn,a_xyzs); 27 } 28 void add_lines(size_t a_floatn,const float* 29 append(m_xyzs,a_floatn,a_xyzs); 30 } 31 void add_line_strip(size_t a_floatn,const fl 32 size_t num = a_floatn/3; 33 if(num<2) return; 34 size_t nxyzs = (num-1)*2*3; 35 size_t offset = m_xyzs.size(); 36 m_xyzs.resize(offset+nxyzs); 37 float* pxyzs = vec_data<float>(m_xyzs)+off 38 gl::line_strip_to_lines(num,a_xyzs,pxyzs); 39 } 40 void add_line_loop(size_t a_floatn,const flo 41 size_t num = a_floatn/3; 42 if(num<2) return; 43 size_t nxyzs = num*2*3; 44 size_t offset = m_xyzs.size(); 45 m_xyzs.resize(offset+nxyzs); 46 float* pxyzs = vec_data<float>(m_xyzs)+off 47 gl::line_loop_to_lines(num,a_xyzs,pxyzs); 48 } 49 void add_triangles_normal(size_t a_floatn,co 50 append(m_xyzs,a_floatn,a_xyzs); 51 append(m_nms,a_floatn,a_nms); 52 } 53 void add_triangle_strip_normal(size_t a_floa 54 size_t num = a_floatn/3; 55 if(num<3) return; 56 size_t nxyzs = (num-2)*3*3; 57 size_t offset = m_xyzs.size(); 58 m_xyzs.resize(offset+nxyzs); 59 float* pxyzs = vec_data<float>(m_xyzs)+off 60 offset = m_nms.size(); 61 m_nms.resize(offset+nxyzs); 62 float* pnms = vec_data<float>(m_nms)+offse 63 gl::triangle_strip_to_triangles_nms(num,a_ 64 } 65 void add_triangle_fan_normal(size_t a_floatn 66 size_t num = a_floatn/3; 67 if(num<3) return; 68 size_t nxyzs = (num-2)*3*3; 69 size_t offset = m_xyzs.size(); 70 m_xyzs.resize(offset+nxyzs); 71 float* pxyzs = vec_data<float>(m_xyzs)+off 72 offset = m_nms.size(); 73 m_nms.resize(offset+nxyzs); 74 float* pnms = vec_data<float>(m_nms)+offse 75 gl::triangle_fan_to_triangles_nms(num,a_xy 76 } 77 78 void add_triangle_strip_as_triangles(size_t 79 add_triangle_strip_normal(a_floatn,a_xyzs, 80 } 81 /* 82 //////////////////////////////////////////// 83 /// for sg::markers and gstos : //////////// 84 //////////////////////////////////////////// 85 void add_lines(const std::vector<float>& a_x 86 append(m_xyzs,a_xyzs.size(),vec_data(a_xyz 87 } 88 void add_triangles_normal(const std::vector< 89 if(a_xyzs.size()!=a_nms.size()) return; 90 append(m_xyzs,a_xyzs.size(),vec_data(a_xyz 91 append(m_nms,a_nms.size(),vec_data(a_nms)) 92 } 93 bool project_point(const mat4f& a_model_matr 94 float& a_x,float& a_y,flo 95 a_w = 1; 96 a_model_matrix.mul_4f(a_x,a_y,a_z,a_w); 97 a_projection_matrix.mul_4f(a_x,a_y,a_z,a_w 98 if(a_w==0.0F) return false; 99 a_x /= a_w; 100 a_y /= a_w; 101 a_z /= a_w; 102 return true; 103 } 104 //////////////////////////////////////////// 105 //////////////////////////////////////////// 106 //////////////////////////////////////////// 107 */ 108 public: 109 std::vector<float> m_xyzs; 110 std::vector<float> m_nms; 111 112 size_t m_gsto_points_sz; 113 size_t m_gsto_lines_sz; 114 size_t m_gsto_tris_sz; 115 size_t m_gsto_nms_sz; 116 }; 117 118 }} 119 120 #endif