|
@@ -40,16 +40,21 @@ import min3d.core.Object3dContainer;
|
|
|
import min3d.core.RendererActivity;
|
|
|
import min3d.vos.CameraVo;
|
|
|
import min3d.vos.Light;
|
|
|
+import min3d.vos.LightType;
|
|
|
import min3d.vos.Number3d;
|
|
|
+import min3d.vos.Number3dManaged;
|
|
|
|
|
|
|
|
|
public class ARActivity extends RendererActivity
|
|
|
{
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private CameraPreview mImageSurfaceView;
|
|
|
private Camera camera;
|
|
|
private FrameLayout cameraPreviewLayout;
|
|
|
|
|
|
+
|
|
|
private Object3dContainer faceObject3D;
|
|
|
private Button mOkButton;
|
|
|
private final Object mLock = new Object();
|
|
@@ -131,8 +136,9 @@ public class ARActivity extends RendererActivity
|
|
|
//scene.lights().add(new Light());
|
|
|
|
|
|
Light myLight = new Light();
|
|
|
- myLight.position.setZ(150);
|
|
|
- myLight.position.setY(150);
|
|
|
+ myLight.position.setZ(0);
|
|
|
+ myLight.position.setY(100);
|
|
|
+ myLight.type(LightType.POSITIONAL);
|
|
|
scene.lights().add(myLight);
|
|
|
|
|
|
|
|
@@ -207,17 +213,140 @@ public class ARActivity extends RendererActivity
|
|
|
mInArea=mDetect=false;
|
|
|
}
|
|
|
}
|
|
|
- float x = 0;
|
|
|
+ protected String updateArSceneResource(Resource rr, Place p, String toDisplay)
|
|
|
+ {
|
|
|
+ Object3d oo = rr.get3DModel(this);
|
|
|
+ CameraVo v = new CameraVo();
|
|
|
+
|
|
|
+ if(mGame.getmSettings().isARMode()) {
|
|
|
+ double distCoef = (p.getDistance(mGame.getPlayer()) / 50) * 0.8;
|
|
|
+ distCoef += 0.2;
|
|
|
+ if (distCoef > 1) distCoef = 1.0;
|
|
|
+
|
|
|
+ double theta = -(-mGame.getPlayer().getOrientationY() + 135 - (0.5 * Math.atan(p.getDistance(mGame.getPlayer()) / 1.6) * 180 / Math.PI) % 360);
|
|
|
+ while (theta < -180) theta += 360;
|
|
|
+ while (theta > 180) theta -= 360;
|
|
|
+
|
|
|
+ oo.position().y = -25 + (float) (50 * Math.sin(-theta * Math.PI / 180.0));
|
|
|
+
|
|
|
+ double alpha = ((float) (mGame.getPlayer().getAngleWith(p))-mGame.getPlayer().getOrientationX() );// - mGame.getPlayer().getOrientationZ();
|
|
|
+ oo.position().z = -20;//(float)(90*distCoef*Math.cos(alpha*Math.PI/180.0));
|
|
|
+ oo.position().x = (float) (90 * distCoef * Math.sin(alpha * Math.PI / 180.0));
|
|
|
+
|
|
|
+ if (mGame.getmSettings().isAreaDebug()) {
|
|
|
+
|
|
|
+ toDisplay += "Azimuth: " + dts(alpha) + "°\nAngle:"+mGame.getPlayer().getAngleWith(p) +"\nPosition (" + dts(oo.position().x) + ", " + dts(oo.position().y)
|
|
|
+ + ", " + dts(oo.position().z) + ")\n\n";
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ oo.position().y = 0;
|
|
|
+ oo.position().z = -20;
|
|
|
+ oo.position().x = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //vX = (float) (mGame.getPlayer().getAngleWith(p));
|
|
|
+ scene.camera(v);
|
|
|
+ scene.addChild(oo);
|
|
|
+ return toDisplay;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* protected void updateArSceneResource(Resource rr, Place p, String toDisplay)
|
|
|
+ {
|
|
|
+ Object3d oo = rr.get3DModel(this);
|
|
|
+ CameraVo v = new CameraVo();
|
|
|
+
|
|
|
+ if(mGame.getmSettings().isARMode()) {
|
|
|
+ double distCoef = (p.getDistance(mGame.getPlayer()) / 50) * 0.8;
|
|
|
+ distCoef += 0.2;
|
|
|
+ if (distCoef > 1) distCoef = 1.0;
|
|
|
+
|
|
|
+ double theta = -(-mGame.getPlayer().getOrientationY() + 135 - (0.5 * Math.atan(p.getDistance(mGame.getPlayer()) / 1.6) * 180 / Math.PI) % 360);
|
|
|
+ while (theta < -180) theta += 360;
|
|
|
+ while (theta > 180) theta -= 360;
|
|
|
+
|
|
|
+ oo.position().y = -25 + (float) (50 * Math.sin(-theta * Math.PI / 180.0));
|
|
|
+
|
|
|
+ double alpha = ((float) (mGame.getPlayer().getAngleWith(p) - mGame.getPlayer().getOrientationX())) + mGame.getPlayer().getOrientationZ();
|
|
|
+ oo.position().z = -20;//(float)(90*distCoef*Math.cos(alpha*Math.PI/180.0));
|
|
|
+ oo.position().x = (float) (90 * distCoef * Math.sin(alpha * Math.PI / 180.0));
|
|
|
+
|
|
|
+ if (mGame.getmSettings().isAreaDebug()) {
|
|
|
+
|
|
|
+ toDisplay += "Azimuth: " + dts(alpha) + "°\nPosition (" + dts(oo.position().x) + ", " + dts(oo.position().y)
|
|
|
+ + ", " + dts(oo.position().z) + ")\n\n";
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ oo.position().y = 0;
|
|
|
+ oo.position().z = -20;
|
|
|
+ oo.position().x = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //vX = (float) (mGame.getPlayer().getAngleWith(p));
|
|
|
+ scene.camera(v);
|
|
|
+ scene.addChild(oo);
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ /*protected String updateArSceneResource(Resource rr, Place p, String toDisplay)
|
|
|
+ {
|
|
|
+ Object3d oo = rr.get3DModel(this);
|
|
|
+ CameraVo v = new CameraVo();
|
|
|
+ v.position.z=0;
|
|
|
+ v.position.y=0;
|
|
|
+ v.position.x=0;
|
|
|
+ //l.type(LightType.POSITIONAL);
|
|
|
+
|
|
|
+
|
|
|
+ double distCoef = (p.getDistance(mGame.getPlayer()) / 50) * 0.8;
|
|
|
+ distCoef += 0.2;
|
|
|
+ if (distCoef > 1) distCoef = 1.0;
|
|
|
+
|
|
|
+ double theta = -(-mGame.getPlayer().getOrientationY() + 135 - (0.5 * Math.atan(p.getDistance(mGame.getPlayer()) / 1.6) * 180 / Math.PI) % 360);
|
|
|
+ while (theta < -180) theta += 360;
|
|
|
+ while (theta > 180) theta -= 360;
|
|
|
+
|
|
|
+ oo.position().y = -25 + (float) (50 * Math.sin(-theta * Math.PI / 180.0));
|
|
|
+
|
|
|
+ double alpha = ((float) (mGame.getPlayer().getAngleWith(p) - mGame.getPlayer().getOrientationX())) - mGame.getPlayer().getOrientationZ();
|
|
|
+ oo.position().z = -20;//(float)(90*distCoef*Math.cos(alpha*Math.PI/180.0));
|
|
|
+ oo.position().x = -(float) (90 * distCoef * Math.sin(alpha * Math.PI / 180.0));
|
|
|
+
|
|
|
+ oo.position().x=(float)(150 * distCoef * Math.sin(mGame.getPlayer().getAngleWith(p) * Math.PI / 180.0));
|
|
|
+ oo.position().y=-20;
|
|
|
+ oo.position().z=(float)(150 * distCoef * Math.cos(mGame.getPlayer().getAngleWith(p) * Math.PI / 180.0));
|
|
|
+
|
|
|
+ v.target.x=(float) (45 * distCoef * Math.sin(mGame.getPlayer().getOrientationX() * Math.PI / 180.0));
|
|
|
+ v.target.z=(float) (45 * distCoef * Math.cos(mGame.getPlayer().getOrientationX() * Math.PI / 180.0));
|
|
|
+ v.target.y=-(float) (20 * Math.cos(mGame.getPlayer().getOrientationY() * Math.PI / 180.0));
|
|
|
+ oo.rotation().x=90-mGame.getPlayer().getOrientationY();
|
|
|
+
|
|
|
+
|
|
|
+ if (mGame.getmSettings().isAreaDebug()) {
|
|
|
+
|
|
|
+ toDisplay += "Azimuth: " + dts(alpha) + "°\nPosition (" + dts(oo.position().x) + ", " + dts(oo.position().y)
|
|
|
+ + ", " + dts(oo.position().z) + ")\n\n";
|
|
|
+ toDisplay+="Target ("+v.target.x+", "+v.target.y+", "+v.target.z+")\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ //vX = (float) (mGame.getPlayer().getAngleWith(p));
|
|
|
+ scene.camera(v);
|
|
|
+ scene.addChild(oo);
|
|
|
+ return toDisplay;
|
|
|
+ }*/
|
|
|
+
|
|
|
protected boolean updateSceneResource()
|
|
|
{
|
|
|
|
|
|
ArrayList<LocatedResources> res = mGame.getResourcesNextToPlayer();
|
|
|
String toDisplay ="";
|
|
|
- float vX =0;
|
|
|
boolean detected = false;
|
|
|
+ boolean isAR = mGame.getmSettings().isARMode();
|
|
|
// String dete = "Detected:\n";
|
|
|
scene.clear();
|
|
|
|
|
|
+
|
|
|
if(mGame.getmSettings().isAreaDebug())
|
|
|
{
|
|
|
ArrayList<Area> ar = mGame.getAreaNextToPlayer();
|
|
@@ -230,40 +359,17 @@ public class ARActivity extends RendererActivity
|
|
|
|
|
|
if(mGame.getmSettings().isAreaDebug()) toDisplay+="Resources détectées: \n";
|
|
|
|
|
|
- if(mGame.getmSettings().isARMode()) {
|
|
|
- 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;
|
|
|
- Object3d oo = rr.get3DModel(this);
|
|
|
- CameraVo v = new CameraVo();
|
|
|
- double distCoef = (p.getDistance(mGame.getPlayer()) / 50) * 0.8;
|
|
|
- distCoef += 0.2;
|
|
|
- if (distCoef > 1) distCoef = 1.0;
|
|
|
-
|
|
|
- double theta = -(-mGame.getPlayer().getOrientationY() + 135 - (0.5 * Math.atan(p.getDistance(mGame.getPlayer()) / 1.6) * 180 / Math.PI) % 360);
|
|
|
- while (theta < -180) theta += 360;
|
|
|
- while (theta > 180) theta -= 360;
|
|
|
-
|
|
|
- oo.position().y = -25 + (float) (50 * Math.sin(-theta * Math.PI / 180.0));
|
|
|
-
|
|
|
- double alpha = ((float) (mGame.getPlayer().getAngleWith(p) - mGame.getPlayer().getOrientationX())) - mGame.getPlayer().getOrientationZ();
|
|
|
- oo.position().z = -20;//(float)(90*distCoef*Math.cos(alpha*Math.PI/180.0));
|
|
|
- oo.position().x = -(float) (90 * distCoef * Math.sin(alpha * Math.PI / 180.0));
|
|
|
-
|
|
|
- if (mGame.getmSettings().isAreaDebug()) {
|
|
|
-
|
|
|
- toDisplay += "Azimuth: " + dts(alpha) + "°\nPosition (" + dts(oo.position().x) + ", " + dts(oo.position().y)
|
|
|
- + ", " + dts(oo.position().z) + ")\n\n";
|
|
|
- }
|
|
|
-
|
|
|
- vX = (float) (mGame.getPlayer().getAngleWith(p));
|
|
|
- scene.camera(v);
|
|
|
- scene.addChild(oo);
|
|
|
- }
|
|
|
+ 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();
|
|
|
+
|
|
|
updateLed(detected, mGame.getResourcesNextToPlayerDistDouble());
|
|
|
|
|
|
|
|
@@ -282,8 +388,10 @@ public class ARActivity extends RendererActivity
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
- return scene.numChildren()>0;
|
|
|
+ if(mGame.getmSettings().isARMode())
|
|
|
+ return scene.numChildren()>0;
|
|
|
+ else
|
|
|
+ return res.size()>0;
|
|
|
}
|
|
|
|
|
|
protected void onList()
|
|
@@ -330,7 +438,7 @@ public class ARActivity extends RendererActivity
|
|
|
int w =mViewWidth = mRlRoot.getMeasuredWidth();
|
|
|
int h =mViewHeight = mRlRoot.getMeasuredHeight();
|
|
|
|
|
|
- mTvGPS.setTextSize(pxToDp((int)(h*0.121f/3.5)));
|
|
|
+ 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)));
|
|
@@ -367,6 +475,8 @@ public class ARActivity extends RendererActivity
|
|
|
{
|
|
|
if(!mUpdate) return;
|
|
|
boolean isResource = false;
|
|
|
+
|
|
|
+ //Precache du modèle 3D
|
|
|
synchronized (mLock) {
|
|
|
if (!isPausing) {
|
|
|
boolean b = mGame.precache3DResource(this);
|