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