示例#1
0
        private void DoWhenEventTypeSingleTap(ARHitResult hitResult)
        {
            // The hit results are sorted by distance. Only the nearest hit point is valid.
            // Set the number of stored objects to 10 to avoid the overload of rendering and AR Engine.
            if (mVirtualObjects.Count >= 16)
            {
                mVirtualObjects.ElementAt(0).GetAnchor().Detach();
                mVirtualObjects.RemoveAt(0);
            }

            IARTrackable currentTrackable = hitResult.Trackable;

            Java.Lang.Object PointOrPlane    = null;
            bool             isPlanHitJudge  = false;
            bool             isPointHitJudge = false;

            try
            {
                PointOrPlane   = currentTrackable.JavaCast <ARPlane>();
                isPlanHitJudge = PointOrPlane.GetType() == typeof(ARPlane);
            }
            catch (Exception e)
            {
                PointOrPlane    = currentTrackable.JavaCast <ARPoint>();
                isPointHitJudge = PointOrPlane.GetType() == typeof(ARPoint);
            };
            if (isPointHitJudge)
            {
                mVirtualObjects.Add(new VirtualObject(hitResult.CreateAnchor(), BLUE_COLORS));
            }
            else if (isPlanHitJudge)
            {
                mVirtualObjects.Add(new VirtualObject(hitResult.CreateAnchor(), GREEN_COLORS));
            }
            else
            {
                Log.Info(TAG, "Hit result is not plane or point.");
            }
        }
示例#2
0
        private void HandleGestureEvent(ARFrame arFrame, ARCamera arCamera, float[] projectionMatrix, float[] viewMatrix)
        {
            GestureEvent mEvent = mQueuedSingleTaps.Poll().JavaCast <GestureEvent>();

            if (mEvent == null)
            {
                return;
            }

            // Do not perform anything when the object is not tracked.
            if (arCamera.TrackingState != ARTrackableTrackingState.Tracking)
            {
                return;
            }
            int eventType = mEvent.GetType();

            switch (eventType)
            {
            case GestureEvent.GESTURE_EVENT_TYPE_DOUBLETAP:
                DoWhenEventTypeDoubleTap(viewMatrix, projectionMatrix, mEvent);
                break;

            case GestureEvent.GESTURE_EVENT_TYPE_SCROLL:
            {
                if (mSelectedObj == null)
                {
                    break;
                }
                ARHitResult hitResult = HitTest4Result(arFrame, arCamera, mEvent.GetEventSecond());
                if (hitResult != null)
                {
                    mSelectedObj.SetAnchor(hitResult.CreateAnchor());
                }
                break;
            }

            case GestureEvent.GESTURE_EVENT_TYPE_SINGLETAPCONFIRMED:
            {
                // Do not perform anything when an object is selected.
                if (mSelectedObj != null)
                {
                    mSelectedObj.SetIsSelected(false);
                    mSelectedObj = null;
                }
                MotionEvent tap       = mEvent.GetEventFirst();
                ARHitResult hitResult = null;

                hitResult = HitTest4Result(arFrame, arCamera, tap);

                if (hitResult == null)
                {
                    break;
                }
                DoWhenEventTypeSingleTap(hitResult);
                break;
            }

            default:
                Log.Info(TAG, "Unknown motion event type, and do nothing.");
                break;
            }
        }