frameManipulator.h 11.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
 * Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library is distributed in the hope that it will be useful, but WITHOUT  *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
 * Web site: http://cgogn.u-strasbg.fr/                                         *
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/


#ifndef __FRAMEMANIPULATOR_H_
#define __FRAMEMANIPULATOR_H_

#include "Utils/vbo.h"
#include "glm/glm.hpp"
//#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pickables.h"

namespace CGoGN
{

namespace Utils
{


//
//
//class LineDrawable
//{
//protected:
//
//	/**
//	 * VBO for position
//	 */
//	Utils::VBO* m_vboPos;
//
//	/**
//	 * Shader
//	 */
//	Utils::ShaderSimpleColor* m_shader;
//
//	/**
//	 * number of indices in vbo
//	 */
//	unsigned int m_nb;
//
//public:
//	/**
//	 * constructor
//	 */
//	LineDrawable();
//
//	/**
//	 * destructor
//	 */
//	virtual ~LineDrawable();
//
//	/**
//	 * set the color of drawing
//	 */
//	void setColor(const Geom::Vec4f& col);
//
//	/**
//	 * draw the Drawable at origin with size=1
//	 */
//	virtual void draw();
//
//	/**
//	 * picking
//	 * @param P camera point
//	 * @param V vector ray direction
//	 * @param epsilon distance epsilon for picking
//	 * @return code picking (0: nothing picked / != 0 something picked)
//	 */
//	virtual unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f) = 0;
//
//};
//
//
//class Pickable
//{
//protected:
//	/**
//	 * type of drawable
//	 */
//	LineDrawable* m_drawable;
//
//	/**
//	 * transformation matrix
//	 */
//	glm::mat4 m_transfo;
//
//	/**
//	 * id of pickable
//	 */
//	unsigned int m_id;
//
//public:
//	/**
//	 * constructor
//	 * @param ld LineDrawable to use for drawing & picking
//	 */
//	Pickable(LineDrawable* ld, unsigned int id):
//		m_drawable(ld),m_transfo(1.0f), m_id(id)
//		{}
//
//	/**
//	 * picking
//	 * @param P camera point
//	 * @param V vector ray direction
//	 * @param epsilon distance epsilon for picking
//	 * @return code picking (0: nothing picked / != 0 something picked)
//	 */
//	unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//
//	/**
//	 * apply inverse transfo on picking ray
//	 */
//	static void invertPV(const Geom::Vec3f& P, const Geom::Vec3f& V, const glm::mat4& transfo, Geom::Vec3f& PP, Geom::Vec3f& VV);
//
//	/**
//	 * draw
//	 */
//	void draw() { m_drawable->draw();}
//
//	/**
//	 * return a ref on the transformation matrix
//	 */
//	glm::mat4&  transfo();
//
//	void rotate(float angle, const Geom::Vec3f& Axis);
//
//	void translate(const Geom::Vec3f& P);
//
//	void scale(const Geom::Vec3f& S);
//
//	/**
//	 * pick a vector of pickable and return the closest
//	 */
//	static unsigned int pick(const std::vector<Pickable*>& picks,const Geom::Vec3f& P, const Geom::Vec3f& V, Pickable*& res);
//
//	float distancefrom(const Geom::Vec3f& P);
//
//
//};
//
//
///**
// * Grid (-1,-1,0 ; 1,1,0)
// */
//class Grid: public LineDrawable
//{
//public:
//	/**
//	 * constructor
//	 * @param sub number of subdivision of grig
//	 */
//	Grid(unsigned int sub=5);
//
//	/**
//	 * change topo subdivision
//	 */
//	void changeTopo(unsigned int sub);
//
//	/**
//	 * picking
//	 */
//	unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
///**
// * Sphere of radius 1 drawon with lines
// */
//class Sphere: public LineDrawable
//{
//protected:
//	GLuint m_ind;
//public:
//	/**
//	 * constructor
//	 * @param par number of parallels
//	 * @param mer number of meridians
//	 */
//	Sphere(unsigned int par=5, unsigned int mer=5);
//
//	/**
//	 * change topo subdivision
//	 */
//	void changeTopo(unsigned int par, unsigned int mer);
//
//	/**
//	 * specific drawing function for sphere (with indexed vbos)
//	 */
//	void draw();
//
//	/**
//	 * picking
//	 */
//	unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
///**
// * Cone of radius 1 drawon with lines
// */
//class Cone: public Sphere
//{
//public:
//	/**
//	 * constructor
//	 * @param par number of parallels
//	 * @param mer number of meridians
//	 */
//	Cone(unsigned int par=5, unsigned int mer=5);
//
//	/**
//	 * change topo subdivision
//	 */
//	void changeTopo(unsigned int par, unsigned int mer);
//
//	/**
//	 * picking
//	 */
//	unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
///**
// * Cone of radius 1 drawon with lines
// */
//class Cylinder: public Sphere
//{
//public:
//	/**
//	 * constructor
//	 * @param par number of parallels
//	 * @param mer number of meridians
//	 */
//	Cylinder(unsigned int par=5, unsigned int mer=5);
//
//	/**
//	 * change topo subdivision
//	 */
//	void changeTopo(unsigned int par, unsigned int mer);
//
//	/**
//	 * picking
//	 */
//	unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
///**
// * Sphere of radius 1 drawon with lines
// */
//class Cube: public LineDrawable
//{
//protected:
//	GLuint m_ind;
//public:
//	/**
//	 * constructor
//	 * @param par number of parallels
//	 * @param mer number of meridians
//	 */
//	Cube(unsigned int sub=0);
//
//	/**
//	 * destructor
//	 */
//	~Cube();
//
//	/**
//	 * change topo subdivision
//	 */
//	void changeTopo(unsigned int sub);
//
//	/**
//	 * specific drawing function for sphere (with indexed vbos)
//	 */
//	void draw();
//
//	/**
//	 * picking
//	 */
//	unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//


class FrameManipulator//: public Pickable
{
public:
311
	enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs, Translations, Rotations, Scales};
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

protected:

	/**
	 * number of segment for circle drawing
	 */
	static const unsigned int nb_segments = 64;

	static const float ring_half_width = 0.08f;


	/**
	 * locking table
	 */
	bool m_locked_axis[11];

328
329
330
331
332
	/**
	 * pinking only locking table
	 */
	bool m_lockedPicking_axis[11];

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
	/**
	 * VBO for position
	 */
	Utils::VBO* m_vboPos;

	/**
	 * VBO for color
	 */
	Utils::VBO* m_vboCol;

	/**
	 * Shader
	 */
	Utils::ShaderSimpleColor* m_shader;

	/**
	 * the axis to be highlighted
	 */
	unsigned int m_highlighted;

	/**
	 * Rotation matrices
	 */
	glm::mat4 m_rotations;

	/**
	 * scale rendering factor
	 */
	float m_scaleRendering;

	/**
	 * translation
	 */
	glm::vec3 m_trans;

	/**
	 * scale
	 */
	glm::vec3 m_scale;

	/**
	 * epsilon distance for picking
	 */
	float m_epsilon;

	/**
	 * compute and set length axes / scale factors
	 */
	void setLengthAxes();

	/**
	 * length of axes
	 */
	Geom::Vec3f m_lengthAxes;

	Geom::Vec3f m_projectedSelectedAxis;

	Geom::Vec3f m_projectedOrigin;

	/**
	 * get the matrix transformation with the scale factor for rendering
	 */
	glm::mat4 transfoRenderFrame();

397
398
	bool axisPickable(unsigned int a) { return (!m_locked_axis[a]) && (!m_lockedPicking_axis[a]);}

399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
public:
	FrameManipulator();

	/**
	 * set size of frame (for rendering)
	 */
	void setSize(float radius);

	/**
	 * add a (signed) val to the size of frame
	 */
	void addSize(float val);

	/**
	 * get the size of frame
	 */
	float getSize();

	/**
	 * draw the frame
	 */
	void draw();

	/**
	 * try picking the frame
	 */
	 unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);


	 /**
429
430
	  * lock an axis (drawing & picking are disabled)
	  * @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
431
432
433
434
435
	  */
	 void lock(unsigned int axis);

	 /**
	  * unlock an axis
436
	  * @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
437
438
439
	  */
	 void unlock(unsigned int axis);

Sylvain Thery's avatar
Sylvain Thery committed
440
441
	 /**
	  * is an axis locked
442
	  * @param axis the axis to test
Sylvain Thery's avatar
Sylvain Thery committed
443
444
445
	  */
	 bool locked(unsigned int axis);

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
	 /**
	  * lock an axis only for pinking
	  */
	 void lockPicking(unsigned int axis);

	 /// lock translations for picking only
	 void lockPickingTranslations();

	 /// lock rotations for picking only
	 void lockPickingRotations();

	 /// lock scales for picking only
	 void lockPickingScales();

	 /**
	  * unlock an axis (only for pinking)
	  */
	 void unlockPicking(unsigned int axis);

	 /// unlock translations for picking only
	 void unlockPickingTranslations();

	 /// unlock rotations for picking only
	 void unlockPickingRotations();

	 /// unlock scales for picking only
	 void unlockPickingScales();
	 /**
	  * is an axis locked (only for pinking)
	  */
	 bool lockedPicking(unsigned int axis);

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
	/**
	 * higlight an axis (change width rendering).
	 * To unhighlight, just highlight NONE or highlight a already highlighted  axis
	 */
	void highlight(unsigned int axis);

	/**
	 * rotate the frame around one of its axis
	 */
	void rotate(unsigned int axis, float angle);

	/**
	 * translate the frame around one of its axis
	 * @param axis
	 * @param x ratio of frame radius
	 */
	void translate(unsigned int axis, float x);

	/**
	 * scale the frame in direction of one axis
	 * @param axis (Xs/Ys/Zs/CENTER)
	 * @param sc scale factor to apply on
	 */
	void scale(unsigned int axis, float sc);




	/**
	 * get the matrix transformation
	 */
	glm::mat4 transfo();

	/**
	 * set the position of frame
	 * @param P the position of origin
	 */
	void setTranslation(const Geom::Vec3f& P);

	Geom::Vec3f getPosition() { return Geom::Vec3f(m_trans[0],m_trans[1],m_trans[2]);}

	Geom::Vec3f getAxis(unsigned int ax);

//	void project(unsigned int ax, Geom::Vec3f& origin, Geom::Vec3f& vect);

	void storeProjection(unsigned int ax);

	/**
	 * set the scale of frame
	 * @param P the vector of scale factors
	 */
	void setScale(const Geom::Vec3f& S);

	/**
	 * set the orientation of frame (Z is deduced)
	 * @param X the vector X of frame
	 * @param Y the vector Y of frame
	 * @return return false if parameters are not unit orthogonal vectors
	 */
	bool setOrientation(const Geom::Vec3f& X, const Geom::Vec3f& Y);

	/**
	 * set transformation matrix
	 */
	void setTransformation( const glm::mat4& transfo);



	float angleFromMouse(int x, int y, int dx, int dy);

	float distanceFromMouse(int dx, int dy);

	float scaleFromMouse(int dx, int dy);

//	float factorCenterFromMouse(int dx, int dy);

	static bool rotationAxis(unsigned int axis) { return (axis>=Xr) && (axis<=Zr);}
	static bool translationAxis(unsigned int axis) { return (axis>=Xt) && (axis<=Zt);}
	static bool scaleAxis(unsigned int axis) { return ((axis>=Xs) && (axis<=Zs))|| (axis==CENTER);}

Sylvain Thery's avatar
Sylvain Thery committed
558
559
560
561
562
563
	/**
	 * translate from screen mouse move
	 */
	void translateInScreen(int dx, int dy);

	void rotateInScreen(int dx, int dy);
564
565
566
567
568
569
};


}
}
#endif