diff --git a/androidgcs/AndroidManifest.xml b/androidgcs/AndroidManifest.xml index f697bc43a..f11682869 100644 --- a/androidgcs/AndroidManifest.xml +++ b/androidgcs/AndroidManifest.xml @@ -26,7 +26,7 @@ @@ -42,6 +42,7 @@ + @@ -68,7 +69,10 @@ android:name="Logger" android:label="Logger" android:theme="@android:style/Theme.Dialog" /> - + + diff --git a/androidgcs/jni/OsgMainApp.cpp b/androidgcs/jni/OsgMainApp.cpp index 681af1d7e..e1fb363b8 100644 --- a/androidgcs/jni/OsgMainApp.cpp +++ b/androidgcs/jni/OsgMainApp.cpp @@ -1,5 +1,5 @@ #include "OsgMainApp.hpp" - +#include OsgMainApp::OsgMainApp(){ @@ -41,7 +41,17 @@ void OsgMainApp::loadModels(){ loadedModel->getOrCreateStateSet()->setAttribute ( prog ); - _root->addChild(loadedModel); + // Woohoo leaky code. This no longer works for multiple models + uavAttitudeAndScale = new osg::MatrixTransform(); + uavAttitudeAndScale->setMatrix(osg::Matrixd::scale(0.2e0,0.2e0,0.2e0)); + + osg::MatrixTransform *rotateModelNED = new osg::MatrixTransform(); + rotateModelNED->setMatrix(osg::Matrixd::scale(0.05e0,0.05e0,0.05e0) * osg::Matrixd::rotate(M_PI, osg::Vec3d(0,0,1))); + rotateModelNED->addChild( loadedModel ); + + uavAttitudeAndScale->addChild( rotateModelNED ); + + _root->addChild(uavAttitudeAndScale); } } @@ -216,5 +226,15 @@ osg::Vec4f OsgMainApp::getClearColor(){ return _viewer->getCamera()->getClearColor(); } -void OsgMainApp::setRPY(float x, float y, float z){ +void OsgMainApp::setQuat(float *q){ + osg::Quat quat(q[1], q[2], q[3], q[0]); + + // Have to rotate the axes from OP NED frame to OSG frame (X east, Y north, Z down) + double angle; + osg::Vec3d axis; + quat.getRotate(angle,axis); + quat.makeRotate(angle, osg::Vec3d(axis[1],axis[0],-axis[2])); + osg::Matrixd rot = osg::Matrixd::rotate(quat); + + uavAttitudeAndScale->setMatrix(rot); } diff --git a/androidgcs/jni/OsgMainApp.hpp b/androidgcs/jni/OsgMainApp.hpp index fbb6ee58c..a1a974659 100644 --- a/androidgcs/jni/OsgMainApp.hpp +++ b/androidgcs/jni/OsgMainApp.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include //osgText @@ -178,7 +179,8 @@ public: osg::Vec4f getClearColor(); //Manipulating the view - void setRPY(float x, float y, float z); + void setQuat(float *q); + osg::MatrixTransform *uavAttitudeAndScale; }; diff --git a/androidgcs/jni/osgNativeLib.cpp b/androidgcs/jni/osgNativeLib.cpp index 734e80bd5..2cc115491 100644 --- a/androidgcs/jni/osgNativeLib.cpp +++ b/androidgcs/jni/osgNativeLib.cpp @@ -22,7 +22,7 @@ extern "C" { 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); - JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setRPY(JNIEnv * env, jobject obj, jfloat roll, jfloat pitch, jfloat yaw); + JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setRPY(JNIEnv * env, jobject obj, jfloat q1, jfloat q2, jfloat q3, jfloat q4); }; JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_init(JNIEnv * env, jobject obj, jint width, jint height){ @@ -113,6 +113,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_openpilot_osg_osgNativeLib_getObjectName return fileNames; } -JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setRPY(JNIEnv * env, jobject obj, jfloat roll, jfloat pitch, jfloat yaw){ - mainApp.setRPY(roll,pitch,yaw); +JNIEXPORT void JNICALL Java_org_openpilot_osg_osgNativeLib_setRPY(JNIEnv * env, jobject obj, jfloat q1, jfloat q2, jfloat q3, jfloat q4){ + float q[4] = {q1, q2, q3, q4}; + mainApp.setQuat(q); } diff --git a/androidgcs/res/layout/gcs_home.xml b/androidgcs/res/layout/gcs_home.xml index 82f638b98..1c0e24c35 100644 --- a/androidgcs/res/layout/gcs_home.xml +++ b/androidgcs/res/layout/gcs_home.xml @@ -77,6 +77,18 @@ android:drawableTop="@drawable/ic_alarms" android:text="@string/alarms" /> +