|
@@ -1,24 +1,32 @@
|
|
package app.brest.testmin3d;
|
|
package app.brest.testmin3d;
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
|
+import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.content.pm.ActivityInfo;
|
|
import android.content.pm.ActivityInfo;
|
|
import android.graphics.PixelFormat;
|
|
import android.graphics.PixelFormat;
|
|
import android.hardware.Camera;
|
|
import android.hardware.Camera;
|
|
import android.media.MediaPlayer;
|
|
import android.media.MediaPlayer;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
+import android.os.Handler;
|
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
|
+import android.view.ViewTreeObserver;
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageButton;
|
|
|
|
+import android.widget.ImageView;
|
|
import android.widget.MediaController;
|
|
import android.widget.MediaController;
|
|
|
|
+import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
import android.widget.VideoView;
|
|
import android.widget.VideoView;
|
|
|
|
|
|
import org.w3c.dom.Text;
|
|
import org.w3c.dom.Text;
|
|
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
+import java.text.NumberFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
@@ -58,12 +66,24 @@ public class ARActivity extends RendererActivity
|
|
protected boolean isPausing=false;
|
|
protected boolean isPausing=false;
|
|
protected static GPSPoint mLocation;
|
|
protected static GPSPoint mLocation;
|
|
protected static boolean mLocationUpdated=false;
|
|
protected static boolean mLocationUpdated=false;
|
|
|
|
+ protected TextView mTvDistance;
|
|
|
|
+ protected TextView mTvAngle;
|
|
|
|
+ protected TextView mTvGPS;
|
|
|
|
+ protected RelativeLayout mRlRoot;
|
|
|
|
+ protected ImageView mIvWhite;
|
|
|
|
+ protected ImageView mIvRed;
|
|
|
|
+ protected ImageView mIvGreen;
|
|
|
|
+ protected ImageView mIvNone;
|
|
|
|
+ protected int mViewWidth;
|
|
|
|
+ protected int mViewHeight;
|
|
|
|
+ protected boolean mDetect=false;
|
|
|
|
+ protected boolean mInArea=false;
|
|
private Game mGame;
|
|
private Game mGame;
|
|
|
|
|
|
|
|
+ private Handler mCustomHandler = new Handler();
|
|
|
|
|
|
public void init()
|
|
public void init()
|
|
{
|
|
{
|
|
- setContentView(R.layout.activity_main);
|
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
|
|
|
|
|
|
|
@@ -80,8 +100,8 @@ public class ARActivity extends RendererActivity
|
|
mOkButton.setVisibility(View.INVISIBLE);
|
|
mOkButton.setVisibility(View.INVISIBLE);
|
|
if(cameraPreviewLayout.getChildCount()<2)
|
|
if(cameraPreviewLayout.getChildCount()<2)
|
|
{
|
|
{
|
|
|
|
+ cameraPreviewLayout.addView(_glSurfaceView,0);
|
|
cameraPreviewLayout.addView(mImageSurfaceView,0);
|
|
cameraPreviewLayout.addView(mImageSurfaceView,0);
|
|
- cameraPreviewLayout.addView(_glSurfaceView,1);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -140,6 +160,62 @@ public class ARActivity extends RendererActivity
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Runnable updateTimerThread = new Runnable() {
|
|
|
|
+
|
|
|
|
+ public void run() {
|
|
|
|
+ mCustomHandler.postDelayed(this, 10);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ protected long mLedPeriode=0;
|
|
|
|
+ protected long mLedLastTick=0;
|
|
|
|
+ protected boolean mLedState=false;
|
|
|
|
+ protected void updateLed(boolean detected, double dist)
|
|
|
|
+ {
|
|
|
|
+ //si detecte
|
|
|
|
+ if(detected)
|
|
|
|
+ {
|
|
|
|
+ mIvWhite.getHandler().post(new Runnable() { public void run() {mIvWhite.setVisibility(View.VISIBLE);}});
|
|
|
|
+ mIvGreen.getHandler().post(new Runnable() { public void run() {mIvGreen.setVisibility(View.VISIBLE);}});
|
|
|
|
+ mIvRed.getHandler().post(new Runnable() { public void run() {mIvRed.setVisibility(View.INVISIBLE);}});
|
|
|
|
+ mInArea=mDetect=true;
|
|
|
|
+ }
|
|
|
|
+ //si dans une zone
|
|
|
|
+ else if(dist>=0)
|
|
|
|
+ {
|
|
|
|
+ if(dist<5) mLedPeriode=5;
|
|
|
|
+ else if(dist>=5 && dist<50) mLedPeriode=(int)((dist-4)*10);
|
|
|
|
+ else mLedPeriode=500;
|
|
|
|
+ if(System.currentTimeMillis()>mLedLastTick+mLedPeriode)
|
|
|
|
+ {
|
|
|
|
+ mLedLastTick=System.currentTimeMillis();
|
|
|
|
+ if(mLedState)
|
|
|
|
+ {
|
|
|
|
+ mLedState=false;
|
|
|
|
+ mIvWhite.getHandler().post(new Runnable() { public void run() {mIvWhite.setVisibility(View.INVISIBLE);}});
|
|
|
|
+ }else
|
|
|
|
+ {
|
|
|
|
+ mLedState=true;
|
|
|
|
+ mIvWhite.getHandler().post(new Runnable() { public void run() {mIvWhite.setVisibility(View.VISIBLE);}});
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mIvGreen.getHandler().post(new Runnable() { public void run() {mIvGreen.setVisibility(View.INVISIBLE);}});
|
|
|
|
+ mIvRed.getHandler().post(new Runnable() { public void run() {mIvRed.setVisibility(View.VISIBLE);}});
|
|
|
|
+ mInArea=true;
|
|
|
|
+ mDetect=false;
|
|
|
|
+ }
|
|
|
|
+ //si rien
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ mIvWhite.getHandler().post(new Runnable() { public void run() {mIvWhite.setVisibility(View.INVISIBLE);}});
|
|
|
|
+ mIvGreen.getHandler().post(new Runnable() { public void run() {mIvGreen.setVisibility(View.INVISIBLE);}});
|
|
|
|
+ mIvRed.getHandler().post(new Runnable() { public void run() {mIvRed.setVisibility(View.INVISIBLE);}});
|
|
|
|
+ mInArea=mDetect=false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
protected boolean updateSceneResource()
|
|
protected boolean updateSceneResource()
|
|
{
|
|
{
|
|
|
|
|
|
@@ -147,12 +223,14 @@ public class ARActivity extends RendererActivity
|
|
final TextView tv = (TextView) findViewById(R.id.text_detected);
|
|
final TextView tv = (TextView) findViewById(R.id.text_detected);
|
|
final TextView tv2 = (TextView)findViewById(R.id.text_place);
|
|
final TextView tv2 = (TextView)findViewById(R.id.text_place);
|
|
String toDisplay ="Detetected \n";
|
|
String toDisplay ="Detetected \n";
|
|
|
|
+ boolean detected = false;
|
|
// String dete = "Detected:\n";
|
|
// String dete = "Detected:\n";
|
|
scene.clear();
|
|
scene.clear();
|
|
for (int i = 0; i < res.size(); i++) {
|
|
for (int i = 0; i < res.size(); i++) {
|
|
Resource rr = res.get(i).getResource();
|
|
Resource rr = res.get(i).getResource();
|
|
Place p = res.get(i).getPlace();
|
|
Place p = res.get(i).getPlace();
|
|
if(rr!=null) {
|
|
if(rr!=null) {
|
|
|
|
+ detected=true;
|
|
toDisplay += "\t" + rr.getName() + " \n";
|
|
toDisplay += "\t" + rr.getName() + " \n";
|
|
//dete += "\t" + rr.getName() + "\n";
|
|
//dete += "\t" + rr.getName() + "\n";
|
|
Object3d oo = rr.get3DModel(this);
|
|
Object3d oo = rr.get3DModel(this);
|
|
@@ -175,19 +253,27 @@ public class ARActivity extends RendererActivity
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ updateLed(detected, mGame.getResourcesNextToPlayerDistDouble());
|
|
|
|
+
|
|
|
|
+
|
|
final String td = toDisplay;
|
|
final String td = toDisplay;
|
|
- mAngle.getHandler().post(new Runnable() {
|
|
|
|
|
|
+ /*mAngle.getHandler().post(new Runnable() {
|
|
public void run() {
|
|
public void run() {
|
|
tv2.setText(td);
|
|
tv2.setText(td);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ });*/
|
|
|
|
|
|
- final String dete2 = mGame.getResourcesNextToPlayer2();
|
|
|
|
|
|
+ final String dete2 = mGame.getResourcesNextToPlayerDist();
|
|
tv.getHandler().post(new Runnable() {
|
|
tv.getHandler().post(new Runnable() {
|
|
public void run() {
|
|
public void run() {
|
|
tv.setText(dete2);
|
|
tv.setText(dete2);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+ mTvDistance.getHandler().post(new Runnable() {
|
|
|
|
+ public void run() {
|
|
|
|
+ mTvDistance.setText(dete2);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
|
|
|
|
return scene.numChildren()>0;
|
|
return scene.numChildren()>0;
|
|
@@ -200,16 +286,65 @@ public class ARActivity extends RendererActivity
|
|
startActivity(intent);
|
|
startActivity(intent);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ protected void moveView(View v, int x, int y, int w, int h)
|
|
|
|
+ {
|
|
|
|
+ RelativeLayout.LayoutParams l = new RelativeLayout.LayoutParams(w, h);
|
|
|
|
+ l.leftMargin = x;
|
|
|
|
+ l.topMargin = y;
|
|
|
|
+ v.setLayoutParams(l);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
{
|
|
{
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
|
+ setContentView(R.layout.activity_main);
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
//mGame = (Game) getIntent().getSerializableExtra("game");
|
|
//mGame = (Game) getIntent().getSerializableExtra("game");
|
|
mGame = Game.game();
|
|
mGame = Game.game();
|
|
mGame.newSensorManager(this);
|
|
mGame.newSensorManager(this);
|
|
|
|
+ mTvDistance=(TextView)findViewById(R.id.tv_distance);
|
|
|
|
+ mTvAngle=(TextView)findViewById(R.id.tv_angle);
|
|
|
|
+ mTvGPS=(TextView)findViewById(R.id.tv_gps);
|
|
|
|
+ mRlRoot=(RelativeLayout) findViewById(R.id.rl_root);
|
|
|
|
+ mIvWhite=(ImageView)findViewById(R.id.iv_white);
|
|
|
|
+ mIvRed=(ImageView)findViewById(R.id.iv_red);
|
|
|
|
+ mIvGreen=(ImageView)findViewById(R.id.iv_green);
|
|
|
|
+ mIvNone=(ImageView)findViewById(R.id.iv_none);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ViewTreeObserver vto = mRlRoot.getViewTreeObserver();
|
|
|
|
+ vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onGlobalLayout() {
|
|
|
|
+ mRlRoot.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
|
|
|
+ int w =mViewWidth = mRlRoot.getMeasuredWidth();
|
|
|
|
+ int h =mViewHeight = mRlRoot.getMeasuredHeight();
|
|
|
|
+
|
|
|
|
+ mTvGPS.setTextSize((int)(h*0.121f/6));
|
|
|
|
+ mTvGPS.setText("N ?°\nE ?°");
|
|
|
|
+ mTvAngle.setTextSize((int)(h*0.121f/6));
|
|
|
|
+ mTvDistance.setTextSize((int)(h*0.046f/1.8));
|
|
|
|
+
|
|
|
|
+ moveView(mTvAngle, (int)(0.03*w), (int)(0.864f*h), (int)(0.291f*w), (int)(0.121*h ));
|
|
|
|
+ moveView(mTvGPS, w-(int)(0.297f*w), (int)(0.875f*h),(int)(0.291f*w), (int)(0.121*h));
|
|
|
|
+ moveView(mTvDistance, w-mTvDistance.getWidth()-(int)(0.359f*w), (int)(0.038f*h), mTvGPS.getWidth(), (int)(0.121*h));
|
|
|
|
+
|
|
|
|
+ moveView(mIvNone, (int)(w/4.0), 0, (int)(w/2.0), (int)(0.06f*h));
|
|
|
|
+ moveView(mIvWhite, (int)(w*0.269), (int)(0.034*h), (int)(w*0.03333), (int)(0.02286f*h));
|
|
|
|
+ moveView(mIvRed, (int)(w*0.702), (int)(0.034*h), (int)(w*0.03333), (int)(0.02286f*h));
|
|
|
|
+ moveView(mIvGreen, (int)(w*0.702), (int)(0.034*h), (int)(w*0.03333), (int)(0.02286f*h));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
+ Log.e("_________", "MrlRoot="+mIvRed.getWidth()+" et "+mIvRed.getHeight());
|
|
|
|
+ int w = mRlRoot.getWidth();
|
|
|
|
+ int h = mRlRoot.getHeight();
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -259,11 +394,12 @@ public class ARActivity extends RendererActivity
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
- mAngle.getHandler().post(new Runnable() {
|
|
|
|
|
|
+ mTvAngle.getHandler().post(new Runnable() {
|
|
public void run() {
|
|
public void run() {
|
|
- mAngle.setText("Angle X: "+mGame.getPlayer().getOrientation()+"°\n Angle Y: "+
|
|
|
|
- mGame.getPlayer().getOrientationY()
|
|
|
|
- +"\n Angle Z: "+mGame.getPlayer().getOrientationZ()+"°");
|
|
|
|
|
|
+ NumberFormat formatter = new DecimalFormat("#0.0");
|
|
|
|
+ mTvAngle.setText("X : "+formatter.format(mGame.getPlayer().getOrientation())+"°\nY : "+
|
|
|
|
+ formatter.format(mGame.getPlayer().getOrientationY())
|
|
|
|
+ +"°\nZ : "+formatter.format(mGame.getPlayer().getOrientationZ())+"°");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -308,10 +444,12 @@ public class ARActivity extends RendererActivity
|
|
{
|
|
{
|
|
if(mLocationUpdated) {
|
|
if(mLocationUpdated) {
|
|
final GPSPoint gps = mLocation;
|
|
final GPSPoint gps = mLocation;
|
|
- mGps.getHandler().post(new Runnable() {
|
|
|
|
|
|
+ mTvGPS.getHandler().post(new Runnable() {
|
|
|
|
|
|
public void run() {
|
|
public void run() {
|
|
- mGps.setText("Latitude: " + gps.getX() + "°\n Longitude: " + gps.getY() + "\n");
|
|
|
|
|
|
+
|
|
|
|
+ NumberFormat formatter = new DecimalFormat("#0.0000000");
|
|
|
|
+ mTvGPS.setText("N "+formatter.format(gps.getX()) + "°\nE " + formatter.format(gps.getY()) + "°\n");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
mLocationUpdated=false;
|
|
mLocationUpdated=false;
|