|
@@ -24,12 +24,13 @@ import java.util.ArrayList;
|
|
|
import app.ara.ui.CameraPreview;
|
|
|
import app.ara.utils.AndroidResources;
|
|
|
import app.ara.utils.Settings;
|
|
|
-import app.ara.utils.app.brest.game.Area;
|
|
|
-import app.ara.utils.app.brest.game.Game;
|
|
|
-import app.ara.utils.app.brest.game.LocatedResources;
|
|
|
-import app.ara.utils.app.brest.game.Place;
|
|
|
-import app.ara.utils.app.brest.game.Resource;
|
|
|
-import app.ara.utils.app.brest.game.Stage;
|
|
|
+import app.ara.utils.error.ErrorHandler;
|
|
|
+import app.ara.utils.game.Area;
|
|
|
+import app.ara.utils.game.Game;
|
|
|
+import app.ara.utils.game.LocatedResources;
|
|
|
+import app.ara.utils.game.Place;
|
|
|
+import app.ara.utils.game.Resource;
|
|
|
+import app.ara.utils.game.Stage;
|
|
|
import app.ara.utils.geometry.GPSPoint;
|
|
|
import min3d.core.Object3d;
|
|
|
import min3d.core.Object3dContainer;
|
|
@@ -81,7 +82,6 @@ public class ARActivity extends RendererActivity
|
|
|
|
|
|
|
|
|
cameraPreviewLayout = (FrameLayout)findViewById(R.id.camera_preview);
|
|
|
- Log.e("____", "Camera:");
|
|
|
camera = checkDeviceCamera();
|
|
|
mImageSurfaceView = new CameraPreview(ARActivity.this, camera);
|
|
|
|
|
@@ -100,10 +100,8 @@ public class ARActivity extends RendererActivity
|
|
|
Camera mCamera = null;
|
|
|
try {
|
|
|
mCamera = Camera.open();
|
|
|
- Log.e("____", "Camera OK "+mCamera);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- Log.e("____", "Camera Fail "+mCamera);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return mCamera;
|
|
@@ -255,60 +253,59 @@ public class ARActivity extends RendererActivity
|
|
|
|
|
|
protected boolean updateSceneResource()
|
|
|
{
|
|
|
-
|
|
|
- ArrayList<LocatedResources> res = mGame.getResourcesNextToPlayer();
|
|
|
- String toDisplay ="";
|
|
|
- boolean detected = false;
|
|
|
- boolean isAR = mGame.getmSettings().isARMode();
|
|
|
- // String dete = "Detected:\n";
|
|
|
- scene.clear();
|
|
|
+ ArrayList<LocatedResources> res = mGame.getResourcesNextToPlayer();
|
|
|
+ String toDisplay ="";
|
|
|
+ boolean detected = false;
|
|
|
+ boolean isAR = mGame.getmSettings().isARMode();
|
|
|
+ // String dete = "Detected:\n";
|
|
|
+ scene.clear();
|
|
|
|
|
|
|
|
|
- if(mGame.getmSettings().isAreaDebug())
|
|
|
- {
|
|
|
- ArrayList<Area> ar = mGame.getAreaNextToPlayer();
|
|
|
- String ttxt = "Zones trouvées:\n";
|
|
|
- for(int i=0; i<ar.size(); i++)
|
|
|
- ttxt+="\t"+ar.get(i).getName()+"\n";
|
|
|
- toDisplay+=ttxt+"\n";
|
|
|
+ if(mGame.getmSettings().isAreaDebug())
|
|
|
+ {
|
|
|
+ ArrayList<Area> ar = mGame.getAreaNextToPlayer();
|
|
|
+ String ttxt = "Zones trouvées:\n";
|
|
|
+ for(int i=0; i<ar.size(); i++)
|
|
|
+ ttxt+="\t"+ar.get(i).getName()+"\n";
|
|
|
+ toDisplay+=ttxt+"\n";
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if(mGame.getmSettings().isAreaDebug()) toDisplay+="Resources détectées: \n";
|
|
|
+ if(mGame.getmSettings().isAreaDebug()) toDisplay+="Resources détectées: \n";
|
|
|
|
|
|
- for (int i = 0; i < res.size(); i++) {
|
|
|
- Resource rr = res.get(i).getResource(0);
|
|
|
- Place p = res.get(i).getPlace();
|
|
|
- if (rr != null) {
|
|
|
- detected = true;
|
|
|
- if(isAR) mGame.getPlayer().freezePosition(p.getLocation());
|
|
|
- toDisplay=updateArSceneResource(rr, p, toDisplay);
|
|
|
+ for (int i = 0; i < res.size(); i++) {
|
|
|
+ Resource rr = res.get(i).getResource(0);
|
|
|
+ Place p = res.get(i).getPlace();
|
|
|
+ if (rr != null) {
|
|
|
+ detected = true;
|
|
|
+ if(isAR) mGame.getPlayer().freezePosition(p.getLocation());
|
|
|
+ toDisplay=updateArSceneResource(rr, p, toDisplay);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if(isAR && res.size()==0) mGame.getPlayer().releasePosition();
|
|
|
+ if(isAR && res.size()==0) mGame.getPlayer().releasePosition();
|
|
|
|
|
|
- updateLed(detected, mGame.getResourcesNextToPlayerDistDouble());
|
|
|
+ updateLed(detected, mGame.getResourcesNextToPlayerDistDouble());
|
|
|
|
|
|
|
|
|
|
|
|
- //affichage en debug
|
|
|
- final String td = toDisplay;
|
|
|
- final TextView xv = (TextView)findViewById(R.id.text_area);
|
|
|
- xv.getHandler().post(new Runnable() { public void run() { xv.setText(td); } });
|
|
|
+ //affichage en debug
|
|
|
+ final String td = toDisplay;
|
|
|
+ final TextView xv = (TextView)findViewById(R.id.text_area);
|
|
|
+ xv.getHandler().post(new Runnable() { public void run() { xv.setText(td); } });
|
|
|
|
|
|
|
|
|
- //affichage de la distance dans l'HUD
|
|
|
- final String dete2 = mGame.getResourcesNextToPlayerDist();
|
|
|
- mTvDistance.getHandler().post(new Runnable() {
|
|
|
- public void run() {
|
|
|
- mTvDistance.setText(dete2);
|
|
|
- }
|
|
|
- });
|
|
|
+ //affichage de la distance dans l'HUD
|
|
|
+ final String dete2 = mGame.getResourcesNextToPlayerDist();
|
|
|
+ mTvDistance.getHandler().post(new Runnable() {
|
|
|
+ public void run() {
|
|
|
+ mTvDistance.setText(dete2);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- if(mGame.getmSettings().isARMode())
|
|
|
- return scene.numChildren()>0;
|
|
|
- else
|
|
|
- return res.size()>0;
|
|
|
+ if(mGame.getmSettings().isARMode())
|
|
|
+ return scene.numChildren()>0;
|
|
|
+ else
|
|
|
+ return res.size()>0;
|
|
|
}
|
|
|
|
|
|
protected void onList()
|
|
@@ -331,55 +328,60 @@ public class ARActivity extends RendererActivity
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
{
|
|
|
super.onCreate(savedInstanceState);
|
|
|
-
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
- setContentView(R.layout.activity_ar);
|
|
|
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
- //mGame = (Game) getIntent().getSerializableExtra("game");
|
|
|
- mGame = Game.game();
|
|
|
- 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(pxToDp((int)(h*0.100f/3.5)));
|
|
|
- mTvGPS.setText("N ?°\nE ?°");
|
|
|
- mTvAngle.setTextSize(pxToDp((int)(h*0.121f/3.5)));
|
|
|
- mTvDistance.setTextSize(pxToDp((int)(h*0.046f)));
|
|
|
-
|
|
|
- moveView(mTvAngle, (int)(0.03*w), (int)(0.864f*h), (int)(0.291f*w), (int)(0.121*h ));
|
|
|
- moveView(mTvGPS, w-(int)(0.32f*w), (int)(0.875f*h),(int)(0.3*w), (int)(0.121*h));
|
|
|
- moveView(mTvDistance, w-mTvDistance.getWidth()-(int)(0.36f*w), (int)(0.033f*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));
|
|
|
- }
|
|
|
- });
|
|
|
+ try{
|
|
|
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
+ setContentView(R.layout.activity_ar);
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
+ //mGame = (Game) getIntent().getSerializableExtra("game");
|
|
|
+ mGame = Game.game();
|
|
|
+ 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(pxToDp((int)(h*0.100f/3.5)));
|
|
|
+ mTvGPS.setText("N ?°\nE ?°");
|
|
|
+ mTvAngle.setTextSize(pxToDp((int)(h*0.121f/3.5)));
|
|
|
+ mTvDistance.setTextSize(pxToDp((int)(h*0.046f)));
|
|
|
+
|
|
|
+ moveView(mTvAngle, (int)(0.03*w), (int)(0.864f*h), (int)(0.291f*w), (int)(0.121*h ));
|
|
|
+ moveView(mTvGPS, w-(int)(0.32f*w), (int)(0.875f*h),(int)(0.3*w), (int)(0.121*h));
|
|
|
+ moveView(mTvDistance, w-mTvDistance.getWidth()-(int)(0.36f*w), (int)(0.033f*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));
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
|
|
|
|
|
|
- int w = mRlRoot.getWidth();
|
|
|
- int h = mRlRoot.getHeight();
|
|
|
+ int w = mRlRoot.getWidth();
|
|
|
+ int h = mRlRoot.getHeight();
|
|
|
|
|
|
- mGame.printStage();
|
|
|
+ mGame.printStage();
|
|
|
+ }catch(Exception e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ ErrorHandler.addError(this, e);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -392,47 +394,54 @@ public class ARActivity extends RendererActivity
|
|
|
*/
|
|
|
public void updateScene()
|
|
|
{
|
|
|
- synchronized (mUpdate)
|
|
|
+ try
|
|
|
{
|
|
|
- if(!mUpdate) return;
|
|
|
+ synchronized (mUpdate)
|
|
|
+ {
|
|
|
+ if(!mUpdate) return;
|
|
|
+
|
|
|
+ //Precache du modèle 3D
|
|
|
+ synchronized (mLock) {
|
|
|
+ if (!isPausing) {
|
|
|
+ boolean b = mGame.precache3DResource(this);
|
|
|
+ mIsResource = updateSceneResource();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ scene.clear();
|
|
|
+ mGame.removeCached3DModels();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //Precache du modèle 3D
|
|
|
- synchronized (mLock) {
|
|
|
- if (!isPausing) {
|
|
|
- boolean b = mGame.precache3DResource(this);
|
|
|
- mIsResource = updateSceneResource();
|
|
|
+ if(mIsResource) {
|
|
|
+ mOkButton.getHandler().post(new Runnable() {
|
|
|
+ public void run() {
|
|
|
+ mOkButton.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
}else
|
|
|
{
|
|
|
- scene.clear();
|
|
|
- mGame.removeCached3DModels();
|
|
|
- }
|
|
|
- }
|
|
|
+ mOkButton.getHandler().post(new Runnable() {
|
|
|
+ public void run() {
|
|
|
+ mOkButton.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- if(mIsResource) {
|
|
|
- mOkButton.getHandler().post(new Runnable() {
|
|
|
- public void run() {
|
|
|
- mOkButton.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
- });
|
|
|
- }else
|
|
|
- {
|
|
|
- mOkButton.getHandler().post(new Runnable() {
|
|
|
+ }
|
|
|
+ mTvAngle.getHandler().post(new Runnable() {
|
|
|
public void run() {
|
|
|
- mOkButton.setVisibility(View.INVISIBLE);
|
|
|
+ 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())+"°");
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ setGpsText();
|
|
|
}
|
|
|
- mTvAngle.getHandler().post(new Runnable() {
|
|
|
- public void run() {
|
|
|
- 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())+"°");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- setGpsText();
|
|
|
+ }catch(Exception e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ ErrorHandler.addError(this, e);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -483,7 +492,7 @@ public class ARActivity extends RendererActivity
|
|
|
|
|
|
public void finish()
|
|
|
{
|
|
|
- mGame.stopSensors();
|
|
|
+ if(mGame!=null)mGame.stopSensors();
|
|
|
super.finish();
|
|
|
}
|
|
|
|
|
@@ -530,7 +539,7 @@ public class ARActivity extends RendererActivity
|
|
|
|
|
|
if(finished)
|
|
|
{
|
|
|
- Log.e("Finished", "Finished");
|
|
|
+ Log.i("app.ara: ARA", "Finished");
|
|
|
}
|
|
|
|
|
|
if(stageFinished)
|
|
@@ -542,14 +551,12 @@ public class ARActivity extends RendererActivity
|
|
|
Intent intent2 = new Intent(this, EndActivity.class);
|
|
|
startActivity(intent2);
|
|
|
}
|
|
|
- System.out.println("Ressource: '"+s.getResourceName()+"' : "+!s.getResourceName().isEmpty());
|
|
|
if(!s.getResourceName().isEmpty() && s.isTransition())
|
|
|
{
|
|
|
Intent intent = AndroidResources.getViewerIntent(this, stageRes);
|
|
|
startActivity(intent);
|
|
|
}
|
|
|
|
|
|
- System.out.println("Transition: '"+s.isTransition());
|
|
|
if(s.isTransition())
|
|
|
{
|
|
|
Intent intent2 = new Intent(this, TransferActivity.class);
|
|
@@ -587,12 +594,19 @@ public class ARActivity extends RendererActivity
|
|
|
public void onClickScreen(View v)
|
|
|
|
|
|
{
|
|
|
- if(mIsResource)
|
|
|
- onClickPickUp(v);
|
|
|
- else if(Settings.getSettings().isGPSDebug())
|
|
|
- mGame.getPlayer().nextStub();
|
|
|
- else {
|
|
|
+ try{
|
|
|
+ if(mIsResource)
|
|
|
+ onClickPickUp(v);
|
|
|
+ else if(Settings.getSettings().isGPSDebug())
|
|
|
+ mGame.getPlayer().nextStub();
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ }catch(Exception e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ ErrorHandler.addError(this, e);
|
|
|
}
|
|
|
}
|
|
|
|