Mercurial > hg > ccmieditor
view native/Falcon/utils.cpp @ 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 source
/* 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/>. */ #include "utils.h" #define MAX(a,b) ((a) < (b) ? (b) : (a)) #define MIN(a,b) ((a) > (b) ? (b) : (a)) void checkExceptions(JNIEnv *env, char* what){ if(env->ExceptionOccurred()){ std::cout << "Exception occurred!!!" << std::endl; std::cout << what << std::endl; env->ExceptionDescribe(); exit(-1); } } void stopExecution(char* msg){ std::cerr << msg << std::endl; exit(-1); } H3DUtil::ArithmeticTypes::Vec3d & screenToHapticSpace(H3DUtil::ArithmeticTypes::Vec3d & aPoint, int w, int h){ int scale = MAX(w,h); double x = (aPoint.x * .1 / scale) - .05; /* in Java Swing (0,0) is the top-left corner, whereas in openGL and HAPI * * (0,0) is the bottom-left corner. Therefore the y must be converted */ aPoint.y = h - aPoint.y; double y = (aPoint.y * .1 / scale) - .05; aPoint.x = x; aPoint.y = y; return aPoint; } H3DUtil::ArithmeticTypes::Vec3d & hapticToScreenSpace(H3DUtil::ArithmeticTypes::Vec3d & aPoint, int w, int h){ int scale = MAX(w,h); double x = (aPoint.x + .05) * scale * 10; double y = (aPoint.y + .05) * scale * 10; aPoint.x = x; /* in Java Swing (0,0) is the top-left corner, whereas in openGL and HAPI * * (0,0) is the bottom-left corner. Therefore the y must be converted */ aPoint.y = h - y; return aPoint; } double pointsDistance(const H3DUtil::ArithmeticTypes::Vec3d & p, const H3DUtil::ArithmeticTypes::Vec3d & q){ /* 2D vectors are assumed */ return sqrt( (p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y) ) ; } H3DUtil::ArithmeticTypes::Vec3d midPoint(const H3DUtil::ArithmeticTypes::Vec3d & start, const H3DUtil::ArithmeticTypes::Vec3d & end){ /* 2D vectors are assumed */ double dx = abs((start.x - end.x)/2); double dy = abs((start.y - end.y)/2); return H3DUtil::ArithmeticTypes::Vec3d( MIN(start.x,end.x)+dx , MIN(start.y,end.y)+dy , 0); }