Ejemplo n.º 1
0
    protected override void OnEndManipulation(TapGesture gesture)
    {
        if (gesture.WasCancelled)
        {
            return;
        }
        if (gesture.TargetObject != null || IsPointerOverUI(gesture))
        {
            return;
        }
        if (GestureTransformationUtility.Raycast(gesture.startPosition, _hits,
                                                 TrackableType.PlaneWithinPolygon))
        {
            if (placedObj != null)
            {
                Destroy(placedObj);
            }
            // GameObject placedObj = Instantiate(DataHandler.Instance.GetFurniture(), pose.position, pose.rotation) as GameObject;
            placedObj = Instantiate(DataHandler.Instance.GetFurniture(), pose.position, pose.rotation) as GameObject;
            parentObj.transform.position = pose.position;
            parentObj.transform.rotation = pose.rotation;
            placedObj.transform.parent   = parentObj.transform;//to control the created prefab

            var anchorObject = new GameObject("placementAnchor");
            anchorObject.transform.position = pose.position;
            anchorObject.transform.rotation = pose.rotation;
            //placedObj.transform.parent = anchorObject.transform;
            parentObj.transform.parent = anchorObject.transform;
        }
    }
Ejemplo n.º 2
0
    void CrosshairCalculation()
    {
        Vector3 origin = arCam.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, 0));

        //   Ray ray = arCam.ScreenPointToRay(origin);

        if (GestureTransformationUtility.Raycast(origin, _hits, TrackableType.PlaneWithinPolygon))
        {
            pose = _hits[0].pose;
            crossHair.transform.position    = pose.position;
            crossHair.transform.eulerAngles = new Vector3(90, 0, 0);
        }
    }
    protected override void OnEndManipulation(TapGesture gesture)
    {
        if (gesture.WasCancelled)
        {
            return;
        }

        // If gesture is targeting an existing object we are done.
        // Allow for test planes
        if (gesture.TargetObject != null && gesture.TargetObject.layer != 9)
        {
            return;
        }

        // Raycast against the location the player touched to search for planes.
        if (GestureTransformationUtility.Raycast(gesture.StartPosition, hits, TrackableType.PlaneWithinPolygon))
        {
            var hit = hits[0];

            // Use hit pose and camera pose to check if hittest is from the
            // back of the plane, if it is, no need to create the anchor.
            if (Vector3.Dot(Camera.main.transform.position - hit.pose.position, hit.pose.rotation * Vector3.up) < 0)
            {
                return;
            }

            if (placementObject == null)
            {
                placementObject = Instantiate(placementPrefab, hit.pose.position, hit.pose.rotation);

                // Create anchor to track reference point and set it as the parent of placementObject.
                // TODO: this should update with a reference point for better tracking.
                var anchorObject = new GameObject("PlacementAnchor");
                anchorObject.transform.position  = hit.pose.position;
                anchorObject.transform.rotation  = hit.pose.rotation;
                placementObject.transform.parent = anchorObject.transform;

                // Find trackables object in scene and use that as parent
                if (trackablesObject == null)
                {
                    trackablesObject = GameObject.Find("Trackables");
                }
                if (trackablesObject != null)
                {
                    anchorObject.transform.parent = trackablesObject.transform;
                }

                onObjectPlaced?.Invoke(this, placementObject);
            }
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Function called when the manipulation is ended.
    /// </summary>
    /// <param name="gesture">The current gesture.</param>
    protected override void OnEndManipulation(TapGesture gesture)
    {
        if (_spawnedObject != null)
        {
            return;
        }

        if (gesture.WasCancelled)
        {
            return;
        }

        // If gesture is targeting an existing object we are done.
        // Allow for test planes
        if (gesture.TargetObject != null && gesture.TargetObject.layer != 9)
        {
            return;
        }

        // Raycast against the location the player touched to search for planes.
        if (GestureTransformationUtility.Raycast(gesture.StartPosition, s_Hits, TrackableType.PlaneWithinPolygon))
        {
            var hit = s_Hits[0];

            _spawnedObject = Instantiate(placementPrefab, hit.pose.position, hit.pose.rotation);

            _spawnedObject.transform.LookAt(new Vector3(
                                                Camera.main.transform.position.x,
                                                _spawnedObject.transform.position.y,
                                                Camera.main.transform.position.z
                                                ));

            if (m_OnObjectPlaced != null)
            {
                m_OnObjectPlaced.Invoke();
            }
        }
    }