Newbie - Haptic Device C++ to Java connection

Hi again everyone,



I am trying to implement a very simple game on a haptic robotic device. The robot is moved in 3D workspace to play the game. The robot however has an SDK based on C++ and the GUI on OpenGL. It has a C++ function which returns the x, y and z coordinates of the ‘3d cursor’. I want to somehow connect my game in Jmonkey to the device. Is there a way I can send those 3d coordinates over to the java game to move the cursor here in the game and information back from the game to the C++ program to output the haptic effects?



Desperate for help. Thanks.

The API to interface Java and C/C++ is called “JNI”.

Hi,



What Haptic Device are you trying to connect?



You could use JTouchToolkit, I have used Novint Falcons and a SenseGraphics Phantom via this package.



The toolkit comes with java wrappers for HDAL and such, and will save you the time of wrapping all the .dlls.



You can get it here:

http://java.net/projects/jtouchtoolkit



I have a few examples of haptic loops + device initialization if you are interested, the documentation can be a bit lagging.

Hey thanks alot!!



I’m using the HapticMaster! Could you please send me the examples? It would be of so much help!! I’ve sent you a message with my email address in it!!



Thanks!

Hey, I send two samples to you via message. Both examples does a haptic render of a sphere, using a Novint Falcon and a Phantom. Hope it helps.

@normen said:
The API to interface Java and C/C++ is called "JNI".

normen, I tried looking into JNI. This might be a stupid question, since I'm totally new to this, but I can't seem to figure out how to use it with JME. The javac tool won't compile any of the files since it doesn't understand the 'jme3 libraries' and gives me an error on every library import I have in my code. The jme doesn't compile because it sees a call to a native function which isn't defined. So I'm kind of stuck her. Please help me a little if you've time. Thanks.
@neogeek said:
normen, I tried looking into JNI. This might be a stupid question, since I'm totally new to this, but I can't seem to figure out how to use it with JME. The javac tool won't compile any of the files since it doesn't understand the 'jme3 libraries' and gives me an error on every library import I have in my code. The jme doesn't compile because it sees a call to a native function which isn't defined. So I'm kind of stuck her. Please help me a little if you've time. Thanks.


This is not a JME problem. You probably should figure out how to do JNI development. It's hard if you are unfamiliar with the concepts and you will need a C compiler. There are probably way better sites to get tutorials and help on that type of development... then when you understand how to do JNI getting it into a JME app will be easy.

Ok. So I got my way around the JNI issue. But when I try to run the java file, although it calls the C functions alright, I get the initial display settings screen for JME but as soon as I click OK, the app crashes and I get the following errors, any idea how to solve these? :S





com.jme3.system.JmeSystem initialize

INFO: Running on jMonkeyEngine 3.0.0 Beta

May 15, 2012 12:00:39 PM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory: C:Usersns11adz.jme3natives_2d9494ee

Exception in thread “main” java.lang.NoClassDefFoundError: org/lwjgl/opengl/Open

GLException

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at com.jme3.system.JmeSystem.newContextLwjgl(JmeSystem.java:202)

at com.jme3.system.JmeSystem.newContext(JmeSystem.java:278)

at com.jme3.app.Application.start(Application.java:363)

at com.jme3.app.Application.start(Application.java:344)

at com.jme3.app.SimpleApplication.start(SimpleApplication.java:134)

at HelloInput.main(HelloInput.java:36)

Caused by: java.lang.ClassNotFoundException: org.lwjgl.opengl.OpenGLException

at java.net.URLClassLoader$1.run(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

… 8 more

Also, when I try to run it through the JME SDK, it runs fine. But I need the C function calls.

The dll has to be in the execution directory which is the project root when running from the SDK.

Thanks a bunch!