void MovePlane(Touch touch) { ARHitTestResult arHit = new ARHitTestResult(); if (DoARRaycast(touch, ref arHit)) { var hitPosition = UnityARMatrixOps.GetPosition(arHit.worldTransform); if (m_ARHit.anchorIdentifier != arHit.anchorIdentifier) { // This means we've hit a different plane, so move to it immediately transform.position = hitPosition; } else { // Calculate the difference var lastPosition = UnityARMatrixOps.GetPosition(m_ARHit.worldTransform); var delta = hitPosition - lastPosition; transform.position += delta; } m_ARHit = arHit; } }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); // spawn Portal GameObject newPortal = Instantiate(portalPrefab); newPortal.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); newPortal.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); portalAnim = newPortal.GetComponent <Animator>(); // spawn Fractal GameObject newFractal = Instantiate(fractalPrefab); newFractal.transform.position = newPortal.transform.position; newFractal.transform.rotation = newPortal.transform.rotation; fractalAnim = newFractal.GetComponent <Animator>(); /* * m_HitTransform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform); * m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform); * Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); */ return(true); } } return(false); }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { if (_isPlaneisPlaced) { return(false); } List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); _gameContent.SetActive(true); _isPlaneisPlaced = true; _ARCameraManager.TurnOffPlaneDetection(); return(true); } } return(false); }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultType) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultType); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got Hit!"); var position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); var rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); switch (objectMode) { case ObjectMode.INV: if (m_ARKitProjectUI.GetGameObjectPressed() == null) { GameObject invisibleWall = (GameObject)Instantiate(invisibleWall_prefab); m_invisibleWallPlacement = invisibleWall.GetComponent <ObjectPlacement>(); m_invisibleWallPlacement.placeObject(position, rotation); } break; case ObjectMode.DEL: GameObject gameObjectDel = m_ARKitProjectUI.GetGameObjectPressed(); if (gameObjectDel != null) { Destroy(gameObjectDel); } break; case ObjectMode.OB1: if (object1_duplicate == true) { if (m_ARKitProjectUI.GetGameObjectPressed() == null) { GameObject object1 = (GameObject)Instantiate(object1_prefab); m_object1Placement = object1.GetComponent <ObjectPlacement>(); m_object1Placement.placeObject(position, rotation); } } else { GameObject object1 = GameObject.FindWithTag("object1"); if (object1 == null) { object1 = (GameObject)Instantiate(object1_prefab); object1.tag = "object1"; m_object1Placement = object1.GetComponent <ObjectPlacement>(); m_object1Placement.placeObject(position, rotation); } else { m_object1Placement = object1.GetComponent <ObjectPlacement>(); m_object1Placement.placeObject(position, rotation); } } break; case ObjectMode.OB2: if (object2_duplicate == true) { if (m_ARKitProjectUI.GetGameObjectPressed() == null) { GameObject object2 = (GameObject)Instantiate(object2_prefab); m_object2Placement = object2.GetComponent <ObjectPlacement>(); m_object2Placement.placeObject(position, rotation); } } else { GameObject object2 = GameObject.FindWithTag("object2"); if (object2 == null) { object2 = (GameObject)Instantiate(object2_prefab); object2.tag = "object2"; m_object2Placement = object2.GetComponent <ObjectPlacement>(); m_object2Placement.placeObject(position, rotation); } else { m_object2Placement = object2.GetComponent <ObjectPlacement>(); m_object2Placement.placeObject(position, rotation); } } break; } return(true); } } return(false); }
// Update is called once per frame void Update() { // #if UNITY_EDITOR //we will only use this script on the editor side, though there is nothing that would prevent it from working on device // if (Input.GetMouseButtonDown (0)) { // Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); // RaycastHit hit; // // //we'll try to hit one of the plane collider gameobjects that were generated by the plugin // //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent // if (Physics.Raycast (ray, out hit, maxRayDistance, collisionLayer)) { // //we're going to get the position from the contact point // m_HitTransform.position = hit.point; // Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); // // //and the rotation from the transform of the plane collider // m_HitTransform.rotation = hit.transform.rotation; // } // } // #else if (Input.touchCount > 0 && m_HitTransform != null) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; List <ARHitTestResult> hitresults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeFeaturePoint); if (hitresults.Count > 0) { foreach (var hitResult in hitresults) { Vector3 position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); } } // // prioritize reults types // ARHitTestResultType[] resultTypes = { // //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry, // ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // // if you want to use infinite planes use this: // //ARHitTestResultType.ARHitTestResultTypeExistingPlane, // //ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane, // //ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane, // //ARHitTestResultType.ARHitTestResultTypeFeaturePoint // }; // // foreach (ARHitTestResultType resultType in resultTypes) // { // if (HitTestWithResultType (point, resultType)) // { // return; // } // } } } // #endif }
public void bringToCenter() { Vector3 screenPosition = Camera.main.ScreenToViewportPoint(new Vector3(Screen.width / 2, Screen.height / 2, 1)); point.x = screenPosition.x; point.y = screenPosition.y; hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeFeaturePoint); if (hitResults.Count > 0) { cubeParent.transform.position = new Vector3(UnityARMatrixOps.GetPosition(hitResults[0].worldTransform).x, UnityARMatrixOps.GetPosition(hitResults[0].worldTransform).y, 1); } }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultType) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultType); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got Hit!"); //This was used in the original UnityARHitTestExample, //but we want to have multiple objects placed based on toggles // so we will change it //m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); //m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); //Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); var position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); var rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); switch (objectMode) { case ObjectMode.INV: if (m_ARKitProjectUI.GetGameObjectPressed() == null) { GameObject invisibleWall = (GameObject)Instantiate(invisibleWall_prefab); m_invisibleWallPlacement = invisibleWall.GetComponent <ObjectPlacement>(); m_invisibleWallPlacement.placeObject(position, rotation); } break; case ObjectMode.DEL: GameObject gameObjectDel = m_ARKitProjectUI.GetGameObjectPressed(); if (gameObjectDel != null) { Destroy(gameObjectDel); } break; case ObjectMode.OB1: if (object1_duplicate == true) { if (m_ARKitProjectUI.GetGameObjectPressed() == null) { GameObject object1 = (GameObject)Instantiate(object1_prefab); m_object1Placement = object1.GetComponent <ObjectPlacement>(); m_object1Placement.placeObject(position, rotation); } } else { GameObject object1 = GameObject.FindWithTag("object1"); if (object1 == null) { object1 = (GameObject)Instantiate(object1_prefab); object1.tag = "object1"; m_object1Placement = object1.GetComponent <ObjectPlacement>(); m_object1Placement.placeObject(position, rotation); } else { m_object1Placement = object1.GetComponent <ObjectPlacement>(); m_object1Placement.placeObject(position, rotation); } } break; case ObjectMode.OB2: if (object2_duplicate == true) { if (m_ARKitProjectUI.GetGameObjectPressed() == null) { GameObject object2 = (GameObject)Instantiate(object2_prefab); m_object2Placement = object2.GetComponent <ObjectPlacement>(); m_object2Placement.placeObject(position, rotation); } } else { GameObject object2 = GameObject.FindWithTag("object2"); if (object2 == null) { object2 = (GameObject)Instantiate(object2_prefab); object2.tag = "object2"; m_object2Placement = object2.GetComponent <ObjectPlacement>(); m_object2Placement.placeObject(position, rotation); } else { m_object2Placement = object2.GetComponent <ObjectPlacement>(); m_object2Placement.placeObject(position, rotation); } } break; } return(true); } } return(false); }