public FindClosestPoint ( Camera cam, Vector2 pos, int maxDist ) : int | ||
cam | Camera | The current camera. |
pos | Vector2 | Position on screen (in pixels). |
maxDist | int | The maximum pixel distance to allow. |
Résultat | int |
/// <summary> /// Wait for the next depth update, then find the nearest point in the point /// cloud. /// </summary> /// <param name="touchPosition">Touch position on the screen.</param> /// <returns>Coroutine IEnumerator.</returns> private IEnumerator _WaitForDepth(Vector2 touchPosition) { m_waitingForDepth = true; // Turn on the camera and wait for a single depth update m_tangoApplication.SetDepthCameraRate( TangoEnums.TangoDepthCameraRate.MAXIMUM); while (m_waitingForDepth) { yield return(null); } m_tangoApplication.SetDepthCameraRate( TangoEnums.TangoDepthCameraRate.DISABLED); Camera cam = Camera.main; int pointIndex = m_pointCloud.FindClosestPoint(cam, touchPosition, 10); if (pointIndex > -1) { // Index is valid m_startPoint = m_endPoint; m_endPoint = m_pointCloud.m_points[pointIndex]; m_distance = Vector3.Distance(m_startPoint, m_endPoint); } }
void placeObject(Vector2 touchPosition, int k) { // Find the plane. Camera cam = Camera.main; Vector3 planeCenter; Plane plane; int index = m_pointCloud.FindClosestPoint(cam, touchPosition, 30); // if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane)) // { // Debug.Log("cannot find plane."); // return; // } // if (index == -1) { print("cannot find surface"); return; } //m_Index.text = "Index at " + m_pointCloud.m_points [index]; Vector3 pointIndex = m_pointCloud.m_points [index]; GameObject marker = Instantiate(m_marker, pointIndex, Quaternion.identity); m_Index.text = "d: " + marker.transform.position; marker.transform.parent = markersObj.transform; marker.tag = tags[k]; markers.Add(marker); if (k < 5) { setMindMapReferenceColor(k + 1); } }
/// <summary> /// Wait for the next depth update, then find the nearest edge in the point /// cloud. /// </summary> /// <param name="touchPosition">Touch position on the screen.</param> /// <returns>Coroutine IEnumerator.</returns> private IEnumerator _WaitForDepth(Vector2 touchPosition) { m_waitingForDepth = true; // Turn on the camera and wait for a single depth update m_tangoApplication.SetDepthCameraRate( TangoEnums.TangoDepthCameraRate.MAXIMUM); while (m_waitingForDepth) { yield return(null); } m_tangoApplication.SetDepthCameraRate( TangoEnums.TangoDepthCameraRate.DISABLED); m_camera = Camera.main; int pointIndex = m_pointCloud.FindClosestPoint(m_camera, touchPosition, 10); if (pointIndex > -1) { m_currTouch = m_pointCloud.m_points[pointIndex]; //_RenderCustomize(m_currTouch, new Vector3(m_currTouch[0] + 0.005f, m_currTouch[1], m_currTouch[2])); Debug.Log("<<<<<<<<<<<<<<<< mouse position: " + m_currTouch[0] + ", " + m_currTouch[1] + ", " + m_currTouch[2]); } TangoSupport.TangoSupportEdge[] edges; int num_edges; bool edgeResult = m_pointCloud.FindEdges(m_imagebuffer, m_camera, touchPosition, out edges, out num_edges); Debug.Log("<<<<<<<<<<< Edge result: " + edgeResult); if (edgeResult == true) { m_edgeCount = num_edges; m_startPoint = new Vector3[num_edges]; m_endPoint = new Vector3[num_edges]; m_nearestPoint = new Vector3[num_edges]; for (int i = 0; i < num_edges; i++) { Debug.Log("<<<<<<<<< starting point's x: " + edges[i].end_points_x1); m_startPoint[i] = new Vector3(edges[i].end_points_x1, edges[i].end_points_y1, edges[i].end_points_z1); Debug.Log("<<<<<<<<<< " + m_startPoint[i][0] + ", " + m_startPoint[i][1] + ", " + m_startPoint[i][2]); m_endPoint[i] = new Vector3(edges[i].end_points_x2, edges[i].end_points_y2, edges[i].end_points_z2); Debug.Log("<<<<<<<<<< " + m_endPoint[i][0] + ", " + m_endPoint[i][1] + ", " + m_endPoint[i][2]); m_nearestPoint[i] = new Vector3(edges[i].closest_point_on_edge_x, edges[i].closest_point_on_edge_y, edges[i].closest_point_on_edge_z); Debug.Log("<<<<<<<<<< " + m_nearestPoint[i][0] + ", " + m_nearestPoint[i][1] + ", " + m_nearestPoint[i][2]); } _RenderLine(); } }
// Free hand drawing -begin public void DrawOnScreenFunction() { if (Input.touchCount == 1) { Touch Pen = Input.GetTouch(0); Vector2 guiPosition = new Vector2(Pen.position.x, Screen.height - Pen.position.y); Camera cam = Camera.main; if (showTextArea.Contains(guiPosition) || buttonArea.Contains(guiPosition)) { return; } int closestIndex = m_pointCloud.FindClosestPoint(cam, Pen.position, TAP_PIXEL_TOLERANCE); if (closestIndex < 0) { return; } float closestDepth = cam.WorldToScreenPoint(m_pointCloud.m_points [closestIndex]).z; Ray touchRay = cam.ScreenPointToRay(new Vector3(Pen.position [0], Pen.position [1], 0)); penDrawPos0 = touchRay.origin + (touchRay.direction * closestDepth); if (Pen.phase == TouchPhase.Moved) { penDrawPos.Add(penDrawPos0); if (penDrawPos.Count >= 2) { Vector3 penPos1 = penDrawPos[penDrawPos.Count - 1]; Vector3 penPos2 = penDrawPos[penDrawPos.Count - 2]; GameObject lineMaterial = (GameObject)Instantiate(GameObject.Find("Line")); var lineRendered = lineMaterial.GetComponent <LineRenderer> (); lineRendered.SetPosition(0, penPos1); lineRendered.SetPosition(1, penPos2); penDraw.Add(lineMaterial); } } } else { penDrawPos.Clear(); } }
void Update() { if (Input.touchCount > 0) { var touch = Input.GetTouch(0); var indexOfClosestPoint = tangoPointCloud.FindClosestPoint(Camera.main, touch.position, 500); // Returns -1 if not found if (indexOfClosestPoint != -1) { var closestPoint = tangoPointCloud.m_points [indexOfClosestPoint]; var showDragLine = MainMenuController.GetEdgeDetectionMode() == "DRAG"; if (!_hasStartPoint) { _hasStartPoint = true; _firstCorner = closestPoint; if (showDragLine) { StartLine(closestPoint); } } _oppositeCorner = closestPoint; if (showDragLine) { ExtendLine(closestPoint); } } if (touch.phase == TouchPhase.Stationary) { _stationaryCount++; } if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled || _stationaryCount > 100) { _stationaryCount = 0; line.SetActive(false); if (_hasStartPoint) { _hasStartPoint = false; HandleTouch(touch.position); } } } }
/// <summary> /// Updates the active placed location. /// </summary> private void _UpdatePlacedLocation() { if (Input.touchCount != 1) { return; } Touch t = Input.GetTouch(0); if (t.phase != TouchPhase.Began) { return; } Camera cam = m_arScreen.m_renderCamera; int closestIndex = m_pointCloud.FindClosestPoint(cam, t.position, TAP_PIXEL_TOLERANCE); if (closestIndex < 0) { return; } if (m_placedLocation) { m_placedLocation.SendMessage("Hide"); } float closestDepth = cam.WorldToScreenPoint(m_pointCloud.m_points[closestIndex]).z; Ray touchRay = cam.ScreenPointToRay(new Vector3(t.position[0], t.position[1], 0)); Vector3 pos = touchRay.origin + (touchRay.direction * closestDepth); Vector3 rot = cam.transform.eulerAngles; rot[0] = rot[2] = 0; m_placedLocation = (GameObject)Instantiate(m_prefabLocation, pos, Quaternion.Euler(rot)); }
/// <summary> /// Wait for the next depth update, then find the nearest point in the point /// cloud. /// </summary> /// <param name="touchPosition">Touch position on the screen.</param> /// <returns>Coroutine IEnumerator.</returns> private IEnumerator _WaitForDepth(Vector2 touchPosition) { m_waitingForDepth = true; // Turn on the camera and wait for a single depth update m_tangoApplication.SetDepthCameraRate( TangoEnums.TangoDepthCameraRate.MAXIMUM); while (m_waitingForDepth) { yield return(null); } m_tangoApplication.SetDepthCameraRate( TangoEnums.TangoDepthCameraRate.DISABLED); Camera cam = Camera.main; int pointIndex = m_pointCloud.FindClosestPoint(cam, touchPosition, 10); if (pointIndex > -1) { // Index is valid if (screenTaps == 0) { m_point0 = m_pointCloud.m_points [pointIndex]; Debug.Log(m_point0); } else if (screenTaps == 1) { m_point1 = m_pointCloud.m_points [pointIndex]; Debug.Log(m_point1); } else if (screenTaps == 2) { m_point2 = m_pointCloud.m_points [pointIndex]; Debug.Log(m_point2); } else { m_point3 = m_pointCloud.m_points [pointIndex]; Debug.Log(m_point3); m_distance23 = Vector3.Distance(m_point2, m_point3); createCube(m_point0, m_distance01, m_distance23, m_distance12); } } // m_startPoint = m_endPoint; // m_point1 = m_pointCloud.m_points [pointIndex]; // m_endPoint = m_pointCloud.m_points[pointIndex]; m_distance12 = Vector3.Distance(m_point1, m_point2); m_distance01 = Vector3.Distance(m_point0, m_point1); // m_distance34 = Vector3.Distance(m_point3, m_point4); screenTaps = screenTaps + 1; Debug.Log(screenTaps); // insertModel (m_point0, "modern_armchair"); }
/// <summary> /// Wait for the next depth update, then find the plane at the touch position. /// </summary> /// <returns>Coroutine IEnumerator.</returns> /// <param name="touchPosition">Touch position to find a plane at.</param> /// <param name="doorCorridorPosition">Door position where to put the door marker.</param> /// <param name="wall">Touch position to find a plane at.</param> /// <param name="doorCorridorBool">True if we are putting a door marker.</param> private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition, Vector3 doorCorridorPosition = new Vector3(), Wall wall = null, bool doorCorridorBool = false) { if (!doorCorridorBool) { if (m_currentMarkType == 1 || m_currentMarkType == 2) { AndroidHelper.ShowAndroidToastMessage("Door or corridors must be on walls"); yield break; } } m_findPlaneWaitingForDepth = true; // Turn on the camera and wait for a single depth update. m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM); while (m_findPlaneWaitingForDepth) { yield return(null); } m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED); // Find the plane. Camera cam = Camera.main; Vector3 planeCenter; Plane plane; // If I'm selecting the floor, set the floor plane if (m_currentMarkType == 3) { if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane)) { yield break; } m_pointCloud.FindFloor(); floor = new Floor(plane, planeCenter); Debug.Log("Height of the floor " + planeCenter.y); AndroidHelper.ShowAndroidToastMessage("Floor found!"); yield break; } else if (!m_pointCloud.m_floorFound) { AndroidHelper.ShowAndroidToastMessage("Please, select first the floor"); yield break; } // Find me the point I touched on screen on world coordinates if I'm not putting a door... if (!doorCorridorBool) { int i = m_pointCloud.FindClosestPoint(cam, touchPosition, 10); if (i < 0) { yield break; } planeCenter = m_pointCloud.m_points [i]; // Put the marker on the floor height planeCenter.y = floor.floorCenter.y; } //... else my door position is already set as parameter. else { planeCenter = doorCorridorPosition; } // Ensure the location is always facing the camera. This is like a LookRotation, but for the Y axis. Vector3 up = floor.floorPlane.normal; Vector3 forward; if (Vector3.Angle(floor.floorPlane.normal, cam.transform.forward) < 175) { Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized; forward = Vector3.Cross(right, up).normalized; } else { // Normal is nearly parallel to camera look direction, the cross product would have too much // floating point error in it. forward = Vector3.Cross(up, cam.transform.right); } // Instantiate marker object. newMarkObject = Instantiate(m_markPrefabs [m_currentMarkType], planeCenter, Quaternion.LookRotation(forward, up)) as GameObject; newMarkObject.tag = "CornersAndWalls"; ARMarker markerScript = newMarkObject.GetComponent <ARMarker> (); markerScript.m_type = m_currentMarkType; markerScript.m_timestamp = (float)m_poseController.LastPoseTimestamp; Matrix4x4 uwTDevice = Matrix4x4.TRS(m_poseController.transform.position, m_poseController.transform.rotation, Vector3.one); Matrix4x4 uwTMarker = Matrix4x4.TRS(newMarkObject.transform.position, newMarkObject.transform.rotation, Vector3.one); markerScript.m_deviceTMarker = Matrix4x4.Inverse(uwTDevice) * uwTMarker; m_markerList.Add(newMarkObject); prevTouchPos = null; selectedLine = null; m_selectedMarker = null; switch (m_currentMarkType) { // Corner case. case 0: corners.Add(new Corner(newMarkObject)); break; // Door case. case 1: TouchScreenKeyboard kb = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, false, false, "Write the name for this destination marker"); while (!kb.done && !kb.wasCanceled) { yield return(null); } newMarkObject.name = kb.text; doors.Add(new Corner(newMarkObject, wall)); break; default: Debug.Log("No valid point inserted."); break; } }