Mercurial > hg > ccmieditor
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:2c67ac862920 | 5:d66dd5880081 |
---|---|
1 /* | |
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool | |
3 | |
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) | |
5 | |
6 This program is free software: you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation, either version 3 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 */ | |
19 | |
20 #include "utils.h" | |
21 | |
22 #define MAX(a,b) ((a) < (b) ? (b) : (a)) | |
23 #define MIN(a,b) ((a) > (b) ? (b) : (a)) | |
24 | |
25 void checkExceptions(JNIEnv *env, char* what){ | |
26 if(env->ExceptionOccurred()){ | |
27 std::cout << "Exception occurred!!!" << std::endl; | |
28 std::cout << what << std::endl; | |
29 env->ExceptionDescribe(); | |
30 exit(-1); | |
31 } | |
32 } | |
33 | |
34 void stopExecution(char* msg){ | |
35 std::cerr << msg << std::endl; | |
36 exit(-1); | |
37 } | |
38 | |
39 H3DUtil::ArithmeticTypes::Vec3d & screenToHapticSpace(H3DUtil::ArithmeticTypes::Vec3d & aPoint, int w, int h){ | |
40 int scale = MAX(w,h); | |
41 double x = (aPoint.x * .1 / scale) - .05; | |
42 /* in Java Swing (0,0) is the top-left corner, whereas in openGL and HAPI * | |
43 * (0,0) is the bottom-left corner. Therefore the y must be converted */ | |
44 aPoint.y = h - aPoint.y; | |
45 double y = (aPoint.y * .1 / scale) - .05; | |
46 | |
47 aPoint.x = x; | |
48 aPoint.y = y; | |
49 return aPoint; | |
50 } | |
51 | |
52 H3DUtil::ArithmeticTypes::Vec3d & hapticToScreenSpace(H3DUtil::ArithmeticTypes::Vec3d & aPoint, int w, int h){ | |
53 int scale = MAX(w,h); | |
54 double x = (aPoint.x + .05) * scale * 10; | |
55 double y = (aPoint.y + .05) * scale * 10; | |
56 | |
57 aPoint.x = x; | |
58 /* in Java Swing (0,0) is the top-left corner, whereas in openGL and HAPI * | |
59 * (0,0) is the bottom-left corner. Therefore the y must be converted */ | |
60 aPoint.y = h - y; | |
61 return aPoint; | |
62 } | |
63 | |
64 | |
65 double pointsDistance(const H3DUtil::ArithmeticTypes::Vec3d & p, const H3DUtil::ArithmeticTypes::Vec3d & q){ | |
66 /* 2D vectors are assumed */ | |
67 return sqrt( (p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y) ) ; | |
68 } | |
69 | |
70 H3DUtil::ArithmeticTypes::Vec3d midPoint(const H3DUtil::ArithmeticTypes::Vec3d & start, const H3DUtil::ArithmeticTypes::Vec3d & end){ | |
71 /* 2D vectors are assumed */ | |
72 double dx = abs((start.x - end.x)/2); | |
73 double dy = abs((start.y - end.y)/2); | |
74 return H3DUtil::ArithmeticTypes::Vec3d( MIN(start.x,end.x)+dx , MIN(start.y,end.y)+dy , 0); | |
75 } |