versor  3.0
C++11 library for Geometric algebra
vsr_cga3D_app.h
1 /*
2  * =====================================================================================
3  *
4  * Filename: vsr_cga3D_app.h
5  *
6  * Description: utility for cga demos which binds with gfx and glv
7  *
8  * Version: 1.0
9  * Created: 01/26/2015 17:29:12
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Pablo Colapinto (), gmail -> wolftype
14  * Organization: pretty awesome
15  *
16  * =====================================================================================
17  */
18 
19 
20 #ifndef vsr_cga3D_app_INC
21 #define vsr_cga3D_app_INC
22 
23 #include "space/vsr_cga3D_op.h" //<-- conformal 3D types and basic
24 
25 #include "draw/vsr_cga3D_draw.h" //<-- fixed pipeline draw routines
26 #include "draw/vsr_cga3D_render.h" //<-- programmable pipeline draw routines
27 
28 #include "util/vsr_cga3D_control.h" //<-- interface controls (mouse and keyboard)
29 #include "gfx/util/gfx_glv_app.h" //<-- an app class with built-in gui
30 
31 //GL2PS
32 #include "gl2ps/gl2ps.h"
33 
34 
35 struct App : public gfx::GFXAppGui {
36 
37  vsr::cga::Point mMouse2D;
38  vsr::cga::Point mMouse3D;
39  vsr::cga::Line mMouseRay;
40 
41  bool bShadedOutput = true;
42 
43  vsr::cga::Point calcMouse3D(float z=.99){
44 
45  auto& vd = gfx::GFXAppGui::mContext.interface.io.viewdata;
46  auto tv = vd.ray;
47 
48  auto p = scene.unproject( io().pos(z) ); //vd.projectMid;
49 
50  Vec tz (tv[0], tv[1], tv[2] );
51 
52  mMouse2D = vsr::cga::Construct::point(p[0],p[1],0);
53  mMouse3D = vsr::cga::Construct::point(p[0],p[1],p[2]);
54  mMouseRay = mMouse3D ^ tz ^ vsr::cga::Infinity(1);
55 
56  //intersection of ray with plane
57  mMouse3D = vsr::cga::Construct::meet( mMouseRay, vsr::cga::DualPlane(tz) );
58 
59  return mMouse3D;
60 
61  }
62 
64  virtual void onKeyDown(const gfx::Keyboard& k){
65  switch(k.code){
66  case 'v':
67  printf("v\n");
68  GL::enablePreset();
69  scene.push(true);
70  gl2ps();
71  scene.pop(true);
72  GL::disablePreset();
73  }
74  }
75 
76 
77  void gl2ps(){
78  static int id = 0;
79  stringstream os; os << "output_" << id << (bShadedOutput ? ".eps" : ".pdf");
80  id++;
81 
82  FILE *fp;
83  int state = GL2PS_OVERFLOW, buffsize = 0;
84 
85  string name = os.str();
86  fp = fopen(name.c_str(), "wb");
87 
88  printf("writing %s to %s\n", os.str().c_str(), name.c_str() );
89  GLint tv[4];
90  glGetIntegerv(GL_VIEWPORT, tv);
91 
92 
93  while(state == GL2PS_OVERFLOW){
94 
95  buffsize += 1024*1024;
96 
97  if (bShadedOutput){
98  gl2psBeginPage("test", "gl2psTestSimple", tv , GL2PS_EPS, GL2PS_SIMPLE_SORT, //NO_SORT
99  GL2PS_BEST_ROOT | GL2PS_TIGHT_BOUNDING_BOX | GL2PS_SIMPLE_LINE_OFFSET | GL2PS_OCCLUSION_CULL, //
100  GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps");
101  } else {
102  gl2psBeginPage("test", "gl2psTestSimple", tv , GL2PS_PDF, GL2PS_NO_SORT,
103  GL2PS_NO_PS3_SHADING | GL2PS_BEST_ROOT | GL2PS_TIGHT_BOUNDING_BOX | GL2PS_OCCLUSION_CULL, //
104  GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps");
105  }
106 
107  gl2psEnable(GL2PS_BLEND);
108  gl2psBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
109  gl2psPointSize(10);
110  gl2psLineWidth(1);
111 
112 
113 
114  //DRAW
115  onDraw();
116 
117  state = gl2psEndPage();
118  }
119 
120  fclose(fp);
121  printf("Done!\n");
122  }
123 
124 
125 };
126 
127 #endif /* ----- #ifndef vsr_cga3D_app_INC ----- */
static Circle meet(const Dls &s, const Dls &d)
circle intersection of dual spheres
Common Operations Specific to CGA3D.
NVec< 5 > Vec
Vector
Definition: vsr_cga3D_types.h:62
virtual void onKeyDown(const gfx::Keyboard &k)
Called when a keyboard key is pressed.
Definition: vsr_cga3D_app.h:64
static Point point(const Circle &c, VSR_PRECISION t)
Point on Circle at theta t.
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
Inf Infinity
Null Infinity Blade: \(n_\infty\)
Definition: vsr_cga3D_types.h:125
Definition: vsr_cga3D_app.h:35