François Gautrais 8 anni fa
parent
commit
5529bd56c4

+ 1 - 1
app/src/main/AndroidManifest.xml

@@ -16,7 +16,7 @@
 
     <application
         android:allowBackup="true"
-        android:icon="@mipmap/ic_launcher"
+        android:icon="@drawable/logo"
         android:label="@string/app_name"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">

+ 9 - 8
app/src/main/java/app/brest/testmin3d/ARActivity.java

@@ -242,15 +242,14 @@ public class ARActivity extends RendererActivity
                 v.target.y=mGame.getPlayer().getOrientationY()-315;
 
                 //si utilisation de field et angle
-                Log.e("_______",rr.getName()+" ---> "+p.isUseAngle());
                 if(p.isUseAngle())
                     v.target.x=(float)(mGame.getPlayer().getOrientationX()-p.getAngle())+mGame.getPlayer().getOrientationZ()-270f;
                 //si utilisation GPS pour l'angle
                 else {
-                    v.target.x = (float) (mGame.getPlayer().getOrientationX() - mGame.getPlayer().getAngleWith(p))
-                            + mGame.getPlayer().getOrientationZ() - 270f;
+                    v.target.x = (float) (mGame.getPlayer().getOrientationX() - mGame.getPlayer().getAngleWith(p)+90)
+                            + mGame.getPlayer().getOrientationZ() ;
 
-                    toDisplay += "Angle " + dts(mGame.getPlayer().getAngleWith(p)) + "°\nx,y = (" + dts(mGame.getPlayer().getXWith(p)) + " m, " + dts(mGame.getPlayer().getYWith(p)) +
+                    toDisplay += "Angle " + dts(mGame.getPlayer().getAngleWith(p)) + "°\nx,y = (" + dts(mGame.getPlayer().getRelXWith(p)*1000000) + " m, " + dts(mGame.getPlayer().getRelYWith(p)*1000000) +
                             " m)\nPlayer :" + dts(mGame.getPlayer().getOrientationX()) + "°\nAngleWith:" + dts(mGame.getPlayer().getAngleWith(p)) +
                             "°\nZ " + dts(mGame.getPlayer().getOrientationZ() - 270f) + "°\nTotal " + dts(v.target.x) + "°";
                 }
@@ -351,7 +350,6 @@ public class ARActivity extends RendererActivity
 
 
 
-        Log.e("_________", "MrlRoot="+mIvRed.getWidth()+" et "+mIvRed.getHeight());
         int w = mRlRoot.getWidth();
         int h = mRlRoot.getHeight();
 
@@ -476,7 +474,8 @@ public class ARActivity extends RendererActivity
                 public void run() {
 
                     NumberFormat formatter = new DecimalFormat("#0.0000000");
-                    mTvGPS.setText("N "+formatter.format(gps.getX()) + "°\nE " + formatter.format(gps.getY()) + "°\n");
+                    NumberFormat formatter2 = new DecimalFormat("#0.0");
+                    mTvGPS.setText("N "+formatter.format(gps.getX()) + "°\nE " + formatter.format(gps.getY()) + "°\n+/- "+formatter2.format(gps.getAccuracy())+" m");
                 }
             });
             mLocationUpdated=false;
@@ -503,7 +502,6 @@ public class ARActivity extends RendererActivity
         if(stageFinished)
         {
            finished = mGame.nextStage();
-            Log.e("--____", "Finished="+finished);
         }
 
         if(finished)
@@ -518,7 +516,6 @@ public class ARActivity extends RendererActivity
 
             if(finished)
             {
-                Log.e("--____", "Here");
                 Intent intent2 = new Intent(this, EndActivity.class);
                 startActivity(intent2);
             }
@@ -555,5 +552,9 @@ public class ARActivity extends RendererActivity
         return (int) (px / Resources.getSystem().getDisplayMetrics().density);
     }
 
+    public void onStub(View v)
+    {
+        mGame.getPlayer().nextStub();
+    }
 
 }

+ 0 - 1
app/src/main/java/app/brest/testmin3d/MenuActivity.java

@@ -148,7 +148,6 @@ public class MenuActivity extends Activity {
 
         if(finished)
         {
-            Log.e("--____", "Here");
             Intent intent2 = new Intent(this, EndActivity.class);
             startActivity(intent2);
         }

+ 11 - 10
app/src/main/java/app/brest/testmin3d/NewMenuActivity.java

@@ -49,7 +49,7 @@ public class NewMenuActivity extends Activity implements View.OnClickListener{
     private Button mBOptions;
     private Button mBMenu;
     private Button mBSend;
-
+    private int mHOffset=0;
 
     private void setUpStyle()
     {
@@ -58,11 +58,12 @@ public class NewMenuActivity extends Activity implements View.OnClickListener{
         int w4 = mWidth/3;
         int w = (int)(w4*1.25);
         int h = dpToPx((int)(mBBriefing.getTextSize()*1.5));
-        moveView(mBBriefing, w4-2*w/3, h4-h,w,h);
-        moveView(mBInvotory, 2*w4-w/3, h4-h,w,h);
-        moveView(mBMap, w4-2*w/3, 2*h4,w,h);
-        moveView(mBOptions, 2*w4-w/3, 2*h4,w,h);
-        moveView(mBSend, 0, mHeight-h, mWidth, h);
+
+        moveView(mBBriefing, w4-2*w/3, mHOffset+h4-h,w,h);
+        moveView(mBInvotory, 2*w4-w/3, mHOffset+h4-h,w,h);
+        moveView(mBMap, w4-2*w/3, mHOffset+2*h4,w,h);
+        moveView(mBOptions, 2*w4-w/3, mHOffset+2*h4,w,h);
+        moveView(mBSend, mWidth/2-w, mHOffset+2*h4+4*h/3, 2*w, h);
         mBMenu.setTextSize(25);
         mBMenu.setTypeface(null,Typeface.BOLD);
         sendVisibility();
@@ -76,6 +77,7 @@ public class NewMenuActivity extends Activity implements View.OnClickListener{
         display.getSize(size);
         mWidth = size.x;
         mHeight = size.y;
+        mHOffset=mHeight/15;
     }
 
     protected void moveView(View v, int x, int y, int w, int h)
@@ -148,7 +150,7 @@ public class NewMenuActivity extends Activity implements View.OnClickListener{
         mIbScanner.setTextSize(22);
         mIbScanner.setOnClickListener(this);
 
-        moveView(mIbScanner, mWidth/2-mHeight/8, mHeight/2-mHeight/8, mHeight/4, mHeight/4);
+        moveView(mIbScanner, mWidth/2-mHeight/8, mHOffset+mHeight/2-mHeight/8, mHeight/4, mHeight/4);
 
         mBBriefing = newButton("Briefing");
         mBInvotory = newButton("Inventaire");
@@ -219,7 +221,6 @@ public class NewMenuActivity extends Activity implements View.OnClickListener{
 
         if(finished)
         {
-            Log.e("--____", "Here");
             Intent intent2 = new Intent(this, EndActivity.class);
             startActivity(intent2);
         }
@@ -251,8 +252,8 @@ public class NewMenuActivity extends Activity implements View.OnClickListener{
 
     private void sendVisibility()
     {
-        if(mGame.canSendData()) mBSend.setVisibility(View.VISIBLE);
-        else mBSend.setVisibility(View.INVISIBLE);
+        //if(mGame.canSendData()) mBSend.setVisibility(View.VISIBLE);
+        //else mBSend.setVisibility(View.INVISIBLE);
     }
 
     private Runnable updateTimerThread = new Runnable() {

+ 7 - 1
app/src/main/java/app/brest/testmin3d/TransferActivity.java

@@ -62,7 +62,13 @@ public class TransferActivity extends Activity {
                 });
 
                 AlertDialog dialog = builder.create();
-                dialog.show();
+                try{
+                    dialog.show();
+                }catch(Exception e)
+                {
+
+                }
+
 
 
             }

+ 69 - 0
app/src/main/java/app/brest/utils/GpsStub.java

@@ -0,0 +1,69 @@
+package app.brest.utils;
+
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import app.brest.utils.geometry.GPSPoint;
+
+/**
+ * Created by ptitcois on 24/10/16.
+ */
+public class GpsStub {
+    protected ArrayList<GPSPoint> mStubs = new ArrayList<GPSPoint>();
+    protected boolean mIsActive;
+    protected int mI = 0;
+
+    public GpsStub(boolean act)
+    {
+        mIsActive=act;
+    }
+
+    public GpsStub(String r)
+    {
+        mIsActive=true;
+        add(r);
+    }
+
+
+    public void add(GPSPoint p)
+    {
+        mStubs.add(p);
+    }
+
+    public void add(String p)
+    {
+        String r[] = p.split(";");
+        for(int i=0; i<r.length; i++)
+            addLine(r[i]);
+    }
+
+    private void addLine(String str)
+    {
+        GPSPoint p =  null;
+        double lon=0, lat=0, acc=0;
+        String res[] = str.split("\\s+");
+        try {
+            if (res.length > 0) lon = (double) Double.parseDouble(res[0]);
+            if (res.length > 1) lat = (double) Double.parseDouble(res[1]);
+            if (res.length > 2) acc = (double) Double.parseDouble(res[2]);
+        }catch (Exception e){}
+        add(new GPSPoint(lon, lat,(float) acc));
+    }
+
+    public GPSPoint next()
+    {
+        if(mStubs.size()>0)
+        {
+            GPSPoint p = mStubs.get(mI);
+            mI++;
+            if(mI==mStubs.size())
+                mI=0;
+            return p;
+        }
+        else return null;
+    }
+
+
+}

+ 36 - 11
app/src/main/java/app/brest/utils/SensorsManager.java

@@ -18,6 +18,7 @@ import android.support.v4.content.ContextCompat;
 import android.widget.Toast;
 
 import app.brest.testmin3d.ARActivity;
+import app.brest.testmin3d.R;
 import app.brest.utils.geometry.GPSPoint;
 
 /**
@@ -25,6 +26,7 @@ import app.brest.utils.geometry.GPSPoint;
  */
 public class SensorsManager implements SensorEventListener, LocationListener {
 
+    public final boolean USE_GPS_STUB=true;
     private SensorManager mSensorManager;
     private Sensor mAccelerometer;
     private Sensor mMagnetometer;
@@ -47,6 +49,7 @@ public class SensorsManager implements SensorEventListener, LocationListener {
     private float mAccuracy;
     private boolean mIsLocalised = false;
     private Activity mParent;
+    private GpsStub mStub=null;
 
     public float getAzimuth() {
         return mBufferX.average();
@@ -90,14 +93,21 @@ public class SensorsManager implements SensorEventListener, LocationListener {
                 ActivityCompat.checkSelfPermission(mParent, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
 
         }
-        if (ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_FINE_LOCATION) ==
-                PackageManager.PERMISSION_GRANTED &&
-                ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
-                        PackageManager.PERMISSION_GRANTED) {
-            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
-        } else {
-            Toast.makeText(parent,"Error", Toast.LENGTH_LONG).show();
-            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+        if(!USE_GPS_STUB) {
+            if (ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_FINE_LOCATION) ==
+                    PackageManager.PERMISSION_GRANTED &&
+                    ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
+                            PackageManager.PERMISSION_GRANTED) {
+                mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+            } else {
+                Toast.makeText(parent, "Error", Toast.LENGTH_LONG).show();
+                mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+            }
+        }
+        if(USE_GPS_STUB) {
+            mIsLocalised=true;
+            mStub=new GpsStub(parent.getResources().getString(R.string.gps_stub));
+            nextStub();
         }
     }
 
@@ -177,9 +187,11 @@ public class SensorsManager implements SensorEventListener, LocationListener {
     @Override
     public void onLocationChanged(Location location) {
         mIsLocalised=true;
-        mLongitude=location.getLongitude();
-        mLatitude=location.getLatitude();
-        mAccuracy=location.getAccuracy();
+        if(!USE_GPS_STUB) {
+            mLongitude = location.getLongitude();
+            mLatitude = location.getLatitude();
+            mAccuracy = location.getAccuracy();
+        }
 
         ARActivity.setLocation(new GPSPoint(mLatitude, mLongitude, mAccuracy));
         //Toast.makeText(mParent,  "Longitude: "+location.getLongitude()+ " Latitude: "+location.getLatitude(), Toast.LENGTH_LONG).show();
@@ -195,4 +207,17 @@ public class SensorsManager implements SensorEventListener, LocationListener {
 
     @Override
     public void onProviderDisabled(String s) {}
+
+    public void nextStub()
+    {
+        if(USE_GPS_STUB)
+        {
+            GPSPoint stub = mStub.next();
+            if(stub==null) return;
+            mLongitude=stub.getX();
+            mLatitude=stub.getY();
+            mAccuracy=stub.getAccuracy();
+            ARActivity.setLocation(new GPSPoint(mLatitude, mLongitude, mAccuracy));
+        }
+    }
 }

+ 3 - 2
app/src/main/java/app/brest/utils/SlideBuffer.java

@@ -44,15 +44,16 @@ public class SlideBuffer {
         mHead =0;
     }
 
-    public void enqueue(float val)
+    public void enqueue(float _val)
     {
+        float val = -_val-90;
         mDataSin= mDataSin + COEF*((float)Math.sin(val*Math.PI/180)-mDataSin);
         mDataCos= mDataCos + COEF*((float)Math.cos(val*Math.PI/180)-mDataCos);
     }
 
     public float average()
     {
-        return (float)((Math.atan2(mDataCos, mDataSin))*180/Math.PI)+180f;
+        return (float)( (((Math.atan2(mDataCos, mDataSin))*180/Math.PI)+180f) % 360);
     }
 
 }

+ 2 - 3
app/src/main/java/app/brest/utils/app/brest/game/Game.java

@@ -102,7 +102,6 @@ public class Game  implements Serializable {
     public boolean nextStage()
     {
         mCurrentStage++;
-        Log.e("--_______", "Current="+mCurrentStage+" > total="+mNStages);
         if(mCurrentStage>mNStages) return true;
 
         loadStageAreasResources();
@@ -313,7 +312,8 @@ public class Game  implements Serializable {
             if(b)
             {
 
-                if(i<mCurrentStageAreas.size() && mCurrentStageAreas.get(i).isOnDirection(mPlayer))
+                if(i<mCurrentStageAreas.size() && mCurrentStageAreas.get(i).isOnDirection(mPlayer) &&
+                        mCurrentStageAreas.get(i).isOnPlace(mPlayer))
                 {
                     r.add(new LocatedResource(
                             mResources.getResourceLeftByName(mCurrentStageAreas.get(i).getResourceName()),
@@ -398,7 +398,6 @@ public class Game  implements Serializable {
     }
     public void printNResource(String str)
     {
-        Log.e("_______", str+" : "+mResources.getNResourceAcquired());
     }
 
 

+ 2 - 1
app/src/main/java/app/brest/utils/app/brest/game/Place.java

@@ -105,7 +105,8 @@ public class Place  implements Serializable {
             float pangle=p.getOrientation()%360;
             while (pangle < 0) pangle += 360;
             float dir = (float)p.getPosition().getAngleWith(mLocation);
-
+            Log.e("_____", "Dir="+dir);
+            Log.e("_____", "Pangle="+pangle+"\n");
             double min = dir - mField / 2;
             double max = dir + mField / 2;
             if (min < 0) {

+ 18 - 1
app/src/main/java/app/brest/utils/app/brest/game/Player.java

@@ -68,7 +68,9 @@ public class Player implements Serializable{
 
     public double getAngleWith(Place p)
     {
-        return mSensors.getPosition().getAngleWith(p.getLocation());
+        double d=mSensors.getPosition().getAngleWith(p.getLocation());;
+        while(d<0) d+=360;
+        return d;
     }
 
     public double getXWith(Place p)
@@ -81,8 +83,23 @@ public class Player implements Serializable{
         return mSensors.getPosition().getDistanceYWith(p.getLocation());
     }
 
+    public double getRelXWith(Place p)
+    {
+        return mSensors.getPosition().getRelXWith(p.getLocation());
+    }
+
+    public double getRelYWith(Place p)
+    {
+        return mSensors.getPosition().getRelYWith(p.getLocation());
+    }
+
     public void newSensorManager(Activity act)
     {
         mSensors = new SensorsManager(act);
     }
+
+    public void nextStub()
+    {
+        mSensors.nextStub();
+    }
 }

+ 34 - 1
app/src/main/java/app/brest/utils/geometry/GPSPoint.java

@@ -75,6 +75,11 @@ public class GPSPoint extends app.brest.utils.geometry.Point  implements Seriali
         return getDistanceWith(b);
     }
 
+    public double getRelXWith(GPSPoint _b)
+    {
+        return _b.mX-mX;
+    }
+
 
     public double getDistanceYWith(GPSPoint _b)
     {
@@ -84,9 +89,37 @@ public class GPSPoint extends app.brest.utils.geometry.Point  implements Seriali
         return getDistanceWith(b);
     }
 
+
+
+
+    public double getRelYWith(GPSPoint _b)
+    {
+
+        return _b.mY-mY;
+    }
+
     public double getAngleWith(GPSPoint p)
     {
-        return Math.atan(getDistanceYWith(p)/getDistanceXWith(p))*180/Math.PI;
+        double dx = getRelXWith(p);
+        double dy = getRelYWith(p);
+        if(dy>0) return -Math.atan(dx/dy)*180/Math.PI;
+        else return 180-Math.atan(dx/dy)*180/Math.PI;
     }
+    /*
+            Opposé
+        _________________
+         \               |
+           \             |
+             \           |
+               \         |  Adjacent
+                 \       |
+                   \     |
+                     \ /\|
+                       \ |
+                         \Alpha=Atan(oppose/adjacent)=atan(x/y)
+
+
+
 
+     */
 }

BIN
app/src/main/res/drawable/logo.png


+ 5 - 4
app/src/main/res/layout/activity_main.xml

@@ -70,7 +70,7 @@
                 android:layout_width="match_parent"
                 android:layout_height="60dp"
                 android:maxLines="3"
-                android:lines="3"
+                android:lines="6"
                 android:textAppearance="?android:attr/textAppearanceSmall"
                 android:text="Small Text"
                 android:id="@+id/gps"
@@ -78,9 +78,9 @@
                 android:textColor="#33b5e5"
                 android:visibility="visible"
                 android:layout_alignTop="@+id/text_place"
-                android:layout_alignBottom="@+id/text_place"
                 android:layout_toRightOf="@+id/tv_angle"
-                android:layout_toEndOf="@+id/tv_angle" />
+                android:layout_toEndOf="@+id/tv_angle"
+                android:layout_alignParentBottom="true" />
 
             <TextView
                 android:layout_width="match_parent"
@@ -132,7 +132,8 @@
                 android:id="@+id/iv_skin"
                 android:scaleType="fitCenter"
                 android:background="@drawable/ar_skin"
-                android:visibility="visible" />
+                android:visibility="visible"
+                android:onClick="onStub" />
 
             <TextView
                 android:layout_width="wrap_content"

+ 18 - 18
app/src/main/res/raw/game_medium

@@ -5,20 +5,20 @@
 			"coordinates" : 
 			[
 				[
-					-1.6636830568313599,
-					48.095661163330078
+					-1.6651475429534912,
+					48.095935821533203
 				],
 				[
-					-1.6633397340774536,
-					48.095485687255859
+					-1.664503812789917,
+					48.095809936523438
 				],
 				[
-					-1.6637313365936279,
-					48.095291137695312
+					-1.6644662618637085,
+					48.095439910888672
 				],
 				[
-					-1.6639888286590576,
-					48.095600128173828
+					-1.6652548313140869,
+					48.095649719238281
 				]
 			],
 			"name" : "aaa",
@@ -28,12 +28,12 @@
 					"angle" : 180,
 					"coordinates" : 
 					[
-						-1.6636937856674194,
-						48.095527648925781
+						-1.6648632287979126,
+						48.095737457275391
 					],
 					"field" : 90,
 					"radius" : 10,
-					"useAngle" : true
+					"useAngle" : false
 				}
 			],
 			"resource" : "aaa"
@@ -103,7 +103,7 @@
 					],
 					"field" : 90,
 					"radius" : 10,
-					"useAngle" : true
+					"useAngle" : false
 				}
 			],
 			"resource" : "ccc"
@@ -135,12 +135,12 @@
 					"angle" : 180,
 					"coordinates" : 
 					[
-						-1.663704514503479,
-						48.095550537109375
+						-1.6636615991592407,
+						48.095504760742188
 					],
 					"field" : 90,
 					"radius" : 10,
-					"useAngle" : true
+					"useAngle" : false
 				}
 			],
 			"resource" : "aa"
@@ -177,7 +177,7 @@
 					],
 					"field" : 90,
 					"radius" : 10,
-					"useAngle" : true
+					"useAngle" : false
 				}
 			],
 			"resource" : "bb"
@@ -288,7 +288,7 @@
 					],
 					"field" : 90,
 					"radius" : 10,
-					"useAngle" : true
+					"useAngle" : false
 				}
 			],
 			"resource" : "b"
@@ -325,7 +325,7 @@
 					],
 					"field" : 90,
 					"radius" : 10,
-					"useAngle" : true
+					"useAngle" : false
 				}
 			],
 			"resource" : "c"

+ 2 - 1
app/src/main/res/values/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">Pont Brest</string>
+    <string name="app_name">Mystère à Recouvrance</string>
     <string name="hello_world">Hello world!</string>
     <string name="action_settings">Settings</string>
     <string name="capture_button">Capture Image From Camera</string>
@@ -70,4 +70,5 @@
     <string name="pref_ringtone_silent">Silent</string>
 
     <string name="pref_title_vibrate">Vibrate</string>
+    <string name="gps_stub">-1.6635852 48.0952597;-1.6637062 48.0954137;-1.6637927 48.0955215;-1.6639079 48.0956793;-1.6641270 48.0957178;-1.6642653 48.0956139;-1.6644785 48.0957216;-1.6648474 48.0958025;-1.6649627 48.0958487;-1.6652739 48.0958718;-1.6658446 48.0954599;-1.6658503 48.0947939;-1.6649685 48.0953636;</string>
 </resources>