Mercurial > hg > ccmieditor
comparison native/PhantomOmni/utils.cpp @ 3:9e67171477bc
PHANTOM Omni Heptic device release
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Wed, 25 Apr 2012 17:09:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:4b2f975e35fa | 3:9e67171477bc |
---|---|
1 #include "utils.h" | |
2 | |
3 void checkExceptions(JNIEnv *env, char* what){ | |
4 if(env->ExceptionOccurred()){ | |
5 std::cout << "Exception occurred!!!" << std::endl; | |
6 std::cout << what << std::endl; | |
7 env->ExceptionDescribe(); | |
8 exit(-1); | |
9 } | |
10 } | |
11 | |
12 void stopExecution(char* msg){ | |
13 std::cerr << msg << std::endl; | |
14 exit(-1); | |
15 } | |
16 | |
17 | |
18 bool fromScreen(const hduVector3Dd &win, hduVector3Dd &obj) { | |
19 | |
20 hduMatrix m_worldTview; | |
21 hduMatrix m_viewTclip; | |
22 int m_viewport[4]; | |
23 glGetDoublev(GL_MODELVIEW_MATRIX, m_worldTview); | |
24 glGetDoublev(GL_PROJECTION_MATRIX, m_viewTclip); | |
25 glGetIntegerv(GL_VIEWPORT, m_viewport); | |
26 int nResult = gluUnProject( | |
27 win[0], win[1], win[2], | |
28 m_worldTview, | |
29 m_viewTclip, | |
30 m_viewport, | |
31 &obj[0], &obj[1], &obj[2]); | |
32 | |
33 return nResult == GL_TRUE; | |
34 } | |
35 | |
36 bool toScreen(const hduVector3Dd &obj, hduVector3Dd &win) { | |
37 | |
38 hduMatrix m_worldTview; | |
39 hduMatrix m_viewTclip; | |
40 int m_viewport[4]; | |
41 glGetDoublev(GL_MODELVIEW_MATRIX, m_worldTview); | |
42 glGetDoublev(GL_PROJECTION_MATRIX, m_viewTclip); | |
43 glGetIntegerv(GL_VIEWPORT, m_viewport); | |
44 int nResult = gluProject( | |
45 obj[0], obj[1], obj[2], | |
46 m_worldTview, | |
47 m_viewTclip, | |
48 m_viewport, | |
49 &win[0], &win[1], &win[2]); | |
50 | |
51 return nResult == GL_TRUE; | |
52 } | |
53 | |
54 | |
55 HDdouble norm(HDdouble v[3]){ | |
56 return sqrt( (v[0]*v[0])+(v[1]*v[1])+(v[2]*v[2])); | |
57 } | |
58 | |
59 void print(char* str){ | |
60 std::cout << str << std::endl; | |
61 } | |
62 | |
63 void print(int str){ | |
64 std::cout << str << std::endl; | |
65 } | |
66 | |
67 float rotate(){ | |
68 static float rot = 0.0f; | |
69 rot += 0.5f; | |
70 if(rot > 360) | |
71 rot = 0; | |
72 return rot; | |
73 } |