Mercurial > hg > ccmieditor
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/native/Falcon/HapticManager.h Tue Jul 10 22:39:37 2012 +0100 @@ -0,0 +1,130 @@ +/* + CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool + + Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#include "CollectionsManager.h" +#include <HAPI/AnyHapticsDevice.h> +#include <HAPI/GodObjectRenderer.h> + +#include <HAPI/HapticPointSet.h> +#include <HAPI/HapticLineSet.h> +#include <HAPI/HapticSpring.h> +#include <HAPI/HapticShapeConstraint.h> + +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glut.h> + + + +class HapticManager +{ + CollectionsManager *cm ; + void (*executeCommand)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy); + HAPI::AnyHapticsDevice *hd; + /* The force effect in use. Contains 0 if there is no force effect in use. */ + H3DUtil::AutoRef<HAPI::HAPIForceEffect> force_effect; + /* the current set of haptic lines. It's used as argument when adding a constraint effect to the hapitc * + * device and it's filled up with the edges of the current diagram through the collection manager */ + vector< HAPI::Collision::LineSegment> line_set; + vector<HAPI::Collision::Point> point_set; + map<HAPI::Collision::Point*,int> point_id_map; + map<HAPI::Collision::LineSegment*,int> line_id_map; + /* in order not to utter continuosly the touched node/edge name, keep track of the node/edge that was * + * last touched and avoid to utter its name unless the proxy touches another node/edge or goes far enough */ + HAPI::Collision::Point* last_touched_point; + HAPI::Collision::LineSegment* last_touched_line; + HAPI::Vec3 proxy_pos; + HAPI::HAPIInt32 pressed_button; + + enum {STICKY, LOOSE} magnetic_mode; + bool magnetic_mode_changed; + + enum {START_DRAGGING, DRAGGING, RELEASED} pickup_mode; + HAPI::Collision::Point *pickedup_point; + HAPI::Collision::LineSegment *pickedup_line; + HAPI::Vec3 pickup_line_pos; + HAPI::Vec3 last_dragging_pos; + + int attract_to; + enum {NO_ATTRACTION ,STOP_ATTRACTION, ACTIVE} attraction_mode; + + bool object_unselected; + + /* how bigger graphic coordinates are than haptic coordinates */ + static const int GRAPHIC_SCALE; + static const int SPRING_FORCE_FACTOR; + static const int LINE_FORCE_FACTOR_LOOSE; + static const int LINE_FORCE_FACTOR_STICKY; + static const int POINT_FORCE_FACTOR; + static const double POINT_COLLISION_THRESHOLD; + static const double LINE_COLLISION_THRESHOLD; + static const double DRAGGING_SOUND_THRESHOLD; + + /* commands sent to the java thread */ + static const char MOVE_CMD; + static const char PLAY_SOUND_CMD; + static const char SPEAK_NAME_CMD; + static const char PICKUP_CMD; + static const char SPEAK_INFO_CMD; + static const char SELECT_CMD; + static const char UNSELECT_CMD; + + /* arguments for PLAY_SOUND_CMD */ + static const int LOOSE_MODE_SOUND; + static const int STICKY_MODE_SOUND; + static const int DRAGGING_SOUND; + + static const HAPI::HAPIInt32 FRONT_BUTTON; + static const HAPI::HAPIInt32 LEFT_BUTTON; + static const HAPI::HAPIInt32 RIGHT_BUTTON; + static const HAPI::HAPIInt32 REAR_BUTTON; + static const HAPI::HAPIInt32 NO_BUTTON; +public: + HapticManager(CollectionsManager * cManager, void (*func)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy)); + + /* try and initialize the haptic device, return false if the initialization fails */ + bool init(void); + + /* drawing routines (both graphically and haptically) */ + void drawCursor(void); + void drawDiagram(bool redrawHapticsScene,bool pickup, int attract_to); + + /* collisions routines: check if the proxy is touching a node or an edge */ + bool checkNodeCollision(void); + bool checkEdgeCollision(void); + + /* check if an unselection command must be issued. Commands cannot be issued in the drawDiagram * + * as it might possibly result in a deadlock. Therefore in drawDiagram the inner flag variable * + * object_unselected is set if necessary, and then when this method is called, the command is * + * issued if the flad was set to true */ + bool checkUnselection(void); + + /* check buttons routine */ + bool checkButtons(void); + + /* routine that plays chain sound during motion if an object is being dragged */ + bool checkMotion(); + + /* release the allocated resources */ + void dispose(void); + + /* a null id value for Java nodes and edges. The id used for nodes and edges is * + * the hashCode of the Java object, therefore a zero value will work for NO_ID */ + static const int NO_ID; +};