diff --git a/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java b/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java index 80e10bd..f55bac4 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java +++ b/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java @@ -32,6 +32,7 @@ import com.google.ar.core.Point; import com.google.ar.core.Point.OrientationMode; import com.google.ar.core.PointCloud; +import com.google.ar.core.Pose; import com.google.ar.core.Session; import com.google.ar.core.Trackable; import com.google.ar.core.TrackingState; @@ -40,7 +41,13 @@ import com.google.ar.core.examples.java.common.framework.model3D.ModelFileFormatException; import com.google.ar.core.examples.java.common.framework.model3D.Object3D; import com.google.ar.core.examples.java.common.framework.model3D.Position3D; +import com.google.ar.core.examples.java.common.framework.model3D.Quaternion3D; import com.google.ar.core.examples.java.common.framework.model3D.Universe; +import com.google.ar.core.examples.java.common.framework.physics.AngularVelocity3D; +import com.google.ar.core.examples.java.common.framework.physics.Force3D; +import com.google.ar.core.examples.java.common.framework.physics.Ground; +import com.google.ar.core.examples.java.common.framework.physics.PhysicalSystem; +import com.google.ar.core.examples.java.common.framework.physics.Solid3D; import com.google.ar.core.examples.java.common.helpers.CameraPermissionHelper; import com.google.ar.core.examples.java.common.helpers.DisplayRotationHelper; import com.google.ar.core.examples.java.common.helpers.FullScreenHelper; @@ -48,6 +55,7 @@ import com.google.ar.core.examples.java.common.helpers.TapHelper; import com.google.ar.core.examples.java.common.helpers.TrackingStateHelper; import com.google.ar.core.examples.java.common.java3d.Appearance; +import com.google.ar.core.examples.java.common.java3d.Box; import com.google.ar.core.examples.java.common.java3d.Material; import com.google.ar.core.examples.java.common.rendering.BackgroundRenderer; import com.google.ar.core.examples.java.common.rendering.ObjectRenderer; @@ -62,6 +70,8 @@ import com.google.ar.core.exceptions.UnavailableUserDeclinedInstallationException; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; + import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -77,6 +87,8 @@ private GLSurfaceView surfaceView; private RWTRenderer renderer; private Universe universe; + private PhysicalSystem physicalSystem; + private Ground ground = null; private boolean installRequested; @@ -111,6 +123,8 @@ private final ArrayList anchors = new ArrayList<>(); + private Collection placedPlanes = new ArrayList<>(); + private float ambient = 0.3f; private float diffuse = 1.0f; private float specular = 1.0f; @@ -140,15 +154,18 @@ surfaceView.setWillNotDraw(false); installRequested = false; - try { - Object3D andy = ModelFactory.loadModel(getResources(), "models/andy.obj", null).createObject(); - andy.setPosition(new Position3D(0.0, 0.0, -1.0)); - universe.place(andy); - } catch (IOException e) { - e.printStackTrace(); - } catch (ModelFileFormatException e) { - e.printStackTrace(); - } + + // For Radish + physicalSystem = new PhysicalSystem(); +// try { +// Object3D andy = ModelFactory.loadModel(getResources(), "models/andy.obj", null).createObject(); +// andy.setPosition(new Position3D(0.0, 0.0, -1.0)); +// universe.place(andy); +// } catch (IOException e) { +// e.printStackTrace(); +// } catch (ModelFileFormatException e) { +// e.printStackTrace(); +// } } @Override @@ -299,6 +316,11 @@ // Handle one tap per frame. handleTap(frame, camera); + // Physics + if (physicalSystem.objects.size() > 0) { + physicalSystem.motion(0, 1, Force3D.ZERO, physicalSystem.objects.get(0).getGravityCenter(), ground); + } + // If frame is ready, render camera preview image to the GL surface. // backgroundRenderer.draw(frame); @@ -340,7 +362,23 @@ messageSnackbarHelper.showMessage(this, SEARCHING_PLANE_MESSAGE); } -// // Visualize planes. + // Visualize planes. + Collection currentPlanes = session.getAllTrackables(Plane.class); + for (Plane plane : currentPlanes) { + if (!placedPlanes.contains(plane)) { + placedPlanes.add(plane); + Box rect = new Box(plane.getExtentX() / 2, 0.1f, plane.getExtentZ() / 2, null); + Object3D rectObj = new Object3D("plane", rect); + Pose p = plane.getCenterPose(); + rectObj.apply(new Position3D(p.tx(), p.ty(), p.tz()), false); + rectObj.apply(new Quaternion3D((double)p.qx(), (double)p.qy(), (double)p.qz(), (double)p.qw()), false); + if (ground == null) { + ground = new Ground(rectObj); + universe.place(ground); + } + } + } + // planeRenderer.drawPlanes( // session.getAllTrackables(Plane.class), camera.getDisplayOrientedPose(), projmtx); // @@ -414,8 +452,10 @@ try { Object3D andy = ModelFactory.loadModel(getResources(), "models/andy.obj", null).createObject(); - andy.setPosition(new Position3D(px, py, pz)); - universe.place(andy); + andy.setPosition(new Position3D(px, py + 0.2, pz)); + Solid3D andyObj = new Solid3D(andy); + universe.place(andyObj); + physicalSystem.add(andyObj); } catch (IOException e) { e.printStackTrace(); } catch (ModelFileFormatException e) {