Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two fingered drag, a submit button, and one point #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified HelicopterControl/libs/android-support-v4.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion HelicopterControl/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
target=android-23
122 changes: 62 additions & 60 deletions HelicopterControl/src/com/example/fftrajectorymapper/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
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;
import android.os.Bundle;
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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -151,10 +149,14 @@ private class oscthread extends AsyncTask<String, Integer, String> {

@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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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");
}
}

Expand All @@ -270,15 +256,31 @@ 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;
case MotionEvent.ACTION_MOVE:
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();
Expand Down Expand Up @@ -356,4 +358,4 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
return super.onOptionsItemSelected(item);
}
}
}
49 changes: 28 additions & 21 deletions HelicopterControl_OSCPlugin/ControlPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,42 +493,50 @@ 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();
void EXPORT_API oscPhaseSpaceStart();
}


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;
Expand Down Expand Up @@ -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();

Expand Down
20 changes: 10 additions & 10 deletions UnityScripts_HelicopterControl/GuideHelicopter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand Down