Game Development Reference
In-Depth Information
Calls the Orient Java object's AddRotation() function with parameter
RotationAngle by calling the CallVoidMethod() JNI function
3.
Listing 11-5. Accessing a Java Method from a Native Code
Java_robs_gldemo_robsgl20tutorial_Physics_AddRotationNative(JNIEnv* env,
jobject thiz,
jobject Orient,
jfloat RotationAngle)
{
/*
GetObjectClass
jclass GetObjectClass(JNIEnv *env, jobject obj);
*/
jclass OrientationClass = (*env)->GetObjectClass(env, Orient);
/*
GetMethodID
jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
*/
jmethodID MethodID = (*env)->GetMethodID(env,
OrientationClass,
"AddRotation",
"(F)V");
/*
NativeType Call<type>Method(JNIEnv *env, jobject obj, jmethodID methodID, ...);
*/
(*env)->CallVoidMethod(env, Orient, MethodID, RotationAngle);
}
JNI Functions
There are many more JNI functions besides those discussed in Listing 11-5. For example, if
the Java function we want to call returns a double numeric value, we would have to call the
CallDoubleMethod() function instead of the CallVoidMethod for a function that returns void.
We won't try and discuss every JNI function here, because this is not intended to be a JNI reference
manual. If you want more information on the complete list of JNI functions supported, please go to
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp9502 .
Note The main web site for JNI specifications is http://docs.oracle.com/javase/6/docs/
technotes/guides/jni/spec/jniTOC.html .
 
 
Search WWH ::




Custom Search