versor  3.0
C++11 library for Geometric algebra
vsr_cga2D_render.h
1 /*
2  * =====================================================================================
3  *
4  * Filename: vsr_cga2D_render.h
5  *
6  * Description:
7  *
8  * Version: 1.0
9  * Created: 06/02/2014 16:12:26
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Pablo Colapinto (), gmail -> wolftype
14  * Organization:
15  *
16  * =====================================================================================
17  */
18 
19 
20 
21 #ifndef vsr_cga2D_render_INC
22 #define vsr_cga2D_render_INC
23 
24 
25 #include "gfx/gfx_renderer.h"
26 
27 #include "vsr_cga2D_types.h"
28 
29 
30 using namespace gfx;
31 
32 namespace vsr {
33 
34  namespace cga2D{
35 
36  namespace XF{
37  inline gfx::Mat4f mat( const Vec& v, VT s) {
38  double x = v[0]; double y = v[1]; //double z = v[2];
39  return gfx::Mat4f( s , 0 , 0 , 0,
40  0 , s , 0 , 0,
41  0 , 0 , s , 0,
42  x , y , 0 , 1 );
43  }
44  }
45 
46  MBO& MeshBuffer(const Dll& s ) { static MBO mbo( Mesh::Line( Vec(-50,0), Vec(50,0) ), GL::DYNAMIC ); return mbo; }
47  MBO& MeshBuffer(const Lin& s ) { return MeshBuffer( Dll() ); }
48 
49  /* vector<MBO>& MeshBuffer(const Vec& s){ */
50  /* static vector<MBO> m = { Mesh::Cone(.3), MBO( Mesh::Line( Vec(0,0,0), s), GL::DYNAMIC ) }; */
51  /* return m; */
52  /* } */
53 
54  vector<MBO>& MeshBuffer(const Pnt& s){
55  static vector<MBO> m = { Mesh::Circle(), Mesh::Point( Pnt() ) };
56  return m;
57  }
58 
59  vector<MBO>& MeshBuffer(const Sph& s ) { return MeshBuffer( Pnt() ); }
60 
61  vector<MBO>& MeshBuffer(const Par& s ) {
62  static vector<MBO> m = { Mesh::Sphere(), Mesh::Points( Ro::split(s) ) };
63  return m;
64  }
65 
66 
72  void Render( const Pnt& pnt, Renderer * re,
73  bool bUpdate=false, float r=1.0,float g=1.0,float b=1.0, float a=1.0 ) {
74 
75  auto& mbo = MeshBuffer( pnt );
76  MBO& circle = mbo[0];
77  MBO& point = mbo[1];
78 
79  double ta = vsr::Ro::size( pnt, true );
80 
81  if ( fabs(ta) > FPERROR ) {
82 
83  bool real = ta > 0 ? 1 : 0;
84 
85  re -> modelview( XF::mat( pnt, sqrt( fabs(ta) ) ) );
86  if (bUpdate) { circle.mesh.color(r,g,b,a); circle.update(); }
87  re -> pipe.line( circle );
88 
89  } else {
90 
91  re -> modelview();
92 
93  point.mesh[0].Pos = Vec3f(pnt[0],pnt[1],pnt[2]);
94  if (bUpdate) point.mesh.color(r,g,b,a);
95  point.update();
96  re -> pipe.line( point );
97 
98  }
99 
100  }
101 
102  } //vsr2D::
103 
104 } //vsr::
105 
106 
107 
108 #endif /* ----- #ifndef vsr_cga2D_render_INC ----- */
109 
110 
NVec< 5 > Vec
Vector
Definition: vsr_cga3D_types.h:62
Definition: vsr_cga2D_draw.h:13
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
NLin< 5 > Lin
Line
Definition: vsr_cga3D_types.h:80
NPar< 5 > Par
Pair
Definition: vsr_cga3D_types.h:73
Cir Circle
Direct Circle 3-blade \(\kappa=p_a \wedge p_b \wedge p_c\)
Definition: vsr_cga3D_types.h:130
NDll< 5 > Dll
DualLine
Definition: vsr_cga3D_types.h:79
Pnt Point
Null Vector \(p=\{e_1,e_2,e_3,n_o,n_\infty\}\)
Definition: vsr_cga3D_types.h:128
the versor library namespace
Definition: vsr_algebra.h:29
Lin Line
Direct Line Trivector \(p_a \wedge p_b \wedge n_\infty\)
Definition: vsr_cga3D_types.h:140
NPnt< 5 > Pnt
Point
Definition: vsr_cga3D_types.h:72
NSph< 5 > Sph
Sphere
Definition: vsr_cga3D_types.h:75
Sph Sphere
Direct Sphere 4-blade \(\Sigma=p_a \wedge p_b \wedge p_c \wedge p_d\)
Definition: vsr_cga3D_types.h:131