#include "ofMain.h"
#include "testApp.h"
#include <jni.h>
#include "ofAppAndroidWindow.h"

//========================================================================
extern "C"{
testApp *kinectApp;
void Java_cc_openframeworks_OFAndroid_init( JNIEnv*  env, jobject  thiz ){

    ofAppAndroidWindow *window = new ofAppAndroidWindow;
	ofSetupOpenGL(window, 800,600, OF_WINDOW);
	kinectApp = new testApp();
	ofRunApp(kinectApp);
}
JNIEXPORT
jbyteArray
JNICALL Java_cc_openframeworks_OFAndroid_getImgPixels( JNIEnv*  env, jobject  thiz){
	jbyteArray res_array = env->NewByteArray(640*480*3);
    if (res_array == 0 || kinectApp->colorImg->getPixels() == 0) {
        return 0;
    }
	env->SetByteArrayRegion(res_array, 0, 640*480*3, (jbyte*)kinectApp->colorImg->getPixels());
	return res_array;
}

JNIEXPORT
jint
JNICALL Java_cc_openframeworks_OFAndroid_getDistance(JNIEnv*  env, jobject  thiz, jint objx, jint objy){
	return (int)kinectApp->kinect.getDistanceAt(objx, objy);
}

void Java_cc_openframeworks_OFAndroid_setAngle(JNIEnv*  env, jobject  thiz, jint angle) {
	if (angle > 30)		angle = 30;
	else if (angle < 0)	angle = 0;
	kinectApp->kinect.setCameraTiltAngle(angle);
}

}

int main(){
	return 0;
}
