versor  3.0
C++11 library for Geometric algebra
vsr_cga3D_control.h
1 /*
2  * =====================================================================================
3  *
4  * Filename: vsr_cga3D_control.h
5  *
6  * Description: bindings to gfx_control.
7  *
8  *
9  * Version: 1.0
10  * Created: 11/17/2014 12:22:29
11  * Revision: none
12  * Compiler: gcc
13  *
14  * Author: Pablo Colapinto (), gmail -> wolftype
15  * Organization: pretty awesome
16  *
17  * =====================================================================================
18  */
19 
20 
21 #ifndef VSR_CGA3D_CONTROL_H_INCLUDED
22 #define VSR_CGA3D_CONTROL_H_INCLUDED
23 
24 #include <sstream>
25 
26 #include "gfx/gfx_objectController.h"
27 
28 #include "space/vsr_cga3D_op.h"
29 #include "form/vsr_cga3D_frame.h"
30 
31 namespace gfx{
32 
33  using namespace vsr;
34  using vsr::cga::Pnt;
35  using vsr::cga::Point;
36  using vsr::cga::Frame;
37  using vsr::cga::Vec;
38  using vsr::cga::Dll;
39  using vsr::cga::Drv;
40  using vsr::cga::Rot;
41  using vsr::cga::Gen;
42 
43  //FOR ALL ROUND MULTIVECTOR TYPES:
44  template<class A>
45  Vec3f ObjectController :: ObjectPtr<A> :: worldPosition(){
46  auto p = cga::Round::loc(*mAddress);
47  return Vec3f(p[0],p[1],p[2]);
48  }
49 
51  template<>
52  Vec3f ObjectController :: ObjectPtr<Frame> :: worldPosition(){
53  auto p = mAddress->pos();
54  return Vec3f(p[0],p[1],p[2]);
55  }
56 
57 
58  //FOR ALL MULTIVECTOR TYPES:
59  template<class A>
60  void ObjectController :: ObjectPtr<A> :: transform (){
61 
62  //Address of State
63  A& ts = *mAddress;
64  //Temp Stored State
65  A& ps = tObject;
66 
67  //Center of Defining Sphere
68  Pnt pnt = cga::Round::loc(ts); //was pos
69 
70  //2D coordinates of Defining Sphere
71  Vec3f sc = i->mScene->project(pos);
72 
73  switch(i->io().keyboard.code){
74 
75  case 's': //SCALE
76  {
77 
78  Vec3f tm1 = i->io().pos() - sc;
79  Vec3f tm2 = i->io().click() - sc;
80 
81  //Drag towards or away from element . . .
82  int neg = (tm1.len() > tm2.len()) ? 1 : -1;
83  float amt = i->io().drag().len() * neg;
84  auto tsd = Gen::dil( pnt, amt);
85 
86  ts = ps.sp( tsd );
87 
88  break;
89  }
90  case 't': //TRANSLATE
91  {
92  Vec3f mdc = i->dragCat() * 10;
93  ts = ps.trs( mdc[0], mdc[1], mdc[2] );
94  break;
95  }
96  case 'r': //ROTATE
97  {
98  auto b = i->axisCat();
99  Dll td = pnt <= (Drv(b[0], b[1], b[2]).dual() );
100  ts = ps.mot( td );
101  break;
102  }
103 
104  default: // DESELECT
105  {
106  // i->deselect(mAddress);
107  break;
108  }
109  }
110 
111  }
112 
113 
114  template<>
115  void ObjectController :: ObjectPtr<Frame> :: transform() {
116 
117  //Address of State
118  Frame& ts = *mAddress;
119  //Temp Stored State
120  Frame& ps = tObject;
121 
122  //Center
123  Pnt pnt = ps.pos();
124 
125  //2D coordinates of Defining Sphere
126  Vec3f sc = i->mScene->project(pos);
127 
128 
129  switch(i->io().keyboard.code){
130  case 's': //SCALE
131  {
132  Vec3f tm1 = i->io().pos() - sc;
133  Vec3f tm2 = i->io().click() - sc;
134 
135  //Drag towards or away from element . . .
136  int neg = (tm1.len() > tm2.len()) ? 1 : -1;
137  float amt = i->io().drag().len() * neg;
138  ts = ps.dilate( amt );
139 
140  break;
141 
142  }
143  case 't': //TRANSLATE
144  {
145  Vec3f mdc = i->dragCat() * 10;
146  ts.pos() = ps.pos().trs( mdc[0], mdc[1], mdc[2] );
147  break;
148  }
149  case 'r': //ROTATE
150  {
151  auto b = i->axisCat();
152  Rot tr = Gen::rot( Vec(b[0],b[1],b[2]).duale() );
153  ts.rot() = tr * ps.rot();
154  break;
155  }
156 
157  default://case 'q': //DESELECT
158  {
159  i->toggleSelect(mAddress);
160  break;
161  }
162  }
163 
164  };
165 
166 
167 }
168 
169 
170 
171 #endif
172 
173 
174 
175 
Common Operations Specific to CGA3D.
NDrv< 5 > Drv
DirectionVector
Definition: vsr_cga3D_types.h:84
NVec< 5 > Vec
Vector
Definition: vsr_cga3D_types.h:62
Definition: vsr_cga2D_draw.h:13
static Rot rot(const Biv &b)
vsr::cga::Rotor from vsr::cga::Bivector
static Point loc(const A &s)
Location (normalizd) of a Round Element (shorthand)
Definition: vsr_cga3D_round.h:146
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
Generators and Logarithms Optimized for 3D Conformal Geometric Algebra.
Definition: vsr_cga3D_op.h:119
the versor library namespace
Definition: vsr_algebra.h:29
Orthonormal Frame composed from a Position and Orientation.
Definition: vsr_cga3D_frame.h:47
NPnt< 5 > Pnt
Point
Definition: vsr_cga3D_types.h:72
3D CGA Orthonormal Frame
static Tsd dil(const Pnt &p, VSR_PRECISION t)
vsr::cga::Dilator from vsr::cga::Point and amt t
NRot< 5 > Rot
Rotor
Definition: vsr_cga3D_types.h:64