annotate native/PhantomOmni/utils.cpp @ 8:ea7885bd9bff tip

fixed bug : render solid line as dotted/dashed when moving the stylus from dotted/dashed to solid
author ccmi-guest
date Thu, 03 Jul 2014 16:12:20 +0100
parents 9e67171477bc
children
rev   line source
fiore@3 1 #include "utils.h"
fiore@3 2
fiore@3 3 void checkExceptions(JNIEnv *env, char* what){
fiore@3 4 if(env->ExceptionOccurred()){
fiore@3 5 std::cout << "Exception occurred!!!" << std::endl;
fiore@3 6 std::cout << what << std::endl;
fiore@3 7 env->ExceptionDescribe();
fiore@3 8 exit(-1);
fiore@3 9 }
fiore@3 10 }
fiore@3 11
fiore@3 12 void stopExecution(char* msg){
fiore@3 13 std::cerr << msg << std::endl;
fiore@3 14 exit(-1);
fiore@3 15 }
fiore@3 16
fiore@3 17
fiore@3 18 bool fromScreen(const hduVector3Dd &win, hduVector3Dd &obj) {
fiore@3 19
fiore@3 20 hduMatrix m_worldTview;
fiore@3 21 hduMatrix m_viewTclip;
fiore@3 22 int m_viewport[4];
fiore@3 23 glGetDoublev(GL_MODELVIEW_MATRIX, m_worldTview);
fiore@3 24 glGetDoublev(GL_PROJECTION_MATRIX, m_viewTclip);
fiore@3 25 glGetIntegerv(GL_VIEWPORT, m_viewport);
fiore@3 26 int nResult = gluUnProject(
fiore@3 27 win[0], win[1], win[2],
fiore@3 28 m_worldTview,
fiore@3 29 m_viewTclip,
fiore@3 30 m_viewport,
fiore@3 31 &obj[0], &obj[1], &obj[2]);
fiore@3 32
fiore@3 33 return nResult == GL_TRUE;
fiore@3 34 }
fiore@3 35
fiore@3 36 bool toScreen(const hduVector3Dd &obj, hduVector3Dd &win) {
fiore@3 37
fiore@3 38 hduMatrix m_worldTview;
fiore@3 39 hduMatrix m_viewTclip;
fiore@3 40 int m_viewport[4];
fiore@3 41 glGetDoublev(GL_MODELVIEW_MATRIX, m_worldTview);
fiore@3 42 glGetDoublev(GL_PROJECTION_MATRIX, m_viewTclip);
fiore@3 43 glGetIntegerv(GL_VIEWPORT, m_viewport);
fiore@3 44 int nResult = gluProject(
fiore@3 45 obj[0], obj[1], obj[2],
fiore@3 46 m_worldTview,
fiore@3 47 m_viewTclip,
fiore@3 48 m_viewport,
fiore@3 49 &win[0], &win[1], &win[2]);
fiore@3 50
fiore@3 51 return nResult == GL_TRUE;
fiore@3 52 }
fiore@3 53
fiore@3 54
fiore@3 55 HDdouble norm(HDdouble v[3]){
fiore@3 56 return sqrt( (v[0]*v[0])+(v[1]*v[1])+(v[2]*v[2]));
fiore@3 57 }
fiore@3 58
fiore@3 59 void print(char* str){
fiore@3 60 std::cout << str << std::endl;
fiore@3 61 }
fiore@3 62
fiore@3 63 void print(int str){
fiore@3 64 std::cout << str << std::endl;
fiore@3 65 }
fiore@3 66
fiore@3 67 float rotate(){
fiore@3 68 static float rot = 0.0f;
fiore@3 69 rot += 0.5f;
fiore@3 70 if(rot > 360)
fiore@3 71 rot = 0;
fiore@3 72 return rot;
fiore@3 73 }