Esempio n. 1
0
        /// <summary>
        /// translate a position over the image to the location on the original image
        /// </summary>
        /// <param name="c">The c.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <returns></returns>
        public static Tuple <int, int> GetRealPos(Control c, int x, int y)
        {
            //get actual image end pos
            var v21 = new Vector(c.BackgroundImage.Width, c.BackgroundImage.Height);
            var mm2 = MathExtras.ConvertMatrix(GetMatrix(c));
            var v22 = Vector.Multiply(v21, mm2);

            //if cursor is outside, ignore
            if (x > v22.X || y > v22.Y)
            {
                return(null);
            }

            //get percentages
            var px = x / v22.X;
            var py = y / v22.Y;

            //get original image translated pos
            var ox = c.BackgroundImage.Width * px;
            var oy = c.BackgroundImage.Height * py;

            var oxi = (int)Math.Round(ox);
            var oyi = (int)Math.Round(oy);

            return(new Tuple <int, int>(oxi, oyi));
        }
Esempio n. 2
0
        public static void SetChart(Dictionary <string, int> rawValues, Chart chart)
        {
            int fmin = 0;
            int fmax = 1;

            if (rawValues.Count > 0)
            {
                fmax = rawValues.Max(x => x.Value);
                fmin = rawValues.Min(x => x.Value);
            }

            //series init
            chart.Series.Clear();
            //   chart.Tag = values;
            var s = new Series();

            s.ChartType = SeriesChartType.Bar;

            foreach (var kvp in rawValues)
            {
                s.Points.AddXY(kvp.Key, kvp.Value);
                var dpc = s.Points[s.Points.Count - 1];
                dpc.Color   = ColorExtras.GetRedGreenBlendedColour(kvp.Value, 0, fmax);
                dpc.ToolTip = kvp.Key + ":" + kvp.Value;
            }

            s.YAxisType         = AxisType.Primary;
            s.XAxisType         = AxisType.Secondary;
            s.IsVisibleInLegend = false;
            chart.Series.Add(s);
            //chartarea init
            chart.ChartAreas.Clear();
            var ca = new ChartArea();

            //  ca.CursorX.IsUserEnabled = true;
            // ca.CursorX.IsUserSelectionEnabled = true;

            ca.AxisX2.ScrollBar.IsPositionedInside = false;
            ca.AxisX2.ScaleView.Size     = zoomMax;
            ca.AxisX2.ScaleView.Position = rawValues.Count - ca.AxisX2.ScaleView.Size;

            ca.AxisX2.Interval = 1;
            ca.AxisY.Interval  = MathExtras.Ceiling((Math.Abs(fmax) - Math.Abs(fmin)) / 8);
            if (ca.AxisY.Interval < 1)
            {
                ca.AxisY.Interval = 1;
            }

            ca.AxisY.Minimum = fmin;
            ca.AxisY.Maximum = fmax;
            if (Math.Abs(ca.AxisY.Minimum - ca.AxisY.Maximum) < 1)
            {
                ca.AxisY.Minimum--;
            }

            s.Sort(PointSortOrder.Ascending);
            chart.ChartAreas.Add(ca);
        }
        /// <summary>
        /// Returns the direction that most closely matches the input.
        ///
        /// This can be used to get the primary magnitude intercardinal direction
        /// from an origin point to an event point, such as a mouse click on a grid.
        ///
        /// If the point given is exactly on a boundary between directions then the direction clockwise is returned.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static Direction GetOctalDirection(int x, int y)
        {
            if (x == 0 && y == 0)
            {
                return(Direction.None);
            }

            double degree = MathExtras.ToDegrees(x, y);

            degree += 450; //rotate to all positive and 0 is up
            degree %= 360; //normalize
            if (degree < 22.5)
            {
                return(Direction.Up);
            }
            else if (degree < 67.5)
            {
                return(Direction.UpRight);
            }
            else if (degree < 112.5)
            {
                return(Direction.Right);
            }
            else if (degree < 157.5)
            {
                return(Direction.DownRight);
            }
            else if (degree < 202.5)
            {
                return(Direction.Down);
            }
            else if (degree < 247.5)
            {
                return(Direction.DownLeft);
            }
            else if (degree < 292.5)
            {
                return(Direction.Left);
            }
            else if (degree < 337.5)
            {
                return(Direction.UpLeft);
            }
            else
            {
                return(Direction.Up);
            }
        }
Esempio n. 4
0
    // ////////////
    #region Map Builder
    // ////////////

    /// <summary>
    /// Builds the map
    /// </summary>
    /// <param name="height">Height of the map</param>
    /// <returns>success</returns>
    public bool BuildMap(int height)
    {
        // Progress stats
        m_currentTask  = "Building Map";
        m_taskTotal    = 0;
        m_taskProgress = 0;

        float partDiagonalLength = MathExtras.CalculateDiagonalOfSquare(m_groundPrefab.transform.localScale.x);
        float partHeight         = m_groundPrefab.transform.localScale.y;

        for (int r = height; r >= 0; r--)
        {
            // Calculate Y pos
            float newPosY = partHeight * r + (partHeight * 0.5f);

            // Calculate Z pos
            float newPosZ = (partDiagonalLength * 0.5f) * (height - r);

            float rowLength = partDiagonalLength * (height - r);

            for (int c = 0; c < (height - r); c++)
            {
                // Calculate X pos
                // TODO: It's still off centered!
                float newPosX = -(rowLength * 0.5f) + (partDiagonalLength * c);

                // Build new part
                GameObject newGroundPart = Instantiate(m_groundPrefab) as GameObject;
                newGroundPart.transform.position    = new Vector3(newPosX, newPosY, newPosZ);
                newGroundPart.transform.eulerAngles = new Vector3(0.0f, 45.0f, 0.0f);
                newGroundPart.transform.SetParent(m_mapFolder);

                // Add part in list for future reference
                m_mapParts.Add(newGroundPart);

                BlockInfo newBlockInfo = newGroundPart.GetComponent <BlockInfo>();
                if (newBlockInfo)
                {
                    m_mapInfo.Add(newBlockInfo);
                }
            }
        }

        return(true);
    }