fiore@5: /*
fiore@5: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
fiore@5:
fiore@5: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
fiore@5:
fiore@5: This program is free software: you can redistribute it and/or modify
fiore@5: it under the terms of the GNU General Public License as published by
fiore@5: the Free Software Foundation, either version 3 of the License, or
fiore@5: (at your option) any later version.
fiore@5:
fiore@5: This program is distributed in the hope that it will be useful,
fiore@5: but WITHOUT ANY WARRANTY; without even the implied warranty of
fiore@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fiore@5: GNU General Public License for more details.
fiore@5:
fiore@5: You should have received a copy of the GNU General Public License
fiore@5: along with this program. If not, see .
fiore@5: */
fiore@5:
fiore@5: #include "HapticManager.h"
fiore@5:
fiore@5: using namespace HAPI;
fiore@5:
fiore@5: // Render a sphere using OpenGL calls.
fiore@5: void drawSphere() {
fiore@5: GLUquadricObj* pObj = gluNewQuadric();
fiore@5: gluSphere(pObj, 0.0010, 10, 10);
fiore@5: gluDeleteQuadric(pObj );
fiore@5: }
fiore@5:
fiore@5: HapticManager::HapticManager(CollectionsManager * cManager,
fiore@5: void (*func)(
fiore@5: const jchar cmd,
fiore@5: const jint ID,
fiore@5: const jdouble startx,
fiore@5: const jdouble starty,
fiore@5: const jdouble endx,
fiore@5: const jdouble endy)
fiore@5: )
fiore@5: : executeCommand(func), cm(cManager), force_effect(0), last_touched_point(NULL),
fiore@5: last_touched_line(NULL),magnetic_mode(LOOSE), pickup_mode(RELEASED), object_unselected(false),
fiore@5: magnetic_mode_changed(false), pickedup_point(NULL), pickedup_line(NULL) {}
fiore@5:
fiore@5:
fiore@5: bool HapticManager::init (void){
fiore@5:
fiore@5: hd = new AnyHapticsDevice();
fiore@5:
fiore@5: // The haptics renderer to use.
fiore@5: hd->setHapticsRenderer( new HAPI::GodObjectRenderer() );
fiore@5:
fiore@5: /* init the device */
fiore@5: if(hd->initDevice() != HAPIHapticsDevice::SUCCESS){
fiore@5: return false;
fiore@5: }
fiore@5:
fiore@5: /* enable the device ( forces and positions will be updated) */
fiore@5: hd->enableDevice();
fiore@5:
fiore@5: return true;
fiore@5: }
fiore@5:
fiore@5: /* draws the visual diagram every time it's called. The haptic diagram is redrawn only if *
fiore@5: * something has changed in the diagram ( redraw_haptic_scene = true ) as, unlike openGL, *
fiore@5: * it doesn't need to be drawn at each frame but only once */
fiore@5: void HapticManager::drawDiagram(bool redraw_haptics_scene, bool pickup, int _attract_to ){
fiore@5:
fiore@5: /* STOP_ATTRACTION means the object has been reached (or eventually deleted). The attraction *
fiore@5: * force must therefore be stopped and a redrawing of the haptic forces is necessary */
fiore@5: if(attraction_mode == STOP_ATTRACTION){
fiore@5: attraction_mode = NO_ATTRACTION;
fiore@5: attract_to = NO_ID;
fiore@5: redraw_haptics_scene = true;
fiore@5: }
fiore@5:
fiore@5: /* _attract_to is different from NO_ID there is no attraction going on (attraction_mode = NO_ATTRACTION)*
fiore@5: * It differs from STOP_ATTRACTION in that the haptic scene doesn't have to be repainted */
fiore@5: if(_attract_to != NO_ID){
fiore@5: attract_to = _attract_to;
fiore@5: attraction_mode = ACTIVE;
fiore@5: redraw_haptics_scene = true;
fiore@5: }
fiore@5:
fiore@5: if(magnetic_mode_changed){
fiore@5: redraw_haptics_scene = true;
fiore@5: magnetic_mode_changed = false;
fiore@5: }
fiore@5:
fiore@5: if(pickup){
fiore@5: pickup_mode = START_DRAGGING;
fiore@5: redraw_haptics_scene = true;
fiore@5: }
fiore@5:
fiore@5: /* wash before use */
fiore@5: if(redraw_haptics_scene){
fiore@5: point_set.clear();
fiore@5: line_set.clear();
fiore@5: point_id_map.clear();
fiore@5: line_id_map.clear();
fiore@5: }
fiore@5:
fiore@5: /* --- draw the edges --- */
fiore@5: glPushAttrib(GL_ENABLE_BIT);
fiore@5: glColor3f(1.0f,0.0f,0.0f); // Red
fiore@5: glLineWidth(2.0);
fiore@5: glDisable(GL_LIGHTING);
fiore@5: glEnable(GL_COLOR_MATERIAL);
fiore@5: int numEdges = cm->getEdgesNum();
fiore@5: for ( int i = 0; i < numEdges; i++){
fiore@5: /* draw the edge in openGL */
fiore@5: CollectionsManager::EdgeData & ed = cm->getEdgeData(i);
fiore@5: glPushAttrib(GL_ENABLE_BIT);
fiore@5: glLineStipple(1, ed.stipplePattern);
fiore@5: glEnable(GL_LINE_STIPPLE);
fiore@5: glBegin(GL_LINES);
fiore@5: for(unsigned int j = 0; j < ed.getSize(); j++){
fiore@5: for(unsigned int k = j; k < ed.getSize(); k++){
fiore@5: if(ed.adjMatrix[j][k]){
fiore@5: glVertex3d(ed.x[j]*2,ed.y[j]*GRAPHIC_SCALE,0);
fiore@5: glVertex3d(ed.x[k]*2,ed.y[k]*GRAPHIC_SCALE,0);
fiore@5: }
fiore@5: }
fiore@5: }
fiore@5: glEnd();
fiore@5: glPopAttrib();
fiore@5: /* update haptics edge line set if a change in the collection occurred */
fiore@5: if(redraw_haptics_scene){
fiore@5: /* build the vector with the edges*/
fiore@5: for(unsigned int j = 0; j < ed.getSize(); j++){
fiore@5: for(unsigned int k = j; k < ed.getSize(); k++){
fiore@5: if(ed.adjMatrix[j][k]){
fiore@5: line_set.push_back(Collision::LineSegment (
fiore@5: Vec3(ed.x[j],ed.y[j],0),
fiore@5: Vec3(ed.x[k],ed.y[k],0)
fiore@5: ));
fiore@5: }
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: for(vector< HAPI::Collision::LineSegment>::iterator itr = line_set.begin(); itr != line_set.end(); itr++){
fiore@5: line_id_map.insert(pair(&(*itr),ed.hapticId));
fiore@5: }
fiore@5: }
fiore@5: }
fiore@5: glPopAttrib();
fiore@5:
fiore@5: /* --- draw the nodes --- */
fiore@5: int numNodes = cm->getNodesNum();
fiore@5: glColor3f(1.0f, 1.0f, 1.0f); // white
fiore@5: for( int i = 0; i < numNodes; i++){
fiore@5: /* draw the nodes in openGL */
fiore@5: glPushMatrix();
fiore@5: CollectionsManager::NodeData &nd = cm->getNodeData(i);
fiore@5: glTranslated(nd.x*GRAPHIC_SCALE,nd.y*GRAPHIC_SCALE, 0);
fiore@5: drawSphere();
fiore@5: glPopMatrix();
fiore@5:
fiore@5: /* update haptics node line set if a change in the collection occurred */
fiore@5: if(redraw_haptics_scene){
fiore@5: point_set.push_back(Vec3(nd.x,nd.y,0));
fiore@5: point_id_map.insert(pair(&(point_set.back()),nd.hapticId)) ;
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: /* --- update the haptic force if a change in the collection occurred --- */
fiore@5: if(redraw_haptics_scene){
fiore@5: /* reset the effects and set up new one, otherwise they would accumulate */
fiore@5: hd->clearEffects();
fiore@5: /* first lines */
fiore@5: if(!line_set.empty()){
fiore@5: /* force according to the current attraction_mode */
fiore@5: int force_factor = (magnetic_mode == STICKY) ? LINE_FORCE_FACTOR_STICKY : LINE_FORCE_FACTOR_LOOSE;
fiore@5: /* if the user is dragging or looking for an object, the force *
fiore@5: * factor is always loose until she drops or find the object */
fiore@5: if(pickup_mode == DRAGGING || pickup_mode == START_DRAGGING || attraction_mode == ACTIVE){
fiore@5: force_factor = LOOSE;
fiore@5: }
fiore@5:
fiore@5: /* update the force */
fiore@5: force_effect.reset( new HapticShapeConstraint(new HapticLineSet( line_set, 0 ),force_factor));
fiore@5: hd->addEffect(force_effect.get());
fiore@5:
fiore@5: /* recalculate last_touched_line if it was != NULL as the pointed *
fiore@5: object is now destroyed after clear() and replaced with a new one */
fiore@5: if(last_touched_line != NULL){
fiore@5: last_touched_line = NULL;
fiore@5: vector::iterator itr;
fiore@5: Vec3 closest_point, normal, tex_coord;
fiore@5: for( itr=line_set.begin(); itr != line_set.end(); itr++ ){
fiore@5: itr->closestPoint(proxy_pos,closest_point,normal,tex_coord);
fiore@5: if(pointsDistance(closest_point,proxy_pos) < LINE_COLLISION_THRESHOLD){
fiore@5: last_touched_line = &(*itr);
fiore@5: break;
fiore@5: }
fiore@5: }
fiore@5: if(last_touched_line == NULL){
fiore@5: /* touched line was != NULL and now is NULL. It means it has been deleted *
fiore@5: * while being touched, therefore an unselect command must be issued */
fiore@5: object_unselected = true;
fiore@5: }
fiore@5: }
fiore@5: }else if(last_touched_line != NULL){
fiore@5: /* if last_touuched_line was != null it means an edge has been deleted *
fiore@5: * which was being touched, therefore un unselect command must be issued */
fiore@5: object_unselected = true;
fiore@5: /* if there are no lines there cannot be a last touched one */
fiore@5: last_touched_line = NULL;
fiore@5: }
fiore@5:
fiore@5: /* now points */
fiore@5: if(!point_set.empty()){
fiore@5: /* update the force */
fiore@5: force_effect.reset( new HapticShapeConstraint(new HapticPointSet( point_set, 0 ),POINT_FORCE_FACTOR ) );
fiore@5: hd->addEffect(force_effect.get());
fiore@5:
fiore@5: /* recalculate lastTouchedNode if it was != NULL as the pointed object is now destroyed after clear() */
fiore@5: if(last_touched_point != NULL){
fiore@5: last_touched_point = NULL;
fiore@5: vector::iterator itr;
fiore@5: for(itr=point_set.begin(); itr != point_set.end(); itr++ ){
fiore@5: if(pointsDistance(itr->position,proxy_pos) < POINT_COLLISION_THRESHOLD ){
fiore@5: last_touched_point = &(*itr);
fiore@5: break;
fiore@5: }
fiore@5: }
fiore@5: if(last_touched_point == NULL){
fiore@5: /* touched point was != NULL and now is NULL. It means it has been deleted *
fiore@5: * while being touched, therefore an unselect command must be issued */
fiore@5: object_unselected = true;
fiore@5: }
fiore@5: }
fiore@5: }else if(last_touched_point != NULL){
fiore@5: /* if last_touuched_point was != null it means a node has been deleted *
fiore@5: * which was being touched, therefore un unselect command must be issued */
fiore@5: object_unselected = true;
fiore@5: /* if there are no points there cannot be a last touched one */
fiore@5: last_touched_point = NULL;
fiore@5: }
fiore@5:
fiore@5: if(pickup_mode == START_DRAGGING && attraction_mode == NO_ATTRACTION){
fiore@5: force_effect.reset(new HapticSpring(proxy_pos,SPRING_FORCE_FACTOR));
fiore@5: hd->addEffect(force_effect.get());
fiore@5: /* spring force is initialized not pickup_mode goes to DRAGGING*/
fiore@5: pickup_mode = DRAGGING;
fiore@5: }else if(attraction_mode == ACTIVE){
fiore@5: bool found = false;
fiore@5: /* let's look for the object into the nodes */
fiore@5: for(map::iterator itr = point_id_map.begin();itr != point_id_map.end(); itr++){
fiore@5: if( (*itr).second == attract_to ){
fiore@5: force_effect.reset(new HapticSpring(((*itr).first)->position,SPRING_FORCE_FACTOR));
fiore@5: hd->addEffect(force_effect.get());
fiore@5: found = true;
fiore@5: break;
fiore@5: }
fiore@5: }
fiore@5: /* if not found look into the edges */
fiore@5: if(!found){
fiore@5: for(map::iterator itr = line_id_map.begin();itr != line_id_map.end(); itr++){
fiore@5: if( (*itr).second == attract_to ){
fiore@5: HAPI::Collision::LineSegment* line_ptr = (*itr).first;
fiore@5: force_effect.reset(new HapticSpring(
fiore@5: midPoint(line_ptr->start, line_ptr->end),
fiore@5: SPRING_FORCE_FACTOR));
fiore@5: hd->addEffect(force_effect.get());
fiore@5: found = true;
fiore@5: break;
fiore@5: }
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: if(!found){
fiore@5: /* element has been deleted before user could reach it: go back to normal */
fiore@5: attraction_mode = STOP_ATTRACTION;
fiore@5: }
fiore@5:
fiore@5: }
fiore@5: /* just deallocate the memory for the last force effect */
fiore@5: force_effect.reset();
fiore@5: /* tranfer all the forces to the device */
fiore@5: hd->transferObjects();
fiore@5: }
fiore@5: }
fiore@5:
fiore@5:
fiore@5: void HapticManager::drawCursor(){
fiore@5: HAPIHapticsRenderer *hr = hd->getHapticsRenderer();
fiore@5: if( hr ) {
fiore@5: /* save the proxy pos in a global variable */
fiore@5: proxy_pos = static_cast< HAPIProxyBasedRenderer * >(hr)->getProxyPosition();
fiore@5:
fiore@5: glPushMatrix();
fiore@5: glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT);
fiore@5: glTranslatef( (GLfloat)proxy_pos.x*GRAPHIC_SCALE,
fiore@5: (GLfloat)proxy_pos.y*GRAPHIC_SCALE,
fiore@5: (GLfloat)proxy_pos.z );
fiore@5: glEnable(GL_COLOR_MATERIAL);
fiore@5: glColor3f(0.0f, 0.5f, 1.0f);// Blue
fiore@5: drawSphere();
fiore@5: glPopAttrib();
fiore@5: glPopMatrix();
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: bool HapticManager::checkNodeCollision(){
fiore@5: /* if the proxy goes far enough from the last touched node, then *
fiore@5: * lastTouched node can be set back to NULL */
fiore@5: bool do_unselect = false;
fiore@5: if(last_touched_point != NULL){
fiore@5: if(pointsDistance(last_touched_point->position, proxy_pos) > POINT_COLLISION_THRESHOLD){
fiore@5: last_touched_point = NULL;
fiore@5: do_unselect = true;
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: /* find the closest point among those closer than POINT_COLLISION_THRESHOLD */
fiore@5: vector::iterator itr;
fiore@5: HAPI::Collision::Point* found_point = NULL;
fiore@5: double min_dist = POINT_COLLISION_THRESHOLD;
fiore@5: double dist;
fiore@5: for(itr=point_set.begin(); itr != point_set.end(); itr++ ){
fiore@5: if((dist = pointsDistance(itr->position,proxy_pos)) < min_dist ){
fiore@5: found_point = &(*itr);
fiore@5: min_dist = dist;
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: if(found_point != NULL){
fiore@5: /* if the last touched point is the same, it means the cursor was *
fiore@5: * already on it therefore do nothing as the node name is uttered only when *
fiore@5: * the proxy comes across it and not at each frame (it would make a mess) */
fiore@5: if(last_touched_point != found_point){
fiore@5: last_touched_point = found_point;
fiore@5: /* Setting last_touched_line to NULL, means untouching the eventual touching line. *
fiore@5: * When a node is touched, the connected lines are indeed untouched as only one object *
fiore@5: * at time can be touching the position proxy */
fiore@5: last_touched_line = NULL;
fiore@5: int point_id = point_id_map[last_touched_point];
fiore@5: /* select the node for eventual highlighting int the java tree */
fiore@5: executeCommand(SELECT_CMD,point_id,0,0,0,0);
fiore@5: /* utter the name of the node */
fiore@5: executeCommand(SPEAK_NAME_CMD,point_id,0,0,0,0);
fiore@5: if(attraction_mode == ACTIVE && point_id == attract_to){
fiore@5: /* we reached the attracting node, stop the attraction force */
fiore@5: attraction_mode = STOP_ATTRACTION;
fiore@5: }
fiore@5: }
fiore@5: return true;
fiore@5: }
fiore@5:
fiore@5: if(do_unselect)
fiore@5: executeCommand(UNSELECT_CMD,0,0,0,0,0);
fiore@5:
fiore@5: return false;
fiore@5: }
fiore@5:
fiore@5: bool HapticManager::checkEdgeCollision(){
fiore@5: Vec3 closest_point, normal, tex_coord;
fiore@5:
fiore@5: /* id is taken from the last touched line is overwritten. To understand why suppose we have an edge *
fiore@5: * made of two lines A and B. When going from one line to another we don't have to utter the name (see *
fiore@5: * comment below. last_touched_line goes from a to NULL before being set to B. If lastTouchedLineId is *
fiore@5: * calculated before checking for NULL-ness it will become -1 and it won't be useful anymore to avoid *
fiore@5: * uttering the edge name when going from A to B. In this way instead proxy goes from A to B, the id is *
fiore@5: * to A's, last_touched_line becomes NULL and then it becomes B, but the name is not uttered because id *
fiore@5: * is the same. This is a very long comment. I want to finish the line to make it look better. bye bye */
fiore@5: int lastTouchedLineId = (last_touched_line == NULL) ? - 1 : line_id_map[last_touched_line];
fiore@5:
fiore@5: bool do_unselect = false;
fiore@5: /* if the proxy goes far enough from the last touched line, then last_touched_line can be set back to NULL */
fiore@5: if(last_touched_line != NULL){
fiore@5: last_touched_line->closestPoint(proxy_pos,closest_point,normal,tex_coord);
fiore@5: if(pointsDistance(closest_point, proxy_pos) > LINE_COLLISION_THRESHOLD){
fiore@5: last_touched_line = NULL;
fiore@5: do_unselect = true;
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: /* find the closest line to the proxy among those closer than LINE_COLLISION_THRESHOLD */
fiore@5: vector::iterator itr;
fiore@5: HAPI::Collision::LineSegment* found_line = NULL;
fiore@5: double min_dist = LINE_COLLISION_THRESHOLD;
fiore@5: double dist;
fiore@5: for( itr=line_set.begin(); itr != line_set.end(); itr++ ){
fiore@5: itr->closestPoint(proxy_pos,closest_point,normal,tex_coord);
fiore@5: if((dist = pointsDistance(closest_point,proxy_pos)) < min_dist){
fiore@5: found_line = &(*itr);
fiore@5: min_dist = dist;
fiore@5: }
fiore@5: }
fiore@5:
fiore@5: if(found_line != NULL){
fiore@5: last_touched_line = found_line;
fiore@5: /* proxy can touch only one object at time either line or point */
fiore@5: last_touched_point = NULL;
fiore@5: /* An edge can be broken into several lines. Such lines will map to the same edge id *
fiore@5: * If the proxy detouches from a line but immediately touches another line mapped to *
fiore@5: * the same id, it just means the proxy is going aling the line and therefore no *
fiore@5: * name must be uttered again (the name must be uttered when touching an edge and *
fiore@5: * not when touching each line. We keep track of the last touched id and if it's the *
fiore@5: * as te new touched line id, then nothing is uttered, for we're on the same edge */
fiore@5: if(lastTouchedLineId != line_id_map[last_touched_line]){
fiore@5: int line_id = line_id_map[last_touched_line];
fiore@5: /* select the node for eventual highlighting int the java tree */
fiore@5: executeCommand(SELECT_CMD,line_id,0,0,0,0);
fiore@5: /* utter the name of the edge */
fiore@5: executeCommand(SPEAK_NAME_CMD,line_id,0,0,0,0);
fiore@5: if(attraction_mode == ACTIVE && line_id == attract_to){
fiore@5: /* we reached the attracting node, stop the attraction force */
fiore@5: attraction_mode = STOP_ATTRACTION;
fiore@5: }
fiore@5: }
fiore@5: return true;
fiore@5: }
fiore@5:
fiore@5: if(do_unselect){
fiore@5: executeCommand(UNSELECT_CMD,0,0,0,0,0);
fiore@5: }
fiore@5:
fiore@5: return false;
fiore@5: }
fiore@5:
fiore@5: bool HapticManager::checkUnselection(void){
fiore@5: if(object_unselected){
fiore@5: object_unselected = false;
fiore@5: executeCommand(UNSELECT_CMD,0,0,0,0,0);
fiore@5: return true;
fiore@5: }
fiore@5: return false;
fiore@5: }
fiore@5:
fiore@5: bool HapticManager::checkButtons(void){
fiore@5: HAPIInt32 status = hd->getButtonStatus();
fiore@5: /* handle the buttons. Buttons can be pressed one at time. If a button is pressed all the *
fiore@5: * other buttons (either when pressed or released) are ignored untill the button is released */
fiore@5: if(pressed_button == NO_BUTTON){
fiore@5: if(status & FRONT_BUTTON){
fiore@5: /* front button pressed, change how magnetic the lines are */
fiore@5: pressed_button = FRONT_BUTTON;
fiore@5: /* switch from sticky to loose and vice versa */
fiore@5: magnetic_mode = (magnetic_mode == STICKY) ? LOOSE : STICKY;
fiore@5: magnetic_mode_changed = true;
fiore@5: /* make a sound according to the new attraction mode */
fiore@5: executeCommand(PLAY_SOUND_CMD, (magnetic_mode == STICKY) ? STICKY_MODE_SOUND : LOOSE_MODE_SOUND ,0,0,0,0);
fiore@5: return true;
fiore@5: }else if(status & REAR_BUTTON){
fiore@5: pressed_button = REAR_BUTTON;
fiore@5: /* rear button pressed: First time it picks up an object, second time it drops it */
fiore@5: if(pickup_mode == RELEASED){ // pickup mode was released, then now user picked up an object
fiore@5: if(last_touched_point != NULL){
fiore@5: pickedup_point = last_touched_point;
fiore@5: last_dragging_pos = pickedup_point->position; // last_dragging_pos used in checkMotion
fiore@5: /* send a pickup command to the Java thread which will in turn issue another pickup *
fiore@5: * command to this thread (pickup = true in drawDiagram) if the lock could be granted */
fiore@5: executeCommand(PICKUP_CMD,point_id_map[last_touched_point],0,0,0,0);
fiore@5: }else if(last_touched_line != NULL){
fiore@5: pickedup_line = last_touched_line;
fiore@5: pickup_line_pos = proxy_pos; // the point where the line was picked up
fiore@5: last_dragging_pos = proxy_pos;// last_dragging_pos used in checkMotion
fiore@5: executeCommand(PICKUP_CMD,line_id_map[last_touched_line],0,0,0,0);
fiore@5: }/* else user picked up thin air. Do nothing. */
fiore@5: }else if(pickup_mode == DRAGGING){ // pickup mode was dragging, then now user dropped an object
fiore@5: pickup_mode = RELEASED;
fiore@5: Vec3 & new_position = hapticToScreenSpace(Vec3(proxy_pos),
fiore@5: cm->getScreenWidth(),
fiore@5: cm->getScreenHeight());
fiore@5: if(pickedup_point){
fiore@5: executeCommand(MOVE_CMD,point_id_map[pickedup_point],new_position.x,new_position.y,0,0);
fiore@5: pickedup_point = NULL;
fiore@5: }else{
fiore@5: hapticToScreenSpace(pickup_line_pos,
fiore@5: cm->getScreenWidth(),
fiore@5: cm->getScreenHeight());
fiore@5: executeCommand(MOVE_CMD,
fiore@5: line_id_map[pickedup_line],
fiore@5: new_position.x,
fiore@5: new_position.y,
fiore@5: pickup_line_pos.x,
fiore@5: pickup_line_pos.y);
fiore@5: pickedup_line = NULL;
fiore@5: }
fiore@5: return true;
fiore@5: }
fiore@5: } else if(status & ( LEFT_BUTTON | RIGHT_BUTTON )){ // either left or right button pressed
fiore@5: pressed_button = (status == LEFT_BUTTON) ? LEFT_BUTTON : RIGHT_BUTTON;
fiore@5: if(last_touched_point != NULL){ // priority to nodes
fiore@5: executeCommand(SPEAK_INFO_CMD,point_id_map[last_touched_point], 0,0,0,0);
fiore@5: return true;
fiore@5: }
fiore@5: if(last_touched_line != NULL){
fiore@5: executeCommand(SPEAK_INFO_CMD,line_id_map[last_touched_line], 0,0,0,0);
fiore@5: return true;
fiore@5: }
fiore@5: }
fiore@5: } else if ( /* deactivate the buttons */
fiore@5: (pressed_button == FRONT_BUTTON && !(status & FRONT_BUTTON)) ||
fiore@5: (pressed_button == REAR_BUTTON && !(status & REAR_BUTTON)) ||
fiore@5: (pressed_button == LEFT_BUTTON && !(status & LEFT_BUTTON)) ||
fiore@5: (pressed_button == RIGHT_BUTTON && !(status & RIGHT_BUTTON)))
fiore@5: {
fiore@5: pressed_button = NO_BUTTON;
fiore@5: }
fiore@5: return false;
fiore@5: }
fiore@5:
fiore@5: bool HapticManager::checkMotion(void){
fiore@5: if(pickup_mode != DRAGGING)
fiore@5: return false;
fiore@5: if(pointsDistance(proxy_pos,last_dragging_pos) > DRAGGING_SOUND_THRESHOLD){
fiore@5: last_dragging_pos = proxy_pos;
fiore@5: executeCommand(PLAY_SOUND_CMD,DRAGGING_SOUND,0,0,0,0);
fiore@5: return true;
fiore@5: }
fiore@5: return false;
fiore@5: }
fiore@5:
fiore@5: void HapticManager::dispose(void){
fiore@5: hd->releaseDevice();
fiore@5: delete hd;
fiore@5: }
fiore@5:
fiore@5:
fiore@5: /* static constants initialization */
fiore@5: const int HapticManager::NO_ID = 0;
fiore@5:
fiore@5: const int HapticManager::GRAPHIC_SCALE = 2;
fiore@5: const int HapticManager::SPRING_FORCE_FACTOR = 200;
fiore@5: const int HapticManager::LINE_FORCE_FACTOR_STICKY = 2000;
fiore@5: const int HapticManager::LINE_FORCE_FACTOR_LOOSE = 100;
fiore@5: const int HapticManager::POINT_FORCE_FACTOR = 20;
fiore@5: const double HapticManager::POINT_COLLISION_THRESHOLD = 0.0025;
fiore@5: const double HapticManager::LINE_COLLISION_THRESHOLD = 0.0025;
fiore@5: const double HapticManager::DRAGGING_SOUND_THRESHOLD = 0.01;
fiore@5:
fiore@5: const int HapticManager::LOOSE_MODE_SOUND = 0;
fiore@5: const int HapticManager::STICKY_MODE_SOUND = 1;
fiore@5: const int HapticManager::DRAGGING_SOUND = 3;
fiore@5:
fiore@5: const char HapticManager::MOVE_CMD = 'm';
fiore@5: const char HapticManager::PLAY_SOUND_CMD = 'g';
fiore@5: const char HapticManager::SPEAK_NAME_CMD = 't';
fiore@5: const char HapticManager::PICKUP_CMD = 'c';
fiore@5: const char HapticManager::SPEAK_INFO_CMD = 'i';
fiore@5: const char HapticManager::SELECT_CMD = 's';
fiore@5: const char HapticManager::UNSELECT_CMD = 'u';
fiore@5:
fiore@5: const HAPIInt32 HapticManager::FRONT_BUTTON = (1 << 2);
fiore@5: const HAPIInt32 HapticManager::LEFT_BUTTON = (1 << 1);
fiore@5: const HAPIInt32 HapticManager::RIGHT_BUTTON = (1 << 3);
fiore@5: const HAPIInt32 HapticManager::REAR_BUTTON = (1 << 0);
fiore@5: const HAPIInt32 HapticManager::NO_BUTTON = 0;