annotate native/PhantomOmni/HapticManager.h @ 8:ea7885bd9bff tip

fixed bug : render solid line as dotted/dashed when moving the stylus from dotted/dashed to solid
author ccmi-guest
date Thu, 03 Jul 2014 16:12:20 +0100
parents 9e67171477bc
children
rev   line source
fiore@3 1 #pragma once
fiore@3 2 #include "stdAfx.h"
fiore@3 3 #include <time.h>
fiore@3 4 #include "HapticException.h"
fiore@3 5 #include "CollectionsManager.h"
fiore@3 6
fiore@3 7 #define NOVIBRATION
fiore@3 8
fiore@3 9 /* The haptic manager draws the diagram openGL scene haptically. *
fiore@3 10 * In order to get all the data about the diagram it's constructed *
fiore@3 11 * passing a reference to the CollectionManager */
fiore@3 12 class HapticManager
fiore@3 13 {
fiore@3 14 enum AttractionStatus {START_ATTRACTION, DOING_ATTRACTION, NO_ATTRACTION, STOP_ATTRACTION};
fiore@3 15 enum SpringStatus { DRAGGING, RELEASED, START_DRAGGING, STOP_DRAGGING };
fiore@3 16 enum VibrationStatus { START_VIBRATION , DOING_VIBRATION , NO_VIBRATION, CAN_VIBRATE};
fiore@3 17
fiore@3 18
fiore@3 19 /* Haptic device and rendering context handles. */
fiore@3 20 HLuint wall1Id;
fiore@3 21 HLuint wall2Id;
fiore@3 22 HLuint frictionFX;
fiore@3 23 HLuint vibrationFX;
fiore@3 24 HLuint attractionFX;
fiore@3 25 HLuint springFX;
fiore@3 26 VibrationStatus vibrationStatus;
fiore@3 27 AttractionStatus attractionStatus;
fiore@3 28 SpringStatus springStatus;
fiore@3 29 #ifdef VIBRATION
fiore@3 30 static const HDdouble VIBRATION_AMPLITUDE;
fiore@3 31 static const HDint VIBRATION_FREQUENCY;
fiore@3 32 static const unsigned int VIBRATION_DURATION;
fiore@3 33 #endif
fiore@3 34 static const double EDGE_SHORTEND_VAL;
fiore@3 35 static const double EDGE_SPEECH_DISTANCE_WHEN_LEAVING_NODE;
fiore@3 36 static const unsigned int CLICK_INTERVAL;
fiore@3 37 clock_t clickStart;
fiore@3 38 clock_t vibrationEnd;
fiore@3 39 HDdouble forceBeforeVibration[3];
fiore@3 40 CollectionsManager *collectionsManager;
fiore@3 41 bool wall;
fiore@3 42 jint attractToHapticId;
fiore@3 43 bool alreadyTouchingAttractingElement;
fiore@3 44 jdouble attractToCoord[3];
fiore@3 45 // this is needed to calulate the distance between the proxy and the last touched node
fiore@3 46 HLdouble lastTouchedNodePosition[3];
fiore@3 47 HLint lastTouchedNodeID;
fiore@3 48 HLint lastTouchedEdgeID;
fiore@3 49 jint lastTouchedEdgeStipplePattern;
fiore@3 50 HLint lastHighlightElementID;
fiore@3 51 HLint draggedElementID;
fiore@3 52 /* when dropping a node after moving it, unless one detouches and touches again the node,
fiore@3 53 the hlGetShapeBooleanv(HL_PROXY_IS_TOUCHING) routine will return a false value when
fiore@3 54 one tries to hook the node again. Even tough the touch and untouch callback are called
fiore@3 55 correctly. this variable keeps track of the last moved element, setting it to HL_OBJECT_ANY
fiore@3 56 on the detouch callback so that this "buggy" behaviour is worked around
fiore@3 57 */
fiore@3 58 HLuint lastMovedElement;
fiore@3 59 bool stillTouchingLastMovedElement;
fiore@3 60 /* this variable is to workaround the HL_PROXY_IS_TOUCHNIG problem to fix issue of stipple pattern:
fiore@3 61 when dropping a node after having picked it up, then the hlGetShapeBooleanv may return false
fiore@3 62 for all the edges attached to a moved node or for a moved edge. Because of that the stipple
fiore@3 63 pattern for dotted and dashed lines might not be enabled. The check is however necessary to stop the
fiore@3 64 effect when actually untouching the node or when changing tab after the pick up and drop.
fiore@3 65 The variable is set/unset in the touching callbacks which works fine.
fiore@3 66 */
fiore@3 67 bool lastTouchedEdgeIsUntouched;
fiore@3 68 HLdouble springStart[3];
fiore@3 69 GLuint displayList1;
fiore@3 70 GLuint displayList2;
fiore@3 71 bool frictionDisabled;
fiore@3 72 bool doneOnce;
fiore@3 73 bool secondClick;
fiore@3 74 bool stickyMode;
fiore@3 75 bool doubleClick;
fiore@3 76 void drawPlane(float offset);
fiore@3 77 void (*executeCommand)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy);
fiore@3 78
fiore@3 79 static void HLCALLBACK hlButton1CB(HLenum event, HLuint object, HLenum thread,
fiore@3 80 HLcache *cache, void *userdata);
fiore@3 81 static void HLCALLBACK hlButton2CB(HLenum event, HLuint object, HLenum thread,
fiore@3 82 HLcache *cache, void *userdata);
fiore@3 83 static void HLCALLBACK hlTouchCB(HLenum event, HLuint object, HLenum thread,
fiore@3 84 HLcache *cache, void *userdata);
fiore@3 85 static void HLCALLBACK hlUntouchCB(HLenum event, HLuint object, HLenum thread,
fiore@3 86 HLcache *cache, void *userdata);
fiore@3 87 static void HLCALLBACK hlMotionCB(HLenum event, HLuint object, HLenum thread,
fiore@3 88 HLcache *cache, void *userdata);
fiore@3 89 #ifdef VIBRATION
fiore@3 90 static void HLCALLBACK vibrationCB(HDdouble force[3], HLcache *cache, void *userdata);
fiore@3 91
fiore@3 92 static void HLCALLBACK beforeVibrationCB(HLcache *cache, void *userdata);
fiore@3 93
fiore@3 94 static void HLCALLBACK afterVibrationCB(HLcache *cache, void *userdata);
fiore@3 95 #endif
fiore@3 96
fiore@3 97 public:
fiore@3 98
fiore@3 99 enum ClickStatus { NO_CLICK, ONE_CLICK, TWO_CLICK };
fiore@3 100
fiore@3 101 static HHD ghHD;
fiore@3 102 static HHLRC ghHLRC;
fiore@3 103 HapticManager(CollectionsManager * cManager, void (*func)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy))
fiore@3 104 : executeCommand(func), wall(true), collectionsManager(cManager), vibrationStatus(NO_VIBRATION), springStatus(RELEASED), alreadyTouchingAttractingElement(false),
fiore@3 105 doneOnce(false), attractionStatus(NO_ATTRACTION), frictionDisabled(false), secondClick(false), clickStart(0), stickyMode(true),
fiore@3 106 lastMovedElement(HL_OBJECT_ANY),stillTouchingLastMovedElement(false),lastTouchedEdgeIsUntouched(false){};
fiore@3 107 ~HapticManager(void) {}
fiore@3 108 void init(void) throw(HapticException);
fiore@3 109 void draw(void);
fiore@3 110 void setAttractTo(jint hapticId);
fiore@3 111 void pickUp(jint hapticId);
fiore@3 112 bool wasAlreadyTouchingAttractingElement(void);
fiore@3 113
fiore@3 114 void enableWall(void){ wall = true; }
fiore@3 115 void disableWall(void){ wall = false; }
fiore@3 116
fiore@3 117 bool isDraggingNode() const { return springStatus == DRAGGING && collectionsManager->isNode(draggedElementID); }
fiore@3 118 bool isDraggingEdge() const { return springStatus == DRAGGING && collectionsManager->isEdge(draggedElementID); }
fiore@3 119 ClickStatus getButton1Status();
fiore@3 120 void doButton1Click(bool doubleClick);
fiore@3 121
fiore@3 122 };