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