Jfloat to Float
Here's my function definition in Java:
public static native void ToucheBegan( float x, float y, int tapcount );
And here's my definition in CPP
JNIEXPORT void JNICALL Java_com_android_templateApp_GL2View_ToucheBegan( JNIEnv *env, jfloat x, jfloat y, jint 开发者_开发技巧tap_count );
When I log:
From Java I send:
125.278595 496.842102 1
And In C++ I receive:
3.274879 125.278595 1140353994
Is there some sort of conversion that have to be done between a jfloat to float or jint to int?
TIA!
You forgot implicit jobject/jclass argument that every JNI function has:
void JNICALL Java_com_android_templateApp_GL2View_ToucheBegan( JNIEnv *env, jobject thiz, jfloat x, jfloat y, jint tap_count );
So you were interpreting 'thiz' as 'x', 'x' as 'y' and 'y' as 'tap_count'.
There isn't any special conversion required.
Check that your C++ logging is acting as anticipated. One way to do this is to assign known values to x,y, and tapcount within the C++ function and make sure they are being logged as expected.
精彩评论