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