diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/native/PhantomOmni/utils.cpp	Wed Apr 25 17:09:09 2012 +0100
@@ -0,0 +1,73 @@
+#include "utils.h"
+
+void checkExceptions(JNIEnv *env, char* what){
+	if(env->ExceptionOccurred()){
+		std::cout << "Exception occurred!!!" << std::endl;
+		std::cout << what << std::endl;
+		env->ExceptionDescribe();
+		exit(-1);
+	}
+}
+
+void stopExecution(char* msg){
+	std::cerr << msg << std::endl;
+	exit(-1);
+}
+
+
+bool fromScreen(const hduVector3Dd &win, hduVector3Dd &obj) {
+
+	hduMatrix m_worldTview;
+    hduMatrix m_viewTclip;
+    int m_viewport[4];
+	glGetDoublev(GL_MODELVIEW_MATRIX, m_worldTview);
+    glGetDoublev(GL_PROJECTION_MATRIX, m_viewTclip);
+    glGetIntegerv(GL_VIEWPORT, m_viewport); 
+    int nResult =	gluUnProject(
+        win[0], win[1], win[2],
+		m_worldTview,
+        m_viewTclip,
+        m_viewport,
+        &obj[0], &obj[1], &obj[2]);
+    
+    return nResult == GL_TRUE;
+}
+
+bool toScreen(const hduVector3Dd &obj, hduVector3Dd &win)  {
+	
+	hduMatrix m_worldTview;
+    hduMatrix m_viewTclip;
+    int m_viewport[4];
+	glGetDoublev(GL_MODELVIEW_MATRIX, m_worldTview);
+    glGetDoublev(GL_PROJECTION_MATRIX, m_viewTclip);
+    glGetIntegerv(GL_VIEWPORT, m_viewport); 
+    int nResult = gluProject(
+        obj[0], obj[1], obj[2],
+		m_worldTview,
+        m_viewTclip,
+        m_viewport,
+        &win[0], &win[1], &win[2]);
+
+    return nResult == GL_TRUE;
+}
+
+
+HDdouble norm(HDdouble v[3]){
+	return sqrt( (v[0]*v[0])+(v[1]*v[1])+(v[2]*v[2]));
+}
+
+void print(char* str){
+	std::cout << str << std::endl;
+}
+
+void print(int str){
+	std::cout << str << std::endl;
+}
+
+float rotate(){
+	static float rot = 0.0f;
+	rot += 0.5f;
+	if(rot > 360)
+		rot = 0;
+	return rot;
+}
\ No newline at end of file