| |
---|
| | import com.google.ar.core.Plane; |
---|
| | 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; |
---|
| | import com.google.ar.core.examples.java.common.framework.RWT.RWTRenderer; |
---|
| | import com.google.ar.core.examples.java.common.framework.model3D.ModelFactory; |
---|
| | 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; |
---|
| | import com.google.ar.core.examples.java.common.helpers.SnackbarHelper; |
---|
| | 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; |
---|
| | import com.google.ar.core.examples.java.common.rendering.ObjectRenderer.BlendMode; |
---|
| |
---|
| | import com.google.ar.core.exceptions.UnavailableSdkTooOldException; |
---|
| | 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; |
---|
| | |
---|
| | /** |
---|
| |
---|
| | // Rendering. The Renderers are created here, and initialized when the GL surface is created. |
---|
| | private GLSurfaceView surfaceView; |
---|
| | private RWTRenderer renderer; |
---|
| | private Universe universe; |
---|
| | private PhysicalSystem physicalSystem; |
---|
| | private Ground ground = null; |
---|
| | |
---|
| | private boolean installRequested; |
---|
| | |
---|
| | private Session session; |
---|
| |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | private final ArrayList<ColoredAnchor> anchors = new ArrayList<>(); |
---|
| | |
---|
| | private Collection<Plane> placedPlanes = new ArrayList<>(); |
---|
| | |
---|
| | private float ambient = 0.3f; |
---|
| | private float diffuse = 1.0f; |
---|
| | private float specular = 1.0f; |
---|
| |
---|
| | surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); |
---|
| | 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 |
---|
| | protected void onResume() { |
---|
| |
---|
| | |
---|
| | // 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); |
---|
| | |
---|
| | // Keep the screen unlocked while tracking, but allow it to lock when tracking stops. |
---|
| |
---|
| | } else { |
---|
| | messageSnackbarHelper.showMessage(this, SEARCHING_PLANE_MESSAGE); |
---|
| | } |
---|
| | |
---|
| | // // Visualize planes. |
---|
| | // Visualize planes. |
---|
| | Collection<Plane> 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); |
---|
| | // |
---|
| | // Visualize anchors created by touch. |
---|
| |
---|
| | double pz = anchor.anchor.getPose().tz(); |
---|
| | |
---|
| | 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) { |
---|
| | e.printStackTrace(); |
---|
| |
---|
| | |