Esempio n. 1
0
    public static Vector3 CreateVisualization(GameObject selectedUnit, GameObject visualizationPrefab)
    {
        RaycastHit hit;

        if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 60, ~LayerMask.GetMask("Ignore Raycast")))
        {
            return(Vector3.zero);
        }
        Vector3 target = new Vector3(hit.point.x, selectedUnit.transform.position.y, hit.point.z);

        if (Vector3.Distance(selectedUnit.transform.position, target) < .6f || Physics.Raycast(selectedUnit.transform.position, target - selectedUnit.transform.position, .6f))
        {
            return(Vector3.zero);
        }

        List <Vector3> points = new List <Vector3>();
        Ray            ray    = new Ray(selectedUnit.transform.position + .749f * Vector3.down, target - selectedUnit.transform.position);

        for (int i = 0; i < 20; i++)
        {
            if (Physics.SphereCast(ray, .25f, .5f))
            {
                break;
            }
            ray.origin += .5f * ray.direction.normalized;
            if (!Physics.Raycast(ray.origin, Vector3.down, .3f))
            {
                break;
            }
            points.Add(ray.origin);
        }
        VisualizationHelper.ProjectileVisualization(points.ToArray(), visualizationPrefab);
        return(target - selectedUnit.transform.position);
    }
        private void GenerateGridDiagram()
        {
            GridCanvas.Children.Clear();
            Random r = new Random();

            int totalItems;

            if (!Int32.TryParse(ItemCount.Text, out totalItems))
            {
                totalItems = 5;
            }

            int cellSize;

            if (!Int32.TryParse(CellSize.Text, out cellSize))
            {
                cellSize = 100;
            }

            var spatialGrid = new SpatialGrid <TestObject>(new Point(0, 0), (int)GridCanvas.Width, (int)GridCanvas.Height, cellSize);

            //for (int i = 0; i < totalItems; i++)
            //    quadTree.Insert(new TestObject(r, QuadCanvas));

            foreach (var cell in spatialGrid.Cells)
            {
                VisualizationHelper.DrawRectangle(r, GridCanvas, cell.Location, cell.Size, cell.Size);
            }
            //foreach (var node in quadTree.Nodes)
            //    VisualizationHelper.DrawRectangle(r, QuadCanvas, node.Location, node.Width, node.Height);
        }
Esempio n. 3
0
        private void GenerateQuadTreeDiagram()
        {
            QuadCanvas.Children.Clear();
            Random r = new Random();

            int propagationThreshold;

            if (!Int32.TryParse(Threshold.Text, out propagationThreshold))
            {
                propagationThreshold = 2;
            }

            int totalItems;

            if (!Int32.TryParse(ItemCount.Text, out totalItems))
            {
                totalItems = 10;
            }

            quadTree = new QuadTree <TestObject>(propagationThreshold, new Point(0, 0), (float)QuadCanvas.Width, (float)QuadCanvas.Height);

            for (int i = 0; i < totalItems; i++)
            {
                quadTree.Insert(new TestObject(r, QuadCanvas));
            }

            foreach (var node in quadTree.Nodes)
            {
                VisualizationHelper.DrawRectangle(r, QuadCanvas, node.Location, node.Width, node.Height);
            }

            QuadCanvas.Children.Add(visualisationRectangle);
        }
Esempio n. 4
0
 void resetActionTarget()
 {
     ghost.SetActive(false);
     line1.positionCount = 0;
     line2.positionCount = 0;
     VisualizationHelper.ResetVisualization();
 }
Esempio n. 5
0
 private void tmrRefreshList_Tick(object sender, EventArgs e)
 {
     if (VisualizationHelper.CheckData(ref settings))
     {
         gvGrid.DataSource = VisualizationHelper.GridSource;
         VisualizationHelper.UpdateMarkers(mapOverlays);
         mapControl.Refresh();
     }
 }
    public static Vector3 CreateVisualization(GameObject selectedUnit, GameObject visualizationPrefab)
    {
        RaycastHit hit;

        Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);
        Vector3 target = new Vector3(hit.point.x, selectedUnit.transform.position.y, hit.point.z);

        if (Vector3.Distance(selectedUnit.transform.position, target) < .6f || Physics.Raycast(selectedUnit.transform.position, target - selectedUnit.transform.position, .6f))
        {
            return(target);
        }

        float          visualizationDistance   = 10;
        float          visualizationSeparation = 0.5f;
        Vector3        nextDestination;
        List <Vector3> points           = new List <Vector3>();
        Vector3        previousPoint    = selectedUnit.transform.position;
        float          distanceTraveled = 0;
        Vector3        nextDirection    = target - selectedUnit.transform.position;

        if (Physics.Raycast(selectedUnit.transform.position, nextDirection, out hit, (visualizationDistance + 1)))
        {
            nextDestination = hit.point;
            nextDirection   = Vector3.Reflect(nextDirection, hit.normal);
        }
        else
        {
            nextDestination = selectedUnit.transform.position + nextDirection.normalized * (visualizationDistance + 1);
        }

        while (distanceTraveled < visualizationDistance)
        {
            float tempDistance = 0;
            while (Vector3.Distance(previousPoint, nextDestination) < visualizationSeparation - tempDistance)
            {
                tempDistance += Vector3.Distance(previousPoint, nextDestination);
                Ray dirRay = new Ray(nextDestination, nextDirection);
                previousPoint = nextDestination;
                if (Physics.Raycast(dirRay, out hit, (visualizationDistance + 1) - distanceTraveled))
                {
                    nextDestination = hit.point;
                    nextDirection   = Vector3.Reflect(nextDirection, hit.normal);
                }
                else
                {
                    nextDestination = dirRay.GetPoint((visualizationDistance + 1) - distanceTraveled);
                }
            }
            points.Add(Vector3.MoveTowards(previousPoint, nextDestination, visualizationSeparation - tempDistance));
            previousPoint     = points[points.Count - 1];
            distanceTraveled += visualizationSeparation;
        }
        VisualizationHelper.ProjectileVisualization(points.ToArray(), visualizationPrefab);
        return(target - selectedUnit.transform.position);
    }
Esempio n. 7
0
 private void frmMain_Load(object sender, EventArgs e)
 {
     lblVersion.Text        = $"Version: {Application.ProductVersion}";
     tmrRefreshList.Enabled = true;
     mapControl.MapProvider = GMapProviders.YandexMap;
     mapControl.ScaleMode   = ScaleModes.Fractional;
     mapControl.MinZoom     = 0;
     mapControl.MaxZoom     = 24;
     mapControl.Zoom        = 2;
     mapControl.Overlays.Add(mapOverlays);
     PcapHelper.CurrentAppForm = this;
     PcapHelper.FillDeviceDropDownList(cbDevice);
     gvRecords.DataSource = PcapHelper.PacketDataSource;
     if (VisualizationHelper.CheckData(ref settings))
     {
         gvGrid.Columns.Clear();
         gvGrid.DataSource = VisualizationHelper.GridSource;
         VisualizationHelper.UpdateMarkers(mapOverlays);
     }
     //for now until al bugs are fixed, I'll hide it, and settings menu button too
     tcMain.TabPages.Remove(tabPacketSniffer);
     mnuSettings.Visible = false;
 }
Esempio n. 8
0
    public static Vector3 CreateVisualization(GameObject selectedUnit, GameObject visualizationPrefab, float power)
    {
        RaycastHit hit;

        if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 60, ~LayerMask.GetMask("Ignore Raycast")))
        {
            return(Vector3.zero);
        }
        Vector3 target = hit.point;

        if (Vector3.Distance(selectedUnit.transform.position, target) < 1.3f)
        {
            return(Vector3.zero);
        }

        float g     = Physics.gravity.magnitude;
        float h     = target.y - selectedUnit.transform.position.y;
        float d     = Vector2.Distance(new Vector2(selectedUnit.transform.position.x, selectedUnit.transform.position.z), new Vector2(target.x, target.z));
        float step1 = Mathf.Pow(power, 4) - g * (g * Mathf.Pow(d, 2) + 2 * h * Mathf.Pow(power, 2));

        if (step1 < 0)
        {
            float upperbound   = d;
            float lowerbound   = 0;
            Ray   directionRay = new Ray(new Vector3(selectedUnit.transform.position.x, 0, selectedUnit.transform.position.z), new Vector3(target.x, 0, target.z) - new Vector3(selectedUnit.transform.position.x, 0, selectedUnit.transform.position.z));
            int   ii           = 0;
            while ((Mathf.Abs(step1) > 10 || step1 < 0) && ii < 100)
            {
                Vector3 nextTest = directionRay.GetPoint((upperbound + lowerbound) / 2);
                Physics.Raycast(new Vector3(nextTest.x, 20, nextTest.z), Vector3.down, out hit);
                h     = hit.point.y - selectedUnit.transform.position.y;
                d     = Vector2.Distance(new Vector2(selectedUnit.transform.position.x, selectedUnit.transform.position.z), new Vector2(hit.point.x, hit.point.z));
                step1 = Mathf.Pow(power, 4) - g * (g * Mathf.Pow(d, 2) + 2 * h * Mathf.Pow(power, 2));
                if (step1 > 0)
                {
                    lowerbound = (upperbound + lowerbound) / 2;
                    if (upperbound - lowerbound < .01f)
                    {
                        nextTest = directionRay.GetPoint(upperbound);
                        Physics.Raycast(new Vector3(nextTest.x, 20, nextTest.z), Vector3.down, out hit);
                        lowerbound = h;
                        upperbound = hit.point.y - selectedUnit.transform.position.y;
                        while ((Mathf.Abs(step1) > 10 || step1 < 0) && ii < 100)
                        {
                            h     = (upperbound + lowerbound) / 2;
                            step1 = Mathf.Pow(power, 4) - g * (g * Mathf.Pow(d, 2) + 2 * h * Mathf.Pow(power, 2));
                            if (step1 > 0)
                            {
                                lowerbound = h;
                            }
                            else
                            {
                                upperbound = h;
                            }
                            ii++;
                        }
                        target = hit.point;
                        break;
                    }
                }
                else
                {
                    upperbound = (upperbound + lowerbound) / 2;
                }
                ii++;
            }
        }
        float angle1 = Mathf.Atan((Mathf.Pow(power, 2) + Mathf.Sqrt(step1)) / (g * d));
        float angle2 = Mathf.Atan((Mathf.Pow(power, 2) - Mathf.Sqrt(step1)) / (g * d));

        if (angle2 > angle1)
        {
            angle1 = angle2;
        }
        float          distance   = 0;
        List <Vector3> points     = new List <Vector3>();
        Vector2        groundCord = new Vector2(selectedUnit.transform.position.x, selectedUnit.transform.position.z);
        RaycastHit     sphereHit;

        while (groundCord != new Vector2(target.x, target.z))
        {
            float y = Mathf.Tan(angle1) * distance - ((g * Mathf.Pow(distance, 2)) / (Mathf.Pow(power, 2) * (Mathf.Cos(2 * angle1) + 1)));
            points.Add(new Vector3(groundCord.x, y + selectedUnit.transform.position.y, groundCord.y));
            if (points.Count > 1 && Physics.SphereCast(points[points.Count - 2], 0.25f, points[points.Count - 1] - points[points.Count - 2], out sphereHit, Vector3.Distance(points[points.Count - 2], points[points.Count - 1])))
            {
                break;
            }
            distance += .2f;

            groundCord = Vector2.MoveTowards(new Vector2(selectedUnit.transform.position.x, selectedUnit.transform.position.z), new Vector2(target.x, target.z), distance);
        }
        VisualizationHelper.ProjectileVisualization(points.ToArray(), visualizationPrefab);
        return(Vector3.RotateTowards(new Vector3(target.x - selectedUnit.transform.position.x, 0, target.z - selectedUnit.transform.position.z), Vector3.up, angle1, 1));
    }
        private Grid MakeContentSub(string Header, GraphElement value)
        {
            var ret = new Grid()
            {
                VerticalAlignment   = VerticalAlignment.Stretch,
                HorizontalAlignment = HorizontalAlignment.Stretch,
            };

            ret.Children.Add(new VisualStorage <GraphElement>()
            {
                Storage = value
            });
            ret.Children.Add(new Label()
            {
                Background = new SolidColorBrush(
                    value is GraphRoot ? System.Windows.Media.Color.FromRgb(153, 112, 41) :
                    value is GraphShape ? System.Windows.Media.Color.FromRgb(153, 145, 41) :
                    value is GraphTransform ? System.Windows.Media.Color.FromRgb(41, 132, 153) :
                    value is GraphParent ? System.Windows.Media.Color.FromRgb(41, 153, 41)
                                        : Colors.Green),
                VerticalAlignment          = VerticalAlignment.Stretch,
                HorizontalAlignment        = HorizontalAlignment.Stretch,
                VerticalContentAlignment   = VerticalAlignment.Center,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Content = Header,
            });
            ret.MouseMove            += NewElement_MouseMove;
            ret.MouseRightButtonDown += NewElement_MouseRightButtonDown;
            ret.IsHitTestVisible      = true;
            ret.MouseEnter           += (_, me) => {
                if (IsConfig)
                {
                    if (ret.Children.Count == 2)
                    {
                        ret.Children.Add(new Border()
                        {
                            BorderBrush     = LightRed,                        //new SolidColorBrush(Colors.Red),
                            BorderThickness = new Thickness(1)
                        });
                    }
                }
            };
            ret.MouseLeave += (_, me) => {
                if (ret.Children.Count == 3)
                {
                    if (((ret.Children[2] as Border).BorderBrush as SolidColorBrush).Color == Colors.Red)
                    {
                    }
                    else
                    {
                        ret.Children.RemoveAt(2);
                    }
                }
            };
            ret.MouseLeftButtonDown += (_, me) => {
                if (IsConfig)
                {
                    foreach (Label lb in Graph.Children)
                    {
                        if (lb.Content != null)
                        {
                            var c = (lb.Content as Grid).Children;
                            if (c.Count == 3)
                            {
                                c.RemoveAt(2);
                            }
                        }
                    }
                    if (ret.Children.Count == 2)
                    {
                        ret.Children.Add(new Border()
                        {
                            BorderBrush     = LightRed,
                            BorderThickness = new Thickness(1)
                        });
                    }
                    (ret.Children[2] as Border).BorderBrush = new SolidColorBrush(Colors.Red);
                    spProperties.Children.Clear();
                    //if (scea.AddedItems.Count == 0) {
                    //	spProperties.Children.Add(new TextBlock() {
                    //		Foreground = white,
                    //		TextWrapping = TextWrapping.Wrap,
                    //		Text = "No Element Selected"
                    //	});
                    //	return;
                    //}
                    if (value is GraphShape gs)
                    {
                        VisualizationHelper.AddToSP(spProperties, visHelper.VisualizeObject(gs.Shape, null, true));
                    }
                    else if (value is GraphTransform gt)
                    {
                        VisualizationHelper.AddToSP(spProperties, visHelper.VisualizeObject(gt.trans, null, true));
                    }
                    else
                    {
                        VisualizationHelper.AddToSP(spProperties, visHelper.VisualizeObject(value, null, true));
                    }
                }
            };
            return(ret);
        }