1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

AndroidGCS OSG: Add the OSG view to the main launcher page

This commit is contained in:
James Cotton 2012-08-21 11:02:57 -05:00
parent 616f488c6c
commit b9e20ad0b7
9 changed files with 64 additions and 14 deletions

View File

@ -26,7 +26,7 @@
<!-- Object browser - main activity at the moment -->
<activity
android:name="org.openpilot.osg.osgViewer"
android:name="org.openpilot.androidgcs.HomePage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -42,6 +42,7 @@
<!-- <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" -->
<!-- android:resource="@xml/device_filter" /> -->
</activity>
<activity
android:name="ObjectBrowser"
android:label="@string/object_browser_name" />
@ -68,7 +69,10 @@
android:name="Logger"
android:label="Logger"
android:theme="@android:style/Theme.Dialog" />
<activity
android:name="OsgViewer"
android:label="3DView" />
<receiver android:name="TelemetryWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

View File

@ -1,5 +1,5 @@
#include "OsgMainApp.hpp"
#include <osg/Quat>
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);
}

View File

@ -23,6 +23,7 @@
#include <osg/Depth>
#include <osg/Program>
#include <osg/Shader>
#include <osg/MatrixTransform>
#include <osg/Node>
#include <osg/Notify>
//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;
};

View File

@ -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);
}

View File

@ -77,6 +77,18 @@
android:drawableTop="@drawable/ic_alarms"
android:text="@string/alarms" />
<Button
android:id="@+id/launch_osgViewer"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="right"
android:layout_row="6"
android:layout_rowSpan="2"
android:background="@android:color/transparent"
android:drawableTop="@drawable/ic_alarms"
android:text="@string/_3dview" />
<Space
android:layout_width="1dp"
android:layout_height="32dp"

View File

@ -32,4 +32,5 @@
<string name="alarms">Alarms</string>
<string name="txrate">TxRate: </string>
<string name="rxrate">RxRate: </string>
<string name="_3dview">3DView</string>
</resources>

View File

@ -83,6 +83,15 @@ public class HomePage extends ObjectManagerActivity {
startActivity(new Intent(HomePage.this, SystemAlarmActivity.class));
}
});
Button osgViewer = (Button) findViewById(R.id.launch_osgViewer);
osgViewer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, OsgViewer.class));
}
});
}
}

View File

@ -83,7 +83,7 @@ public abstract class ObjectManagerActivity extends Activity {
private HashMap<Observer, UAVObject> listeners;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

View File

@ -1,8 +1,9 @@
package org.openpilot.osg;
package org.openpilot.androidgcs;
import org.openpilot.androidgcs.R;
import org.openpilot.osg.ColorPickerDialog;
import org.openpilot.osg.EGLview;
import org.openpilot.osg.osgNativeLib;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Color;
import android.graphics.PointF;
@ -20,7 +21,7 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class osgViewer extends Activity implements View.OnTouchListener, View.OnKeyListener, ColorPickerDialog.OnColorChangeListener {
public class OsgViewer extends ObjectManagerActivity implements View.OnTouchListener, View.OnKeyListener, ColorPickerDialog.OnColorChangeListener {
enum moveTypes { NONE , DRAG, MDRAG, ZOOM ,ACTUALIZE}
enum navType { PRINCIPAL , SECONDARY }
enum lightType { ON , OFF }