fiore@5
|
1 /*
|
fiore@5
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
fiore@5
|
3
|
fiore@5
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
fiore@5
|
5
|
fiore@5
|
6 This program is free software: you can redistribute it and/or modify
|
fiore@5
|
7 it under the terms of the GNU General Public License as published by
|
fiore@5
|
8 the Free Software Foundation, either version 3 of the License, or
|
fiore@5
|
9 (at your option) any later version.
|
fiore@5
|
10
|
fiore@5
|
11 This program is distributed in the hope that it will be useful,
|
fiore@5
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
fiore@5
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
fiore@5
|
14 GNU General Public License for more details.
|
fiore@5
|
15
|
fiore@5
|
16 You should have received a copy of the GNU General Public License
|
fiore@5
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
fiore@5
|
18 */
|
fiore@5
|
19 #pragma once
|
fiore@5
|
20 #include "CollectionsManager.h"
|
fiore@5
|
21 #include <HAPI/AnyHapticsDevice.h>
|
fiore@5
|
22 #include <HAPI/GodObjectRenderer.h>
|
fiore@5
|
23
|
fiore@5
|
24 #include <HAPI/HapticPointSet.h>
|
fiore@5
|
25 #include <HAPI/HapticLineSet.h>
|
fiore@5
|
26 #include <HAPI/HapticSpring.h>
|
fiore@5
|
27 #include <HAPI/HapticShapeConstraint.h>
|
fiore@5
|
28
|
fiore@5
|
29 #include <GL/gl.h>
|
fiore@5
|
30 #include <GL/glu.h>
|
fiore@5
|
31 #include <GL/glut.h>
|
fiore@5
|
32
|
fiore@5
|
33
|
fiore@5
|
34
|
fiore@5
|
35 class HapticManager
|
fiore@5
|
36 {
|
fiore@5
|
37 CollectionsManager *cm ;
|
fiore@5
|
38 void (*executeCommand)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy);
|
fiore@5
|
39 HAPI::AnyHapticsDevice *hd;
|
fiore@5
|
40 /* The force effect in use. Contains 0 if there is no force effect in use. */
|
fiore@5
|
41 H3DUtil::AutoRef<HAPI::HAPIForceEffect> force_effect;
|
fiore@5
|
42 /* the current set of haptic lines. It's used as argument when adding a constraint effect to the hapitc *
|
fiore@5
|
43 * device and it's filled up with the edges of the current diagram through the collection manager */
|
fiore@5
|
44 vector< HAPI::Collision::LineSegment> line_set;
|
fiore@5
|
45 vector<HAPI::Collision::Point> point_set;
|
fiore@5
|
46 map<HAPI::Collision::Point*,int> point_id_map;
|
fiore@5
|
47 map<HAPI::Collision::LineSegment*,int> line_id_map;
|
fiore@5
|
48 /* in order not to utter continuosly the touched node/edge name, keep track of the node/edge that was *
|
fiore@5
|
49 * last touched and avoid to utter its name unless the proxy touches another node/edge or goes far enough */
|
fiore@5
|
50 HAPI::Collision::Point* last_touched_point;
|
fiore@5
|
51 HAPI::Collision::LineSegment* last_touched_line;
|
fiore@5
|
52 HAPI::Vec3 proxy_pos;
|
fiore@5
|
53 HAPI::HAPIInt32 pressed_button;
|
fiore@5
|
54
|
fiore@5
|
55 enum {STICKY, LOOSE} magnetic_mode;
|
fiore@5
|
56 bool magnetic_mode_changed;
|
fiore@5
|
57
|
fiore@5
|
58 enum {START_DRAGGING, DRAGGING, RELEASED} pickup_mode;
|
fiore@5
|
59 HAPI::Collision::Point *pickedup_point;
|
fiore@5
|
60 HAPI::Collision::LineSegment *pickedup_line;
|
fiore@5
|
61 HAPI::Vec3 pickup_line_pos;
|
fiore@5
|
62 HAPI::Vec3 last_dragging_pos;
|
fiore@5
|
63
|
fiore@5
|
64 int attract_to;
|
fiore@5
|
65 enum {NO_ATTRACTION ,STOP_ATTRACTION, ACTIVE} attraction_mode;
|
fiore@5
|
66
|
fiore@5
|
67 bool object_unselected;
|
fiore@5
|
68
|
fiore@5
|
69 /* how bigger graphic coordinates are than haptic coordinates */
|
fiore@5
|
70 static const int GRAPHIC_SCALE;
|
fiore@5
|
71 static const int SPRING_FORCE_FACTOR;
|
fiore@5
|
72 static const int LINE_FORCE_FACTOR_LOOSE;
|
fiore@5
|
73 static const int LINE_FORCE_FACTOR_STICKY;
|
fiore@5
|
74 static const int POINT_FORCE_FACTOR;
|
fiore@5
|
75 static const double POINT_COLLISION_THRESHOLD;
|
fiore@5
|
76 static const double LINE_COLLISION_THRESHOLD;
|
fiore@5
|
77 static const double DRAGGING_SOUND_THRESHOLD;
|
fiore@5
|
78
|
fiore@5
|
79 /* commands sent to the java thread */
|
fiore@5
|
80 static const char MOVE_CMD;
|
fiore@5
|
81 static const char PLAY_SOUND_CMD;
|
fiore@5
|
82 static const char SPEAK_NAME_CMD;
|
fiore@5
|
83 static const char PICKUP_CMD;
|
fiore@5
|
84 static const char SPEAK_INFO_CMD;
|
fiore@5
|
85 static const char SELECT_CMD;
|
fiore@5
|
86 static const char UNSELECT_CMD;
|
fiore@5
|
87
|
fiore@5
|
88 /* arguments for PLAY_SOUND_CMD */
|
fiore@5
|
89 static const int LOOSE_MODE_SOUND;
|
fiore@5
|
90 static const int STICKY_MODE_SOUND;
|
fiore@5
|
91 static const int DRAGGING_SOUND;
|
fiore@5
|
92
|
fiore@5
|
93 static const HAPI::HAPIInt32 FRONT_BUTTON;
|
fiore@5
|
94 static const HAPI::HAPIInt32 LEFT_BUTTON;
|
fiore@5
|
95 static const HAPI::HAPIInt32 RIGHT_BUTTON;
|
fiore@5
|
96 static const HAPI::HAPIInt32 REAR_BUTTON;
|
fiore@5
|
97 static const HAPI::HAPIInt32 NO_BUTTON;
|
fiore@5
|
98 public:
|
fiore@5
|
99 HapticManager(CollectionsManager * cManager, void (*func)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy));
|
fiore@5
|
100
|
fiore@5
|
101 /* try and initialize the haptic device, return false if the initialization fails */
|
fiore@5
|
102 bool init(void);
|
fiore@5
|
103
|
fiore@5
|
104 /* drawing routines (both graphically and haptically) */
|
fiore@5
|
105 void drawCursor(void);
|
fiore@5
|
106 void drawDiagram(bool redrawHapticsScene,bool pickup, int attract_to);
|
fiore@5
|
107
|
fiore@5
|
108 /* collisions routines: check if the proxy is touching a node or an edge */
|
fiore@5
|
109 bool checkNodeCollision(void);
|
fiore@5
|
110 bool checkEdgeCollision(void);
|
fiore@5
|
111
|
fiore@5
|
112 /* check if an unselection command must be issued. Commands cannot be issued in the drawDiagram *
|
fiore@5
|
113 * as it might possibly result in a deadlock. Therefore in drawDiagram the inner flag variable *
|
fiore@5
|
114 * object_unselected is set if necessary, and then when this method is called, the command is *
|
fiore@5
|
115 * issued if the flad was set to true */
|
fiore@5
|
116 bool checkUnselection(void);
|
fiore@5
|
117
|
fiore@5
|
118 /* check buttons routine */
|
fiore@5
|
119 bool checkButtons(void);
|
fiore@5
|
120
|
fiore@5
|
121 /* routine that plays chain sound during motion if an object is being dragged */
|
fiore@5
|
122 bool checkMotion();
|
fiore@5
|
123
|
fiore@5
|
124 /* release the allocated resources */
|
fiore@5
|
125 void dispose(void);
|
fiore@5
|
126
|
fiore@5
|
127 /* a null id value for Java nodes and edges. The id used for nodes and edges is *
|
fiore@5
|
128 * the hashCode of the Java object, therefore a zero value will work for NO_ID */
|
fiore@5
|
129 static const int NO_ID;
|
fiore@5
|
130 };
|