public void UpdateTarget(Transform hostTransform, GizmoShowSetting gizmoSetting)
    {
        if (HostTransform == hostTransform)
        {
            DisableGizmos();
            HostTransform = null;
            return;
        }

        //TODO FIX
        HostTransform = hostTransform;
        var rot = hostTransform.rotation;

        HostTransform.rotation = Quaternion.identity;
        var bounds = BoundsHelper.GetBounds(HostTransform);

        HostTransform.rotation = rot;
        transform.rotation     = rot;
        Center       = bounds.center;
        positionDiff = Center - HostTransform.transform.position;

        xArrow.SetActive(gizmoSetting.movement);
        yArrow.SetActive(gizmoSetting.movement);
        zArrow.SetActive(gizmoSetting.movement);
        if (useNegativeAxis)
        {
            negativexArrow.SetActive(gizmoSetting.movement);
            negativeyArrow.SetActive(gizmoSetting.movement);
            negativezArrow.SetActive(gizmoSetting.movement);
        }

        roll.SetActive(gizmoSetting.rotation);
        yaw.SetActive(gizmoSetting.rotation);
        pitch.SetActive(gizmoSetting.rotation);
    }
Exemple #2
0
        protected virtual bool UpdateVertexBufferFromGeometrySource(IEnumerable <TDxPoint> newPoints)
        {
            bool vertexBufferSizeChanged = false;

            // Vertices will be resized to the next power of 2, saves on resizing too much
            _pointList = newPoints.ToArray();
            var pointCount = _pointList.Length;

            // There's an issue with nVidia cards that the rendering pipeline locks up if we try to reuse
            // Vertex buffers allocated on the default pool. AMD cards seem to be ok. Work around is to use
            // the system pool, which is slow, or lock the back buffer via the target image.

            if (DxHost.LockImage())
            {
                if (_vertexBuffer == null || pointCount > _vertexBufferAllocated || pointCount < (_vertexBufferAllocated >> 1))
                {
                    _vertexBuffer?.Dispose();
                    var newSize = MathHelper.CeilingPow2(pointCount);
                    _vertexBuffer           = new VertexBuffer(Device, Utilities.SizeOf <TDxPoint>() * newSize, Usage.WriteOnly, VertexFormat.None, Pool.Default);
                    _vertexBufferAllocated  = newSize;
                    vertexBufferSizeChanged = true;
                }
                // Lock the entire buffer by specifying 0 for the offset and size, throw away it's current contents
                var vertexStream = _vertexBuffer.Lock(0, 0, LockFlags.Discard);
                vertexStream.WriteRange(_pointList);
                _vertexBuffer.Unlock();
                DxHost.UnlockImage();
            }
            _vertexCount = pointCount;

            // Calculate the bounds of the list on a background thread
            var localPointList = _pointList;
            var dataTransform  = Plotter.Viewport.Transform.DataTransform;

            if (localPointList.Any())
            {
                Action resizeAction = () =>
                {
                    var minX = localPointList[0].X;
                    var maxX = localPointList[0].X;
                    var minY = localPointList[0].Y;
                    var maxY = localPointList[0].Y;
                    foreach (var point in localPointList)
                    {
                        minX = Math.Min(minX, point.X);
                        maxX = Math.Max(maxX, point.X);
                        minY = Math.Min(minY, point.Y);
                        maxY = Math.Max(maxY, point.Y);
                    }
                    var bounds = BoundsHelper.GetViewportBounds(new[] { new System.Windows.Point(minX, minY), new System.Windows.Point(maxX, maxY) }, dataTransform);
                    _syncContext.Send(s =>
                    {
                        Viewport2D.SetContentBounds(this, bounds);
                    }, null);
                };
                // Spawn action on throttled update thread
                _throttledAction.InvokeAction(resizeAction);
            }
            return(vertexBufferSizeChanged);
        }
    void Update()
    {
        if (HostTransform == null)
        {
            return;
        }

        var bounds = BoundsHelper.GetBounds(HostTransform);
        var scaler = 1f;

        if (!IsStaticScale)
        {
            var hostScale = bounds.size;
            scaler = hostScale.x;
            if (scaler < hostScale.y)
            {
                scaler = hostScale.y;
            }
            if (scaler < hostScale.z)
            {
                scaler = hostScale.z;
            }
        }

        transform.position   = HostTransform.position + positionDiff;
        transform.localScale = scaler * Vector3.one;
    }
Exemple #4
0
        protected override void UpdateCore()
        {
            if (DataSource == null)
            {
                return;
            }
            if (Plotter == null)
            {
                return;
            }
            if (!IsEnabled)
            {
                return;
            }

            Rect output    = Viewport.Output;
            var  transform = GetTransform();

            if (FilteredPoints == null || !(transform.DataTransform is IdentityTransform))
            {
                IEnumerable <Point> points = GetPoints();
                if (!points.Any())
                {
                    return;
                }

                var bounds = BoundsHelper.GetViewportBounds(points, transform.DataTransform);
                if (bounds.Width >= 0 && bounds.Height >= 0)
                {
                    bounds = new DataRect(bounds.XMin - 360.0, bounds.YMin, bounds.Width + 720.0, bounds.Height);
                }
                Viewport2D.SetContentBounds(this, bounds);

                // getting new value of transform as it could change after calculating and setting content bounds.
                transform = GetTransform();
                List <Point> transformedPoints = transform.DataToScreenAsList(points);

                var screenOffset = transform.DataToScreen(new Point(360, 0));

                // Analysis and filtering of unnecessary points
                FilteredPoints = new FakePointList(transformedPoints, double.NegativeInfinity, double.PositiveInfinity);
                if (ProvideVisiblePoints)
                {
                    List <Point> viewportPointsList = null;
                    viewportPointsList = new List <Point>(transformedPoints.Count);
                    if (transform.DataTransform is IdentityTransform)
                    {
                        viewportPointsList.AddRange(points);
                    }
                    else
                    {
                        var viewportPoints = points.DataToViewport(transform.DataTransform);
                        viewportPointsList.AddRange(viewportPoints);
                    }
                    SetVisiblePoints(this, new ReadOnlyCollection <Point>(viewportPointsList));
                }
                Offset = new Vector();
            }
        }
Exemple #5
0
 private void UpdateBounds(IPointDataSource dataSource)
 {
     if (this.Plotter != null)
     {
         var      transform = ((Plotter2D)Plotter).Viewport.Transform;
         DataRect bounds    = BoundsHelper.GetViewportBounds(dataSource.GetPoints(), transform.DataTransform);
         Viewport2D.SetContentBounds(this, bounds);
     }
 }
        public async Task <IEnumerable <PlaceViewModel> > GetPlacesFromArea(float lat, float lon, float range)
        {
            string url = BoundsHelper.GetBounds(lat, lon, range);

            Task <string> getPlaceTask = HttpHelper.GetAsync(hitchWikiURI + url);
            string        result       = await getPlaceTask;

            return(StringToViewModels(result));
        }
Exemple #7
0
    void changeBoundingBox()
    {
        BoundingBox = BoundsHelper.BuildBounds(touches.Values);

        oldCentre = centre;
        centre    = getCentrePoint();

        if (liftBy != 0f)
        {
            centre = centre.UpTowards(targetCamera.transform.position, upDir, liftBy);
        }

        if (touchesChanged)
        {
            oldCentre = centre;
        }

        delta += (centre - oldCentre);
    }
Exemple #8
0
        public IPin GetPin(Node node, float testX, float testY)
        {
            var x = node.X;
            var y = node.Y;

            using var headerTextPaint = _paint.Clone().WithColor(0xFF_FFFFFF).WithTypeface(_headerTypeface);
            using var textPaint       = _paint.Clone().WithColor(0xFF_FFFFFF).WithTypeface(_nodeTypeface);

            var lineHeight = (int)(textPaint.FontMetrics.Descent - textPaint.FontMetrics.Ascent + textPaint.FontMetrics.Leading);

            var width = GetNodeWidth(node, headerTextPaint, textPaint);

            y -= (int)(textPaint.FontMetrics.Ascent - 3);

            // Hit-test circle radius larger than render radius
            var circleRadius = lineHeight / 2f;
            var pinOffset    = lineHeight / 4f;

            var pY = y;

            for (var i = 0; i < node.InputPins.Count; i++, pY += lineHeight)
            {
                var pin = node.InputPins[i];

                if (BoundsHelper.CircleContainsInclusive(x, pY - pinOffset, circleRadius, testX, testY))
                {
                    return(pin);
                }
            }

            pY = y;
            for (var i = 0; i < node.OutputPins.Count; i++, pY += lineHeight)
            {
                var pin = node.OutputPins[i];

                if (BoundsHelper.CircleContainsInclusive(x + width, pY - pinOffset, circleRadius, testX, testY))
                {
                    return(pin);
                }
            }

            return(null);
        }
        protected override void UpdateCore()
        {
            if (Viewport == null || Viewport.Output == new Rect(0, 0, 0, 0) || DataSource == null)
            {
                return;
            }

            foreach (var m in Markers)
            {
                Plotter.MainCanvas.Children.Remove(m);
            }


            if (Markers.Count == 0)
            {
                return;
            }

            var transform = GetTransform();

            for (int i = 0; i < Markers.Count; i++)
            {
                var    offset = GetXValue(this);
                double X      = LineGraphWithPoints.GetXValue(Markers[i] as DependencyObject) + GetXValue(this);
                double Y      = LineGraphWithPoints.GetYValue(Markers[i] as DependencyObject);

                var p = transform.DataToScreen(new Point(X, Y));

                //Update the points
                double canvasy = p.Y - Markers[i].Height / 2;
                double canvasx = p.X - Markers[i].Width / 2;
                Canvas.SetTop(Markers[i], canvasy);
                Canvas.SetLeft(Markers[i], canvasx);

                if (canvasy < Plotter.MainCanvas.ActualHeight & canvasy > 0 & canvasx < Plotter.MainCanvas.ActualWidth & canvasx > 0)
                {
                    Plotter.MainCanvas.Children.Add(Markers[i]);
                }
            }
            ContentBounds = BoundsHelper.GetViewportBounds(GetPoints(), transform.DataTransform);
            base.UpdateCore();
        }
    void changeBoundingBox()
    {
        BoundingBox = BoundsHelper.BuildBounds(touches.Values);

        if (touchesChanged && touches.Count > 0)
        {
            yPos = ZStack.Add(gameObject);
        }

        if (touchesChanged && touches.Count > 1)
        {
            scaler.StartMove(
                getWorldPoint(touches.Values.First().position),
                getCentrePoint());
        }
        else if (touchesChanged && touches.Count == 1)
        {
            scaler.StartMove(getCentrePoint().SetY(yPos));
        }
        else if (touchesChanged && touches.Count == 0)
        {
            scaler.EndMove();
            ZStack.Remove(gameObject);
        }

        if (scaler.IsMoving)
        {
            if (touches.Count > 1)
            {
                scaler.UpdateMove(getWorldPoint(touches.Values.First().position), getCentrePoint());
            }
            else if (touches.Count == 1)
            {
                scaler.UpdateMove(getCentrePoint());
            }
        }
    }
Exemple #11
0
        public InteractiveGameObject(GameObject InteractiveGameObjectParent)
        {
            var childRenderers = InteractiveGameObjectParent.GetComponentsInChildren <Renderer>();

            if (childRenderers != null)
            {
                AverageModelLocalBounds = BoundsHelper.GetAverageRendererBoundsLocal(childRenderers, InteractiveGameObjectParent.transform.worldToLocalMatrix);
            }

            Animator = InteractiveGameObjectParent.GetComponent <Animator>();
            if (Animator == null)
            {
                Animator = InteractiveGameObjectParent.GetComponentInChildren <Animator>();
            }

            this.InteractiveGameObjectParent = InteractiveGameObjectParent;
            Renderers = RendererRetrievableHelper.GetAllRederers(this.InteractiveGameObjectParent, false);

            Agent = InteractiveGameObjectParent.GetComponent <NavMeshAgent>();
            InitAgent();

            PhysicsRigidbody = this.InteractiveGameObjectParent.GetComponent <Rigidbody>();
            PhysicsCollider  = this.InteractiveGameObjectParent.GetComponent <Collider>();
        }
Exemple #12
0
        private void UpdateUIRepresentation()
        {
            if (isUpdating)
            {
                return;
            }

            if (plotter == null)
            {
                return;
            }

            IPointDataSource dataSource = DataSource;

            if (dataSource == null)
            {
                return;
            }

            visibleWhileUpdate = plotter.Viewport.Visible;

            isUpdating = true;

            panel.Children.Clear();

            DependencyObject dependencyDataSource = dataSource as DependencyObject;

            if (dependencyDataSource != null)
            {
                DataSource2dContext.SetVisibleRect(dependencyDataSource, plotter.Viewport.Visible);
                DataSource2dContext.SetScreenRect(dependencyDataSource, plotter.Viewport.Output);
            }

            IEnumerable <Point> viewportPoints = dataSource;

            var transform = plotter.Viewport.Transform;

            if (!(transform.DataTransform is IdentityTransform))
            {
                viewportPoints = dataSource.DataToViewport(transform.DataTransform);
            }

            var screenPoints   = viewportPoints.ViewportToScreen(transform);
            var filteredPoints = filters.Filter(screenPoints, plotter.Viewport);

            DataRect bounds = DataRect.Empty;

            double strokeThickness = 3;

            bool  first = true;
            Point lastPointOfPrevLine = new Point();

            int overallCount = 0;

            panel.BeginBatchAdd();

            const int ptsInPolyline = 500;

            foreach (var pointGroup in filteredPoints.Split(ptsInPolyline))
            {
                int ptsCount = ptsInPolyline;

                if (!first)
                {
                    ptsCount++;
                }

                PointCollection pointCollection = new PointCollection(ptsCount);

                if (!first)
                {
                    pointCollection.Add(lastPointOfPrevLine);
                }
                else
                {
                    first = false;
                }

                pointCollection.AddMany(pointGroup);

                overallCount += pointCollection.Count - 1;

                if (pointCollection.Count == 0)
                {
                    break;
                }

                lastPointOfPrevLine = pointCollection[pointCollection.Count - 1];

                pointCollection.Freeze();

                DataRect ithBounds = BoundsHelper.GetViewportBounds(pointCollection.ScreenToViewport(transform));
#if geom
                UIElement line = null;

                StreamGeometry geometry = new StreamGeometry();
                using (var dc = geometry.Open())
                {
                    dc.BeginFigure(pointCollection[0], false, false);
                    dc.PolyLineTo(pointCollection, true, false);
                }
                geometry.Freeze();
                GeometryDrawing drawing = new GeometryDrawing {
                    Geometry = geometry, Pen = new Pen(Brushes.Blue, 1)
                };
                drawing.Freeze();
                DrawingBrush brush = new DrawingBrush {
                    Drawing = drawing
                };
                brush.Freeze();

                var rectangle = new Rectangle {
                    Fill = brush, IsHitTestVisible = false
                };
                Rect ithScreenBounds = ithBounds.ViewportToScreen(transform);
                if (true || ithScreenBounds.Width > 2000 || ithScreenBounds.Height > 2000 || ithScreenBounds.Width < 1 || ithScreenBounds.Height < 1)
                {
                    line = rectangle;
                }
                else
                {
                    Size intSize = new Size((int)ithScreenBounds.Width, (int)ithScreenBounds.Height);
                    rectangle.Measure(intSize);
                    rectangle.Arrange(new Rect(intSize));

                    RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)ithScreenBounds.Width, (int)ithScreenBounds.Height, 96, 96, PixelFormats.Pbgra32);
                    renderBitmap.Render(rectangle);
                    renderBitmap.Freeze();
                    line = new Image {
                        Source = renderBitmap
                    };
                }
#else
                var line = CreateLine();
                line.Points = pointCollection;
#endif

                bounds.Union(ithBounds);

                ViewportRectPanel.SetViewportBounds(line, ithBounds);
#if !geom
                ViewportMarginPanel.SetScreenMargin(line, new Size(strokeThickness / 2, strokeThickness / 2));
#endif
                panel.Children.Add(line);

                isUpdating = false;
            }

            panel.EndBatchAdd();

            Debug.WriteLine("OverallCount = " + (overallCount + 1));

            Viewport2D.SetContentBounds(this, bounds);

            isUpdating = false;
        }
 public static Bounds BuildBounds(IEnumerable <Touch> points)
 {
     return(BoundsHelper.BuildBounds(points.Select(p => p.position.ToVector3())));
 }