1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00
LibrePilot/androidgcs/jni/osgNativeLib.cpp

120 lines
5.5 KiB
C++
Raw Normal View History

2012-08-21 05:56:21 +02:00
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include <iostream>
#include "OsgMainApp.hpp"
OsgMainApp mainApp;
extern "C" {
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_init(JNIEnv * env, jobject obj, jint width, jint height);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_step(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_clearContents(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_mouseButtonPressEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_mouseButtonReleaseEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_mouseMoveEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_keyboardDown(JNIEnv * env, jobject obj, jint key);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_keyboardUp(JNIEnv * env, jobject obj, jint key);
JNIEXPORT jintArray JNICALL Java_org_openpilot_osg_osgNativeLib_getClearColor(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setClearColor(JNIEnv * env, jobject obj, jint red, jint green, jint blue);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_loadObject(JNIEnv * env, jobject obj, jstring address);
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_unLoadObject(JNIEnv * env, jobject obj, jint number);
JNIEXPORT jobjectArray JNICALL Java_org_openpilot_osg_osgNativeLib_getObjectNames(JNIEnv * env, jobject obj);
2012-08-21 18:25:14 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setQuat(JNIEnv * env, jobject obj, jfloat q1, jfloat q2, jfloat q3, jfloat q4);
2012-08-21 05:56:21 +02:00
};
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_init(JNIEnv * env, jobject obj, jint width, jint height){
2012-08-21 05:56:21 +02:00
mainApp.initOsgWindow(0,0,width,height);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_step(JNIEnv * env, jobject obj){
2012-08-21 05:56:21 +02:00
mainApp.draw();
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_clearContents(JNIEnv * env, jobject obj){
2012-08-21 05:56:21 +02:00
mainApp.clearScene();
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_mouseButtonPressEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button){
2012-08-21 05:56:21 +02:00
mainApp.mouseButtonPressEvent(x,y,button);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_mouseButtonReleaseEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button){
2012-08-21 05:56:21 +02:00
mainApp.mouseButtonReleaseEvent(x,y,button);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_mouseMoveEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y){
2012-08-21 05:56:21 +02:00
mainApp.mouseMoveEvent(x,y);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_keyboardDown(JNIEnv * env, jobject obj, jint key){
2012-08-21 05:56:21 +02:00
mainApp.keyboardDown(key);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_keyboardUp(JNIEnv * env, jobject obj, jint key){
2012-08-21 05:56:21 +02:00
mainApp.keyboardUp(key);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT jintArray JNICALL Java_org_openpilot_osg_osgNativeLib_getClearColor(JNIEnv * env, jobject obj){
2012-08-21 05:56:21 +02:00
jintArray color;
color = env->NewIntArray(3);
if (color == NULL) {
return NULL;
}
osg::Vec4 vTemp1 = mainApp.getClearColor();
jint vTemp2[3];
vTemp2[0] = (int) (vTemp1.r() * 255);
vTemp2[1] = (int) (vTemp1.g() * 255);
vTemp2[2] = (int) (vTemp1.b() * 255);
std::cout<<vTemp2[0]<<" "<<vTemp2[1]<<" "<<vTemp2[2]<<" "<<std::endl;
env->SetIntArrayRegion(color, 0, 3, vTemp2);
return color;
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setClearColor(JNIEnv * env, jobject obj, jint red, jint green, jint blue){
2012-08-21 05:56:21 +02:00
osg::Vec4 tVec((float) red / 255.0f, (float) green / 255.0f, (float) blue / 255.0f, 0.0f);
mainApp.setClearColor(tVec);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_loadObject(JNIEnv * env, jobject obj, jstring address){
2012-08-21 05:56:21 +02:00
//Import Strings from JNI
2012-08-21 07:04:26 +02:00
const char *nativeAddress = env->GetStringUTFChars(address, JNI_FALSE);
2012-08-21 05:56:21 +02:00
mainApp.loadObject(std::string(nativeAddress));
//Release Strings to JNI
env->ReleaseStringUTFChars(address, nativeAddress);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_loadObject(JNIEnv * env, jobject obj, jstring address, jstring name){
2012-08-21 05:56:21 +02:00
//Import Strings from JNI
2012-08-21 07:04:26 +02:00
const char *nativeAddress = env->GetStringUTFChars(address, JNI_FALSE);
const char *nativeName = env->GetStringUTFChars(name, JNI_FALSE);
2012-08-21 05:56:21 +02:00
mainApp.loadObject(std::string(nativeName),std::string(nativeAddress));
//Release Strings to JNI
env->ReleaseStringUTFChars(address, nativeAddress);
env->ReleaseStringUTFChars(address, nativeName);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_unLoadObject(JNIEnv * env, jobject obj, jint number){
2012-08-21 05:56:21 +02:00
mainApp.unLoadObject(number);
}
2012-08-21 07:04:26 +02:00
JNIEXPORT jobjectArray JNICALL Java_org_openpilot_osg_osgNativeLib_getObjectNames(JNIEnv * env, jobject obj){
2012-08-21 05:56:21 +02:00
jobjectArray fileNames;
unsigned int numModels = mainApp.getNumberObjects();
fileNames = (jobjectArray)env->NewObjectArray(numModels,env->FindClass("java/lang/String"),env->NewStringUTF(""));
for(unsigned int i=0;i < numModels;i++){
std::string name = mainApp.getObjectName(i);
env->SetObjectArrayElement(fileNames,i,env->NewStringUTF(name.c_str()));
}
return fileNames;
}
2012-08-21 18:25:14 +02:00
JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setQuat(JNIEnv * env, jobject obj, jfloat q1, jfloat q2, jfloat q3, jfloat q4){
float q[4] = {q1, q2, q3, q4};
mainApp.setQuat(q);
}