Exemplo n.º 1
0
    /// <summary>
    /// Creates a marker game object
    /// </summary>
    /// <returns>The Object Marker object</returns>
    ObjectMarker CreateMarker()
    {
        GameObject   go    = GameObject.Instantiate(labelPrefab as Object, markersParent) as GameObject;
        ObjectMarker label = go.GetComponent <ObjectMarker>();

        return(label);
    }
Exemplo n.º 2
0
 public void InitObjectMarker(VoxelArrayEditor voxelArray)
 {
     marker = CreateObjectMarker(voxelArray);
     marker.transform.parent = voxelArray.transform;
     marker.objectEntity     = this;
     marker.tag = "ObjectMarker";
 }
    /// <summary>
    /// Adds the anchor.
    /// </summary>
    /// <param name="marker">The marker.</param>
    public void AddAnchor(ObjectMarker marker)
    {
        GameObject go = marker.gameObject;

        if (store == null)
        {
            DebugManager.Instance.PrintToInfoLog("Store uninitialised");
            return;
        }

        WorldAnchor wa = go.GetComponent <WorldAnchor>();

        if (wa == null)
        {
            wa = go.AddComponent <WorldAnchor>();
        }
        else
        {
            DebugManager.Instance.PrintToInfoLog("Already anchored:" + marker.markerName);
        }


        bool saved = store.Save(marker.markerName, wa);

        DebugManager.Instance.PrintToInfoLog("saved:" + marker.markerName + "::" + saved + "@" + go.transform.position);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Toggles the menu visibility.
    /// </summary>
    /// <param name="go">The gameobject of the marker.</param>
    public void ToggleMenuVisibility(GameObject go)
    {
        if (go != null && lastMarker != go.GetComponent <ObjectMarker>())
        {
            gameObject.SetActive(true);
            gameObject.transform.position = go.transform.position
                                            + (Camera.main.transform.position - go.transform.position).normalized * 0.1f;
            lastMarker = go.GetComponent <ObjectMarker>();
        }
        //if last click was registered on me
        else
        {
            //if moving
            if (go.GetComponent <MoveWithObject>())
            {
                go.GetComponent <MoveWithObject>().StopRunning();
                Destroy(go.GetComponent <MoveWithObject>());
                if (needsRepinning)
                {
                    needsRepinning = false;
                    PersistenceManager.Instance.AddAnchor(lastMarker);
                }
            }

            gameObject.SetActive(false);
            lastMarker = null;
        }
    }
Exemplo n.º 5
0
 public ObjectMarker GetClubs()
 {
     if (this.clubs == null)
     {
         this.clubs = GetComponentInChildren <Clubs>();
     }
     return(this.clubs);
 }
Exemplo n.º 6
0
 public ObjectMarker GetSpades()
 {
     if (this.spades == null)
     {
         this.spades = GetComponentInChildren <Spades>();
     }
     return(this.spades);
 }
Exemplo n.º 7
0
 public ObjectMarker GetHearts()
 {
     if (this.hearts == null)
     {
         this.hearts = GetComponentInChildren <Hearts>();
     }
     return(this.hearts);
 }
Exemplo n.º 8
0
 public ObjectMarker GetDiamonds()
 {
     if (this.diamonds == null)
     {
         this.diamonds = GetComponentInChildren <Diamonds>();
     }
     return(this.diamonds);
 }
    /// <summary>
    /// Deletes the anchor.
    /// </summary>
    /// <param name="om">The om.</param>
    public void DeleteAnchor(ObjectMarker om)
    {
        string      markerName = om.markerName;
        WorldAnchor wa         = om.GetComponent <WorldAnchor>();

        if (wa)
        {
            DestroyImmediate(om.GetComponent <WorldAnchor>());
        }

        DebugManager.Instance.PrintToInfoLog("Anchor " + markerName + " deleted: " + (store != null ? store.Delete(markerName).ToString() : "No store.") + ":: " + wa);
    }
Exemplo n.º 10
0
    /// <summary>
    /// Deletes the object.
    /// </summary>
    /// <param name="obj">The object.</param>
    public void DeleteObject(GameObject obj)
    {
        print(obj);
        if (obj == lastMarkerPlacement)
        {
            return;
        }

        DebugManager.Instance.PrintToRunningLog("Clicked on: " + obj.name);
        ObjectMarker marker = obj.GetComponent <ObjectMarker>();

        markers.Remove(marker);

        Destroy(marker.gameObject);
    }
Exemplo n.º 11
0
    /// <summary>
    /// Attempts to Drops the label and the marker at the given position if no overlaps found
    /// </summary>
    /// <param name="pos">Position</param>
    /// <param name="obj">RecognisedObject</param>
    /// <returns>The Object Marker object</returns>
    public ObjectMarker AttemptToDropMarker(Vector3 pos, RecognisedObject obj)
    {
        if (IsOverlappingSimilarMarker(pos, obj.type))
        {
            DebugManager.Instance.PrintToRunningLog("Similar marker: " + obj.type);
            return(null);
        }
        else
        {
            ObjectMarker marker = CreateMarker();
            marker.SetProperties(pos, obj.type, obj.score);

            markers.Add(marker);
            return(marker);
        }
    }
Exemplo n.º 12
0
    void ParseResponse(ResponseStruct resp, Matrix4x4 cameraToWorldMatrix, Matrix4x4 projectionMatrix)
    {
        foreach (RecognisedObject obj in resp.recognizedObjects)
        {
            Vector3?hitPoint = ObjectLocator.Instance.PixelToWorldPoint(new Vector2(obj.details[0] + (obj.details[2] - obj.details[0]) / 2,
                                                                                    obj.details[1] + (obj.details[3] - obj.details[1]) / 2),
                                                                        cameraToWorldMatrix, projectionMatrix);

            if (hitPoint.HasValue)
            {
                ObjectMarker marker = ObjectLocator.Instance.AttemptToDropMarker(hitPoint.Value, obj);
            }
            else
            {
                DebugManager.Instance.PrintToRunningLog("No boundary found");
            }
        }
    }
    /// <summary>
    /// Gets all anchors.
    /// </summary>
    void GetAllAnchors()
    {
        string[] ids = this.store.GetAllIds();
        DebugManager.Instance.PrintToInfoLog("persistence : " + store.anchorCount + " " + ids.Length);
        for (int index = 0; index < ids.Length; index++)
        {
            ///[0]: Marker type
            ///[1]: Marker confidence score
            ///[2]: Marker additional info(random number for now)
            string[] chunks = ids[index].Split(':');

            RecognisedObject obj = new RecognisedObject
            {
                type  = chunks[0],
                score = float.Parse(chunks[1])
            };
            ObjectMarker om = ObjectLocator.Instance.AttemptToDropMarker(Vector3.zero, obj);
            om.markerName = ids[index];

            store.Load(ids[index], om.gameObject);
            DebugManager.Instance.PrintToInfoLog(ids[index] + "@" + om.transform.position);
        }
    }
 /// <summary>
 /// Determines whether the specified marker is anchored.
 /// </summary>
 /// <param name="om">The om.</param>
 /// <returns>
 ///   <c>true</c> if the specified om is anchored; otherwise, <c>false</c>.
 /// </returns>
 public bool IsAnchor(ObjectMarker om)
 {
     return(om.GetComponent <WorldAnchor>() != null);
 }
Exemplo n.º 15
0
        private void RefreshTarget2()
        {
            ObjectMarker targetMarker = null;
            GMapMarker   target       = null;

            ObjTarget2 = UnitCore.Instance.TargetObj2;
            //refresh 2D target
            if (MapMode == 0)
            {
                if (UnitCore.Instance.mainMap != null)
                {
                    var itor = UnitCore.Instance.mainMap.Markers.GetEnumerator();
                    while (itor.MoveNext())
                    {
                        var marker = itor.Current;

                        if ((int)marker.Tag == 902)//900+1,2,3,4...
                        {
                            if (marker.Shape is ObjectMarker obj)
                            {
                                targetMarker = obj;
                                target       = marker;
                            }
                            break;
                        }
                    }
                }
                if (target == null || targetMarker == null)
                {
                    return;
                }

                App.Current.Dispatcher.Invoke(new Action(() =>
                {
                    targetMarker.Refresh(UnitCore.Instance.TargetObj2);
                    var point = new PointLatLng(UnitCore.Instance.TargetObj2.Latitude,
                                                UnitCore.Instance.TargetObj2.Longitude);
                    point.Offset(UnitCore.Instance.MainMapCfg.MapOffset.Lat,
                                 UnitCore.Instance.MainMapCfg.MapOffset.Lng);
                    target.Position = point;
                    //remove legacy route
                    var isExist = UnitCore.Instance.mainMap.Markers.Contains(UnitCore.Instance.TargetRoute2);
                    UnitCore.Instance.BuoyLock.WaitOne();
                    UnitCore.Instance.mainMap.Markers.Remove(UnitCore.Instance.TargetRoute2);
                    UnitCore.Instance.BuoyLock.ReleaseMutex();
                    UnitCore.Instance.routePoint2.Remove(PointLatLng.Zero);

                    UnitCore.Instance.routePoint2.Add(point);
                    //if (UnitCore.Instance.routePoint.Count > 300)
                    //    UnitCore.Instance.routePoint.RemoveAt(0);
                    if (UnitCore.Instance.routePoint2.Count == 1)
                    {
                        return;
                    }
                    UnitCore.Instance.TargetRoute2 = new GMapMarker(UnitCore.Instance.routePoint2[0]);
                    {
                        UnitCore.Instance.TargetRoute2.Tag        = 102;
                        UnitCore.Instance.TargetRoute2.routebrush = Brushes.Yellow;

                        UnitCore.Instance.TargetRoute2.Route.AddRange(UnitCore.Instance.routePoint2);

                        UnitCore.Instance.TargetRoute2.RegenerateRouteShape(UnitCore.Instance.mainMap);
                        UnitCore.Instance.TargetRoute2.ZIndex = -1;
                    }
                    if (isExist)
                    {
                        UnitCore.Instance.BuoyLock.WaitOne();
                        UnitCore.Instance.mainMap.Markers.Add(UnitCore.Instance.TargetRoute2);
                        UnitCore.Instance.BuoyLock.ReleaseMutex();
                    }

                    if (UnitCore.Instance.AutoTrace)
                    {
                        UnitCore.Instance.mainMap.Position = point;
                    }
                }));
            }
        }
Exemplo n.º 16
0
        private void RefreshTarget1()
        {
            ObjectMarker targetMarker = null;
            GMapMarker   target       = null;

            ObjTarget1 = UnitCore.Instance.TargetObj1;
            //refresh 2D target
            if (MapMode == 0)
            {
                if (UnitCore.Instance.mainMap != null)
                {
                    var itor = UnitCore.Instance.mainMap.Markers.GetEnumerator();
                    while (itor.MoveNext())
                    {
                        var marker = itor.Current;

                        if ((int)marker.Tag == 901)//900+1,2,3,4...
                        {
                            if (marker.Shape is ObjectMarker obj)
                            {
                                targetMarker = obj;
                                target       = marker;
                            }
                            break;
                        }
                    }
                }
                if (target == null || targetMarker == null)
                {
                    return;
                }

                App.Current.Dispatcher.Invoke(new Action(() =>
                {
                    targetMarker.Refresh(UnitCore.Instance.TargetObj1);
                    var point = new PointLatLng(UnitCore.Instance.TargetObj1.Latitude,
                                                UnitCore.Instance.TargetObj1.Longitude);
                    point.Offset(UnitCore.Instance.MainMapCfg.MapOffset.Lat,
                                 UnitCore.Instance.MainMapCfg.MapOffset.Lng);
                    target.Position = point;
                    //remove legacy route
                    var isExist = UnitCore.Instance.mainMap.Markers.Contains(UnitCore.Instance.TargetRoute1);
                    UnitCore.Instance.BuoyLock.WaitOne();
                    UnitCore.Instance.mainMap.Markers.Remove(UnitCore.Instance.TargetRoute1);
                    UnitCore.Instance.BuoyLock.ReleaseMutex();
                    UnitCore.Instance.routePoint1.Remove(PointLatLng.Zero);

                    UnitCore.Instance.routePoint1.Add(point);
                    //if (UnitCore.Instance.routePoint.Count > 300)
                    //    UnitCore.Instance.routePoint.RemoveAt(0);
                    if (UnitCore.Instance.routePoint1.Count == 1)
                    {
                        return;
                    }
                    UnitCore.Instance.TargetRoute1 = new GMapMarker(UnitCore.Instance.routePoint1[0]);
                    {
                        UnitCore.Instance.TargetRoute1.Tag        = 101;
                        UnitCore.Instance.TargetRoute1.routebrush = Brushes.Red;

                        UnitCore.Instance.TargetRoute1.Route.AddRange(UnitCore.Instance.routePoint1);

                        UnitCore.Instance.TargetRoute1.RegenerateRouteShape(UnitCore.Instance.mainMap);
                        UnitCore.Instance.TargetRoute1.ZIndex = -1;
                    }
                    if (isExist)
                    {
                        UnitCore.Instance.BuoyLock.WaitOne();
                        UnitCore.Instance.mainMap.Markers.Add(UnitCore.Instance.TargetRoute1);
                        UnitCore.Instance.BuoyLock.ReleaseMutex();
                    }

                    if (UnitCore.Instance.AutoTrace)
                    {
                        UnitCore.Instance.mainMap.Position = point;
                    }
                }));
            }
            else//3D
            {
                Refresh3DView();
                if (ObjInfoVisible)
                {
                    TargetInfo = UnitCore.Instance.TargetObj1.Name + "   " + UnitCore.Instance.TargetObj1.Time + "(UTC)\r" +
                                 "经度:" + UnitCore.Instance.TargetObj1.Longitude.ToString("F06") + "\r|纬度:" +
                                 UnitCore.Instance.TargetObj1.Latitude.ToString("F06") + "\r" +
                                 "测算深度:" + UnitCore.Instance.TargetObj1.Depth.ToString("F02") +
                                 "测距状态:" + UnitCore.Instance.TargetObj1.Status;
                }
                else
                {
                    TargetInfo = "";
                }
            }
        }
Exemplo n.º 17
0
    void Update()
    {
        if (Input.touchCount == 0)
        {
            if (currentTouchOperation == TouchOperation.SELECT)
            {
                voxelArray.TouchUp();
            }
            if (currentTouchOperation == TouchOperation.MOVE)
            {
                movingAxis.TouchUp();
            }
            currentTouchOperation = TouchOperation.NONE;
        }
        else if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);

            RaycastHit hit;
            if (currentTouchOperation != TouchOperation.SELECT)
            {
                selectingXRay = true;
            }
            bool rayHitSomething = Physics.Raycast(cam.ScreenPointToRay(Input.GetTouch(0).position),
                                                   out hit, Mathf.Infinity, selectingXRay ? Physics.DefaultRaycastLayers : NO_XRAY_MASK);
            Voxel         hitVoxel         = null;
            int           hitFaceI         = -1;
            TransformAxis hitTransformAxis = null;
            ObjectMarker  hitMarker        = null;
            if (rayHitSomething)
            {
                GameObject hitObject = hit.transform.gameObject;
                if (hitObject.tag == "Voxel")
                {
                    hitVoxel = hitObject.GetComponent <Voxel>();
                    hitFaceI = Voxel.FaceIForDirection(hit.normal);
                    if (hitFaceI == -1)
                    {
                        hitVoxel = null;
                    }
                }
                else if (hitObject.tag == "ObjectMarker")
                {
                    hitMarker = hitObject.GetComponent <ObjectMarker>();
                }
                else if (hitObject.tag == "MoveAxis")
                {
                    hitTransformAxis = hitObject.GetComponent <TransformAxis>();
                }

                if ((hitVoxel != null && hitVoxel.substance != null && hitVoxel.substance.xRay) ||
                    (hitMarker != null && (hitMarker.gameObject.layer == 8 || hitMarker.gameObject.layer == 10)))     // xray or SelectedObject layer
                {
                    // allow moving axes through xray substances
                    RaycastHit newHit;
                    if (Physics.Raycast(cam.ScreenPointToRay(Input.GetTouch(0).position),
                                        out newHit, Mathf.Infinity, NO_TRANSPARENT_MASK))
                    {
                        if (newHit.transform.tag == "MoveAxis")
                        {
                            hitVoxel         = null;
                            hitFaceI         = -1;
                            hitMarker        = null;
                            hitTransformAxis = newHit.transform.GetComponent <TransformAxis>();
                        }
                    }
                }
            }
            if (hitVoxel != null)
            {
                lastHitVoxel = hitVoxel;
                lastHitFaceI = hitFaceI;
            }
            else if (hitMarker != null)
            {
                lastHitVoxel = null;
                lastHitFaceI = -1;
            }

            if (touch.phase == TouchPhase.Began)
            {
                if (currentTouchOperation == TouchOperation.SELECT)
                {
                    voxelArray.TouchUp();
                }
                // this seems to improve the reliability of double-taps when things are running slowly.
                // I think it's because there's not always a long enough gap between taps
                // for the touch operation to be cleared.
                currentTouchOperation = TouchOperation.NONE;
            }

            if (currentTouchOperation == TouchOperation.NONE)
            {
                if (GUIPanel.PanelContainingPoint(touch.position) != null)
                {
                    currentTouchOperation = TouchOperation.GUI;
                }
                else if (touch.phase != TouchPhase.Moved && touch.phase != TouchPhase.Ended && touch.tapCount == 1)
                {
                }   // wait until moved or released, in case a multitouch operation is about to begin
                else if (!rayHitSomething)
                {
                    voxelArray.TouchDown(null);
                }
                else if (hitVoxel != null)
                {
                    if (touch.tapCount == 1)
                    {
                        currentTouchOperation = TouchOperation.SELECT;
                        voxelArray.TouchDown(hitVoxel, hitFaceI);
                        selectingXRay = hitVoxel.substance != null && hitVoxel.substance.xRay;
                    }
                    else if (touch.tapCount == 2)
                    {
                        voxelArray.DoubleTouch(hitVoxel, hitFaceI);
                    }
                    else if (touch.tapCount == 3)
                    {
                        voxelArray.TripleTouch(hitVoxel, hitFaceI);
                    }
                    UpdateZoomDepth();
                }
                else if (hitMarker != null)
                {
                    currentTouchOperation = TouchOperation.SELECT;
                    voxelArray.TouchDown(hitMarker);
                    selectingXRay = hitMarker.objectEntity.xRay;
                    UpdateZoomDepth();
                }
                else if (hitTransformAxis != null)
                {
                    if (touch.tapCount == 1)
                    {
                        currentTouchOperation = TouchOperation.MOVE;
                        movingAxis            = hitTransformAxis;
                        movingAxis.TouchDown(touch);
                    }
                    else if (touch.tapCount == 2 && lastHitVoxel != null)
                    {
                        voxelArray.DoubleTouch(lastHitVoxel, lastHitFaceI);
                    }
                    else if (touch.tapCount == 3 && lastHitVoxel != null)
                    {
                        voxelArray.TripleTouch(lastHitVoxel, lastHitFaceI);
                    }
                    UpdateZoomDepth();
                }
            } // end if currentTouchOperation == NONE

            else if (currentTouchOperation == TouchOperation.SELECT)
            {
                if (hitVoxel != null)
                {
                    voxelArray.TouchDrag(hitVoxel, hitFaceI);
                }
                if (hitMarker != null)
                {
                    voxelArray.TouchDrag(hitMarker);
                }
            }
            else if (currentTouchOperation == TouchOperation.MOVE)
            {
                movingAxis.TouchDrag(touch);
            }
        } // end if touch count is 1
        else if (Input.touchCount == 2)
        {
            if (currentTouchOperation == TouchOperation.NONE)
            {
                currentTouchOperation = TouchOperation.CAMERA;
                UpdateZoomDepth();
            }
            if (currentTouchOperation != TouchOperation.CAMERA)
            {
                return;
            }

            Touch touchZero = Input.GetTouch(0);
            Touch touchOne  = Input.GetTouch(1);

            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

            float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

            float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

            float scaleFactor = Mathf.Pow(1.005f, deltaMagnitudeDiff / cam.pixelHeight * 700f);
            if (scaleFactor != 1)
            {
                pivot.localScale *= scaleFactor;
                if (pivot.localScale.x > MAX_ZOOM)
                {
                    pivot.localScale = new Vector3(MAX_ZOOM, MAX_ZOOM, MAX_ZOOM);
                }
                if (pivot.localScale.x < MIN_ZOOM)
                {
                    pivot.localScale = new Vector3(MIN_ZOOM, MIN_ZOOM, MIN_ZOOM);
                }
            }

            Vector3 move = (touchZero.deltaPosition + touchOne.deltaPosition) / 2;
            move *= 300f;
            move /= cam.pixelHeight;
            Vector3 pivotRotationEuler = pivot.rotation.eulerAngles;
            pivotRotationEuler.y += move.x;
            pivotRotationEuler.x -= move.y;
            if (pivotRotationEuler.x > 90 && pivotRotationEuler.x < 180)
            {
                pivotRotationEuler.x = 90;
            }
            if (pivotRotationEuler.x < -90 || (pivotRotationEuler.x > 180 && pivotRotationEuler.x < 270))
            {
                pivotRotationEuler.x = -90;
            }
            pivot.rotation = Quaternion.Euler(pivotRotationEuler);
        }
        else if (Input.touchCount == 3)
        {
            if (currentTouchOperation == TouchOperation.NONE)
            {
                currentTouchOperation = TouchOperation.CAMERA;
                UpdateZoomDepth();
            }
            if (currentTouchOperation != TouchOperation.CAMERA)
            {
                return;
            }

            Vector2 move = new Vector2(0, 0);
            for (int i = 0; i < 3; i++)
            {
                move += Input.GetTouch(i).deltaPosition;
            }
            move           *= 4.0f;
            move           /= cam.pixelHeight;
            pivot.position -= move.x * pivot.right * pivot.localScale.z;
            pivot.position -= move.y * pivot.up * pivot.localScale.z;
        }
    }