| |
---|
| | messageSnackbarHelper.showMessage(this, SEARCHING_PLANE_MESSAGE); |
---|
| | } |
---|
| | |
---|
| | // Visualize planes. |
---|
| | Collection<Plane> updatedPlanes = frame.getUpdatedTrackables(Plane.class); |
---|
| | for (Plane plane : updatedPlanes) { |
---|
| | if (placedPlane == null) { |
---|
| | placedPlane = plane; |
---|
| | Appearance ap = new Appearance(); |
---|
| | ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f)); |
---|
| | FloatBuffer vertices = plane.getPolygon(); |
---|
| | vertices.position(0); |
---|
| | TriangleFanArray polygon = new TriangleFanArray(vertices.remaining() / 2, TriangleArray.COORDINATES, new int[]{vertices.remaining() / 2}); |
---|
| | for (int i = 0; i < vertices.remaining() / 2; i++) { |
---|
| | polygon.setCoordinate(i, new float[]{vertices.get(i * 2), 0.0f, vertices.get(i * 2 + 1)}); |
---|
| | } |
---|
| | polyObj = new Object3D("plane", new Shape3D(polygon, ap)); |
---|
| | Pose p = plane.getCenterPose(); |
---|
| | polyObj.apply(new Position3D(p.tx(), p.ty(), p.tz()), false); |
---|
| | polyObj.apply(new Quaternion3D((double) p.qx(), (double) p.qy(), (double) p.qz(), (double) p.qw()), false); |
---|
| | ground = new Ground(polyObj); |
---|
| | universe.place(ground); |
---|
| | } else if (plane.equals(placedPlane)) { |
---|
| | Appearance ap = new Appearance(); |
---|
| | ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f)); |
---|
| | FloatBuffer vertices = plane.getPolygon(); |
---|
| | vertices.position(0); |
---|
| | TriangleFanArray polygon = new TriangleFanArray(vertices.remaining() / 2, TriangleArray.COORDINATES, new int[]{vertices.remaining() / 2}); |
---|
| | for (int i = 0; i < vertices.remaining() / 2; i++) { |
---|
| | polygon.setCoordinate(i, new float[]{vertices.get(i * 2), 0.0f, vertices.get(i * 2 + 1)}); |
---|
| | } |
---|
| | polyObj = new Object3D("plane", new Shape3D(polygon, ap)); |
---|
| | Pose p = plane.getCenterPose(); |
---|
| | polyObj.apply(new Position3D(p.tx(), p.ty(), p.tz()), false); |
---|
| | polyObj.apply(new Quaternion3D((double) p.qx(), (double) p.qy(), (double) p.qz(), (double) p.qw()), false); |
---|
| | universe.displace(ground); |
---|
| | ground = new Ground(polyObj); |
---|
| | universe.place(ground); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | ///////////////////////////////////////////////////////////////////////////////////// |
---|
| | // 以下は複数検出面に対応したコードだが、検出面が2個以上になるとちゃんと動かない? |
---|
| | // |
---|
| | // Collection<Plane> updatedPlanes = frame.getUpdatedTrackables(Plane.class); |
---|
| | // if (updatedPlanes != null && updatedPlanes.size() > 0) { |
---|
| | // if (ground != null) universe.displace(ground); |
---|
| | // Object3D polygons[] = new Object3D[updatedPlanes.size()]; |
---|
| | // int i = 0; |
---|
| | // for (Plane plane : updatedPlanes) { |
---|
| | // for (Plane plane : updatedPlanes) { |
---|
| | // if (placedPlane == null) { |
---|
| | // placedPlane = plane; |
---|
| | // Appearance ap = new Appearance(); |
---|
| | // ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f)); |
---|
| | // FloatBuffer vertices = plane.getPolygon(); |
---|
| | // vertices.position(0); |
---|
| | // TriangleFanArray polygon = new TriangleFanArray(vertices.remaining() / 2, TriangleArray.COORDINATES, new int[]{vertices.remaining() / 2}); |
---|
| | // for (int j = 0; j < vertices.remaining() / 2; j++) { |
---|
| | // polygon.setCoordinate(j, new float[]{vertices.get(j * 2), 0.0f, vertices.get(j * 2 + 1)}); |
---|
| | // for (int i = 0; i < vertices.remaining() / 2; i++) { |
---|
| | // polygon.setCoordinate(i, new float[]{vertices.get(i * 2), 0.0f, vertices.get(i * 2 + 1)}); |
---|
| | // } |
---|
| | // Object3D polyObj = new Object3D("plane" + i, new Shape3D(polygon, ap)); |
---|
| | // polyObj = new Object3D("plane", new Shape3D(polygon, ap)); |
---|
| | // Pose p = plane.getCenterPose(); |
---|
| | // polyObj.apply(new Position3D(p.tx(), p.ty(), p.tz()), false); |
---|
| | // polyObj.apply(new Quaternion3D((double) p.qx(), (double) p.qy(), (double) p.qz(), (double) p.qw()), false); |
---|
| | // polygons[i] = polyObj; |
---|
| | // i++; |
---|
| | // ground = new Ground(polyObj); |
---|
| | // universe.place(ground); |
---|
| | // } else if (plane.equals(placedPlane)) { |
---|
| | // Appearance ap = new Appearance(); |
---|
| | // ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f)); |
---|
| | // FloatBuffer vertices = plane.getPolygon(); |
---|
| | // vertices.position(0); |
---|
| | // TriangleFanArray polygon = new TriangleFanArray(vertices.remaining() / 2, TriangleArray.COORDINATES, new int[]{vertices.remaining() / 2}); |
---|
| | // for (int i = 0; i < vertices.remaining() / 2; i++) { |
---|
| | // polygon.setCoordinate(i, new float[]{vertices.get(i * 2), 0.0f, vertices.get(i * 2 + 1)}); |
---|
| | // } |
---|
| | // polyObj = new Object3D("plane", new Shape3D(polygon, ap)); |
---|
| | // Pose p = plane.getCenterPose(); |
---|
| | // polyObj.apply(new Position3D(p.tx(), p.ty(), p.tz()), false); |
---|
| | // polyObj.apply(new Quaternion3D((double) p.qx(), (double) p.qy(), (double) p.qz(), (double) p.qw()), false); |
---|
| | // universe.displace(ground); |
---|
| | // ground = new Ground(polyObj); |
---|
| | // universe.place(ground); |
---|
| | // } |
---|
| | // ground = new Ground(new Object3D("ground", polygons)); |
---|
| | // universe.place(ground); |
---|
| | // } |
---|
| | |
---|
| | ///////////////////////////////////////////////////////////////////////////////////// |
---|
| | // 以下は複数検出面に対応したコードだが、検出面が2個以上になるとちゃんと動かない? |
---|
| | // |
---|
| | Collection<Plane> updatedPlanes = frame.getUpdatedTrackables(Plane.class); |
---|
| | if (updatedPlanes != null && updatedPlanes.size() > 0) { |
---|
| | if (ground != null) universe.displace(ground); |
---|
| | ArrayList<Object3D> polygons = new ArrayList<>(); |
---|
| | for (Plane plane : updatedPlanes) { |
---|
| | if (plane.getSubsumedBy() == null) { |
---|
| | Appearance ap = new Appearance(); |
---|
| | ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f)); |
---|
| | FloatBuffer vertices = plane.getPolygon(); |
---|
| | vertices.position(0); |
---|
| | TriangleFanArray polygon = new TriangleFanArray(vertices.remaining() / 2, TriangleArray.COORDINATES, new int[]{vertices.remaining() / 2}); |
---|
| | for (int j = 0; j < vertices.remaining() / 2; j++) { |
---|
| | polygon.setCoordinate(j, new float[]{vertices.get(j * 2), 0.0f, vertices.get(j * 2 + 1)}); |
---|
| | } |
---|
| | Object3D polyObj = new Object3D("plane" + (polygons.size() + 1), new Shape3D(polygon, ap)); |
---|
| | Pose p = plane.getCenterPose(); |
---|
| | polyObj.apply(new Position3D(p.tx(), p.ty(), p.tz()), false); |
---|
| | polyObj.apply(new Quaternion3D((double) p.qx(), (double) p.qy(), (double) p.qz(), (double) p.qw()), false); |
---|
| | polygons.add(polyObj); |
---|
| | } |
---|
| | } |
---|
| | ground = new Ground(new Object3D("ground", polygons.toArray(new Object3D[]{}))); |
---|
| | universe.place(ground); |
---|
| | } |
---|
| | ///////////////////////////////////////////////////////////////////////////////////// |
---|
| | |
---|
| | |
---|
| | // planeRenderer.drawPlanes( |
---|
| |
---|
| | |