diff --git a/HelicopterControl/libs/android-support-v4.jar b/HelicopterControl/libs/android-support-v4.jar index 96644edb..2a9bf3c9 100755 Binary files a/HelicopterControl/libs/android-support-v4.jar and b/HelicopterControl/libs/android-support-v4.jar differ diff --git a/HelicopterControl/project.properties b/HelicopterControl/project.properties index a3ee5ab6..916037e3 100755 --- a/HelicopterControl/project.properties +++ b/HelicopterControl/project.properties @@ -11,4 +11,4 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-17 +target=android-23 diff --git a/HelicopterControl/src/com/example/fftrajectorymapper/MainActivity.java b/HelicopterControl/src/com/example/fftrajectorymapper/MainActivity.java index d853cb72..aed096be 100755 --- a/HelicopterControl/src/com/example/fftrajectorymapper/MainActivity.java +++ b/HelicopterControl/src/com/example/fftrajectorymapper/MainActivity.java @@ -19,8 +19,6 @@ import android.graphics.EmbossMaskFilter; import android.graphics.MaskFilter; import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.os.AsyncTask; @@ -28,6 +26,7 @@ import android.os.Environment; import android.preference.PreferenceManager; import android.util.Log; +import android.view.Display; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; @@ -62,8 +61,9 @@ public class MainActivity extends Activity{ float originY = 0; float mapWidth = 400; float mapHeight = 400; - int dragButtonSize = 160; - float sX, sY, fX, fY, prevX, prevY, picX, picY; + int submitButtonSize = 160; + int submitButtonMargin = 10; + float sX, sY, tmpX, tmpY, prevX, prevY, picX, picY; Bitmap mBitmap; int OSCPort = 7244; @@ -84,7 +84,7 @@ protected void onCreate(Bundle savedInstanceState) { mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); - mPaint.setColor(0xFF0000FF); + mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); @@ -128,17 +128,15 @@ public void colorChanged(int color) { mPaint.setColor(color); } - public void sendMessage(float sX,float sY,float fX,float fY,float picX,float picY,Bitmap mBitmap){ + public void sendMessage(float sX,float sY,float picX,float picY,Bitmap mBitmap,float submitted){ //Need to account for changing the origin! float unityStartX = ((sX - picX - originX)/mBitmap.getWidth())*mapWidth; float unityStartY = ((sY - picY - originY)/mBitmap.getHeight())*mapHeight; - float unityEndX = ((fX - picX - originX)/mBitmap.getWidth())*mapWidth; - float unityEndY = ((fY - picY - originY)/mBitmap.getHeight())*mapHeight; - args = new Object[4]; + args = new Object[3]; args[0] = unityStartX; args[1] = unityStartY; - args[2] = unityEndX; - args[3] = unityEndY; + args[2] = submitted; + //args[3] = 2.7; message = new OSCMessage("/coords",Arrays.asList(args)); try{ sender.send(message); @@ -151,10 +149,14 @@ private class oscthread extends AsyncTask { @Override protected String doInBackground(String... params) { - sendMessage(sX,sY,fX,fY,picX,picY,mBitmap); + boolean submitted = params[0] == "submit"; + if(submitted){ + sendMessage(sX,sY,picX,picY,mBitmap,1); + } else { + sendMessage(sX,sY,picX,picY,mBitmap,0); + } return null; - } - + } } public class MyView extends View { @@ -184,52 +186,33 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { //Log.i("DRBRG", "Width: " + w + " Height: " + h); } - - protected void calcFinalPoints(float x,float y){ - double dist = Math.sqrt(Math.pow((sX - x),2) + Math.pow((sY - y),2)); - if(dist > maxLength){ - double theta; - if(x > sX){ - theta = Math.atan((sY-y)/(sX-x)); - } else if (sX > x){ - theta = Math.atan((sY-y)/(sX-x)) + Math.PI; - } else { - if(y > sY){ - theta = Math.PI/2; - } else { - theta = (3*Math.PI)/2; - } - } - fX = sX + (float) (maxLength * Math.cos(theta)); - fY = sY + (float) (maxLength * Math.sin(theta)); - } else { - fX = x; - fY = y; - } - } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0xFFAAAAAA); canvas.drawBitmap(mBitmap, picX, picY, mBitmapPaint); - - canvas.drawLine(sX,sY,fX,fY,mPaint); //Draw a circle at the player location canvas.drawCircle(mBitmap.getWidth() * (playerX/mapWidth) + picX + originX, mBitmap.getHeight() * (playerY/mapHeight) + picY + originY, 8, mPaint); canvas.drawCircle(sX, sY, 3, mPaint); - canvas.drawRect(0, 0, dragButtonSize, dragButtonSize, mPaint); + canvas.drawRect(submitButtonMargin, submitButtonMargin, submitButtonSize, submitButtonSize, mPaint); } private static final float TOUCH_TOLERANCE = 4; private void touch_start(float x, float y) { - if(!mapMove && x > 80 && y > 40){ - sX = x; - sY = y; - fX = x; - fY = y; + if(!mapMove){ + //Check if pressed submit + if(x > submitButtonMargin + && y >submitButtonMargin + && x < submitButtonSize - submitButtonMargin + && y < submitButtonSize - submitButtonMargin){ + //Maybe do something? + } else { + sX = x; + sY = y; + } } prevX = x; prevY = y; @@ -243,25 +226,28 @@ private void touch_move(float x, float y) { picY += deltY; sX += deltX; sY += deltY; - fX += deltX; - fY += deltY; prevX = x; prevY = y; - } else { - calcFinalPoints(x,y); + } else { + if(x > submitButtonMargin + && y >submitButtonMargin + && x < submitButtonSize - submitButtonMargin + && y < submitButtonSize - submitButtonMargin){ + //Maybe do something? + } else { + sX = x; + sY = y; + } } } private void touch_up(float x, float y) { - if(mapMove){ - if(x < dragButtonSize && y < dragButtonSize){ - mapMove = false; - } + if(x > submitButtonMargin + && y >submitButtonMargin + && x < submitButtonSize - submitButtonMargin + && y < submitButtonSize - submitButtonMargin){ + new oscthread().execute("submit"); } else { - if(x < dragButtonSize && y < dragButtonSize){ - mapMove = true; - } else { - new oscthread().execute("test"); - } + new oscthread().execute("standard"); } } @@ -270,8 +256,19 @@ public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); - switch (event.getAction()) { + switch (event.getActionMasked()) { + case MotionEvent.ACTION_POINTER_DOWN: + Log.w("osc", "down twice"); + mapMove = true; + sX = tmpX; + sY = tmpY; + touch_start(x,y); + invalidate(); + break; case MotionEvent.ACTION_DOWN: + Log.w("osc", "down"); + tmpX = sX; + tmpY = sY; touch_start(x, y); invalidate(); break; @@ -279,6 +276,11 @@ public boolean onTouchEvent(MotionEvent event) { touch_move(x, y); invalidate(); break; + case MotionEvent.ACTION_POINTER_UP: + mapMove = false; + touch_up(x, y); + invalidate(); + break; case MotionEvent.ACTION_UP: touch_up(x, y); invalidate(); @@ -356,4 +358,4 @@ public boolean onOptionsItemSelected(MenuItem item) { } return super.onOptionsItemSelected(item); } -} +} \ No newline at end of file diff --git a/HelicopterControl_OSCPlugin/ControlPlugin.cpp b/HelicopterControl_OSCPlugin/ControlPlugin.cpp index c00bcac8..b0ac12af 100644 --- a/HelicopterControl_OSCPlugin/ControlPlugin.cpp +++ b/HelicopterControl_OSCPlugin/ControlPlugin.cpp @@ -493,17 +493,18 @@ static void DoRendering (const float* worldMatrix, const float* identityMatrix, #define PORT 7245 #define QPORT 7244 #define SEND_PORT 7001 -float startX = 0; -float startY = 0; -float endX = 0; -float endY = 0; +float recentX = 0; +float recentY = 0; +float submitX = 0; +float submitY = 0; +float submitted = 0; extern "C" { int EXPORT_API startStream(); int EXPORT_API initInterprocessMemory(); - float EXPORT_API getStartX(); - float EXPORT_API getStartY(); - float EXPORT_API getEndX(); - float EXPORT_API getEndY(); + float EXPORT_API getRecentX(); + float EXPORT_API getRecentY(); + float EXPORT_API getSubmitX(); + float EXPORT_API getSubmitY(); void EXPORT_API setDistance(float distance); void EXPORT_API endServer(); void EXPORT_API oscStart(); @@ -511,24 +512,31 @@ extern "C" { } -extern "C" float EXPORT_API getStartX() +extern "C" float EXPORT_API getRecentX() { - return startX; + return recentX; } -extern "C" float EXPORT_API getStartY() +extern "C" float EXPORT_API getRecentY() { - return startY; + return recentY; } -extern "C" float EXPORT_API getEndX() +extern "C" float EXPORT_API getSubmitX() { - return endX; + return submitX; } -extern "C" float EXPORT_API getEndY() +extern "C" float EXPORT_API getSubmitY() { - return endY; + return submitY; +} + +void checkForSubmit(float x, float y,float submit){ + if(submit){ + submitX = x; + submitY = y; + } } UdpTransmitSocket* transmitSocket = nullptr; @@ -568,11 +576,10 @@ class QuaternionPacketListener : public osc::OscPacketListener { // reflection for overloaded messages (eg you can call // (*arg)->IsBool() to check if a bool was passed etc). osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); - startX = (arg++)->AsFloat(); - startY = (arg++)->AsFloat(); - endX = (arg++)->AsFloat(); - endY = (arg++)->AsFloat(); - + recentX = (arg++)->AsFloat(); + recentY = (arg++)->AsFloat(); + submitted = (arg++)->AsFloat(); + checkForSubmit(recentX,recentY,submitted); if( arg != m.ArgumentsEnd() ) throw osc::ExcessArgumentException(); diff --git a/UnityScripts_HelicopterControl/GuideHelicopter.cs b/UnityScripts_HelicopterControl/GuideHelicopter.cs index dfc364bc..045e5edf 100644 --- a/UnityScripts_HelicopterControl/GuideHelicopter.cs +++ b/UnityScripts_HelicopterControl/GuideHelicopter.cs @@ -10,16 +10,16 @@ public class GuideHelicopter : MonoBehaviour { [DllImport("HelicopterControlPlugin")] - private static extern float getStartX(); + private static extern float getRecentX(); [DllImport("HelicopterControlPlugin")] - private static extern float getStartY(); + private static extern float getRecentY(); [DllImport("HelicopterControlPlugin")] - private static extern float getEndX(); + private static extern float getSubmitX(); [DllImport("HelicopterControlPlugin")] - private static extern float getEndY(); + private static extern float getSubmitY(); [DllImport("HelicopterControlPlugin")] private static extern float endServer(); @@ -28,14 +28,14 @@ public class GuideHelicopter : MonoBehaviour void Update() { - float startX = getStartX(); - float startY = getStartY(); - float endX = getEndX(); - float endY = getEndY(); - //Debug.Log ("(" + startX + "," + startY + ") -> (" + endX + "," + endY + ")"); + float recentX = getRecentX(); + float recentY = getRecentY(); + float submitX = getSubmitX(); + float submitY = getSubmitY(); + Debug.Log ("(" + recentX + "," + recentY + ") -> (" + submitX + "," + submitY + ")"); if (marker != null) { - marker.transform.position = new Vector3(startX, marker.transform.position.y, -startY); + marker.transform.position = new Vector3(recentX, marker.transform.position.y, -recentY); } }