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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 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  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&){return *this;}
 22 public:
 23   void clear() {m_xyzs.clear();m_nms.clear();}
 24 
 25   void add_points(size_t a_floatn,const float* a_xyzs) {
 26     append(m_xyzs,a_floatn,a_xyzs);
 27   }
 28   void add_lines(size_t a_floatn,const float* a_xyzs) {
 29     append(m_xyzs,a_floatn,a_xyzs);
 30   }
 31   void add_line_strip(size_t a_floatn,const float* a_xyzs) {
 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)+offset;
 38     gl::line_strip_to_lines(num,a_xyzs,pxyzs);
 39   }
 40   void add_line_loop(size_t a_floatn,const float* a_xyzs) {
 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)+offset;
 47     gl::line_loop_to_lines(num,a_xyzs,pxyzs);
 48   }
 49   void add_triangles_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
 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_floatn,const float* a_xyzs,const float* a_nms) {
 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)+offset;
 60     offset = m_nms.size();
 61     m_nms.resize(offset+nxyzs);
 62     float* pnms = vec_data<float>(m_nms)+offset;
 63     gl::triangle_strip_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms);
 64   }
 65   void add_triangle_fan_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
 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)+offset;
 72     offset = m_nms.size();
 73     m_nms.resize(offset+nxyzs);
 74     float* pnms = vec_data<float>(m_nms)+offset;
 75     gl::triangle_fan_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms);
 76   }
 77 
 78   void add_triangle_strip_as_triangles(size_t a_floatn,const float* a_xyzs,const float* a_nms) { //used in sg::sphere, icosahedron_sphere.
 79     add_triangle_strip_normal(a_floatn,a_xyzs,a_nms);
 80   }
 81 /*
 82   /////////////////////////////////////////////////////////
 83   /// for sg::markers and gstos : /////////////////////////
 84   /////////////////////////////////////////////////////////
 85   void add_lines(const std::vector<float>& a_xyzs) {
 86     append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs));
 87   }
 88   void add_triangles_normal(const std::vector<float>& a_xyzs,const std::vector<float>& a_nms) { //for sg::markers.
 89     if(a_xyzs.size()!=a_nms.size()) return;
 90     append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs));
 91     append(m_nms,a_nms.size(),vec_data(a_nms));
 92   }
 93   bool project_point(const mat4f& a_model_matrix,const mat4f& a_projection_matrix,
 94                      float& a_x,float& a_y,float& a_z,float& a_w) {
 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