easyar是国内开发的一款ar技术sdk,最近开发时遇到问题--- easyar 识别成功后,怎么回调java层代码(其实回调方法sdk应该给出,现在没有只能自己写了)?
很简单,改几个地方就行了
在Renderer.java
public void onDrawFrame (GL10 gl) {MainActivity. nativeRender ( this ) ;
}
//此方法用来c层回调,输出c代码层的信息
public void output (String out) {
Log. i ( "zdbb" , "zdbb.. c代码回调: " + out) ;
}
MainAtivity.java
public static native void nativeRender (Object obj) ;
helloar.cc (红色字体为关键)
extern "C" {
JNIEXPORT jboolean JNICALL JNIFUNCTION_NATIVE (nativeInit(JNIEnv* env , jobject object)) ;
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE (nativeDestory(JNIEnv* env , jobject object)) ;
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE (nativeInitGL(JNIEnv* env , jobject object)) ;
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE (nativeResizeGL(JNIEnv* env , jobject object , jint w , jint h)) ;
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE (nativeRender(JNIEnv* env , jobject obj , jobject log ));
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE(nativeRotationChange(JNIEnv* env, jobject obj, jboolean portrait));
};
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE (nativeRender(JNIEnv* env , jobject obj , jobject log) )
{
ar.render( env, log ) ;
}
void HelloARVideo ::render( JNIEnv* env, jobject obj )
{
glClearColor( 0.f , 0.f , 0.f , 1.f ) ;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
Frame frame = augmenter_ .newFrame() ;
if ( view_size [ 0 ] > 0 ){
AR ::resizeGL( view_size [ 0 , view_size [ 1 ) ;
if ( camera_ && camera_ .isOpened())
view_size [ 0 ] = - 1 ;
}
augmenter_ .setViewPort( viewport_ ) ;
augmenter_ .drawVideoBackground() ;
glViewport( viewport_ [ 0 , viewport_ [ 1 , viewport_ [ 2 , viewport_ [ 3 ) ;
AugmentedTarget :: Status status = frame.targets() [ 0 .status() ;
if (status == AugmentedTarget :: kTargetStatusTracked ){
int id = frame.targets() [ 0 .target().id() ;
std :: string idStr = frame.targets() [ 0 .target().uid() ;
if ( active_target && active_target != id) {
video ->onLost() ;
delete video ;
video = NULL ;
tracked_target = 0 ;
active_target = 0 ;
}
if (! tracked_target ) {
/*
* 回调java代码
*/ jclass cls = env->GetObjectClass(obj);
jmethodID jmid = env->GetMethodID(cls, "output", "(Ljava/lang/String;)V");
jstring info = env->NewStringUTF("你的选择没有错,我欠你的太多 ! ! ! ");
env->CallVoidMethod(obj, jmid,info);
jboolean *jboolean1 = new jboolean(false);
env->ReleaseStringUTFChars(info,env->GetStringUTFChars( info,jboolean1));
if ( video == NULL ) {
if (frame.targets() [ 0 .target().name() == std :: string ( "argame" ) && texid [ 0 ]) {
video = new ARVideo ;
video ->openVideoFile( "video.mp4" , texid [ 0 ]) ;
video_renderer = renderer [ 0 ;
}
else if (frame.targets() [ 0 .target().name() == std :: string ( "namecard" ) && texid [ 1 ]) {
video = new ARVideo ;
video ->openTransparentVideoFile( "transparentvideo.mp4" , texid [ 1 ]) ;
video_renderer = renderer [ 1 ;
}
else if (frame.targets() [ 0 .target().name() == std :: string ( "idback" ) && texid [ 2 ]) {
video = new ARVideo ;
video ->openStreamingVideo( "http://m21.oss-cn-qingdao.aliyuncs.com/1494836612692.mp4" , texid [ 2 ]) ;
video_renderer = renderer [ 2 ;
}
}
if ( video ) {
video ->onFound() ;
tracked_target = id ;
active_target = id ;
}
}
Matrix44F projectionMatrix = getProjectionGL( camera_ .cameraCalibration() , 0.2f , 500.f ) ;
Matrix44F cameraview = getPoseGL(frame.targets() [ 0 .pose()) ;
ImageTarget target = frame.targets() [ 0 .target().cast_dynamic< ImageTarget >() ;
if ( tracked_target ) {
video ->update() ;
video_renderer ->render(projectionMatrix , cameraview , target.size()) ;
}
} else {
if ( tracked_target ) {
video ->onLost() ;
tracked_target = 0 ;
}
}
}