Exemplo n.º 1
0
        private Matrix GetMarkerRenderMatrix(MapMarker marker)
        {
            float   sx = 1.0f, sy = 1.0f;
            MapIcon ic  = marker.Icon;
            int     icw = ic.TexWidth;
            int     ich = ic.TexHeight;

            if (icw > ich) //shrink square vertically
            {
                sy = ((float)ich) / ((float)icw);
            }
            else //shrink square horizontally
            {
                sx = ((float)icw) / ((float)ich);
            }

            sx *= ic.Scale;
            sy *= ic.Scale;


            float px = marker.ScreenPos.X - ic.Center.X * ic.Scale;
            float py = marker.ScreenPos.Y - ic.Center.Y * ic.Scale;

            px = (float)Math.Round(px, MidpointRounding.AwayFromZero); //snap to pixels...
            py = (float)Math.Round(py, MidpointRounding.AwayFromZero);


            Matrix scale = Matrix.Scaling(sx, sy, 0.0f);
            Matrix trans = Matrix.Translation(px, py, 0.0f);

            return(Matrix.Multiply(scale, trans));
        }
Exemplo n.º 2
0
        private MapMarker FindMousedMarker()
        {
            float mx = MouseLastPoint.X;
            float my = MouseLastPoint.Y;

            if (ShowLocatorCheckBox.Checked)
            {
                if (IsMapMarkerUnderPoint(LocatorMarker, mx, my))
                {
                    return(LocatorMarker);
                }
            }

            //search backwards through the render markers (front to back)
            for (int i = RenderMarkers.Count - 1; i >= 0; i--)
            {
                MapMarker m = RenderMarkers[i];
                if (IsMapMarkerUnderPoint(m, mx, my))
                {
                    return(m);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        private void MapForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MouseButtonDown = true;
            }
            MouseDownPoint = e.Location;
            MouseLastPoint = MouseDownPoint;

            if (MouseButtonDown)
            {
                if (MousedMarker != null)
                {
                    if (MousedMarker.IsMovable)
                    {
                        GrabbedMarker = MousedMarker;
                    }
                    else
                    {
                        SelectedMarker                = MousedMarker;
                        SelectionNameTextBox.Text     = SelectedMarker.Name;
                        SelectionPositionTextBox.Text = SelectedMarker.Get3DWorldPosString();
                        UpdateSelectionPanel();
                        SelectionPanel.Visible = true;
                    }
                }
                else
                {
                    GrabbedMarker = null;
                    //SelectedMarker = null;
                    //SelectionPanel.Visible = false;
                }
            }
        }
Exemplo n.º 4
0
        private void SetOriginButton_Click(object sender, EventArgs e)
        {
            if (CurrentMap == null)
            {
                return;
            }

            TextureOriginTextBox.Text = TextureCoordTextBox.Text;

            string[] comps = TextureOriginTextBox.Text.Split(',');
            if (comps.Length > 1)
            {
                Vector3 origin = new Vector3(0.0f);
                float.TryParse(comps[0].Trim(), out origin.X);
                float.TryParse(comps[1].Trim(), out origin.Y);
                CurrentMap.Origin = origin;

                RecalculateAllMarkers();

                LocatorMarker.WorldPos   = new Vector3(0.0f); //force to the world origin
                LocatorMarker.TexturePos = origin;
                GrabbedMarker            = LocatorMarker;     //don't force the marker update when updating textbox..
                LocateTextBox.Text       = "0, 0, 0";
                GrabbedMarker            = null;
                WorldCoordTextBox.Text   = LocatorMarker.Get2DWorldPosString();
                TextureCoordTextBox.Text = LocatorMarker.Get2DTexturePosString();
            }
        }
Exemplo n.º 5
0
        private void GoToMarker(MapMarker m)
        {
            //adjust the target to account for the main panel...
            Vector3 view = m.TexturePos;

            view.X += ((float)(MainPanel.Width + 4) * 0.5f) / CurrentZoom;

            TargetViewCenter = view;
        }
Exemplo n.º 6
0
        private bool IsMapMarkerUnderPoint(MapMarker marker, float x, float y)
        {
            float dx  = x - marker.ScreenPos.X;
            float dy  = y - marker.ScreenPos.Y;
            float mcx = marker.Icon.Center.X;
            float mcy = marker.Icon.Center.Y;
            bool  bx  = ((dx >= -mcx) && (dx <= mcx));
            bool  by  = ((dy <= 0.0f) && (dy >= -mcy));

            return(bx && by);
        }
Exemplo n.º 7
0
 private void GoToSelectedMarkerButton_Click(object sender, EventArgs e)
 {
     if (MarkersListView.SelectedItems.Count == 1)
     {
         MapMarker m = MarkersListView.SelectedItems[0].Tag as MapMarker;
         if (m != null)
         {
             GoToMarker(m);
         }
     }
 }
Exemplo n.º 8
0
 private void MarkersListView_DoubleClick(object sender, EventArgs e)
 {
     //go to the marker..
     if (MarkersListView.SelectedItems.Count == 1)
     {
         MapMarker m = MarkersListView.SelectedItems[0].Tag as MapMarker;
         if (m != null)
         {
             GoToMarker(m);
         }
     }
 }
Exemplo n.º 9
0
        private void MapForm_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MouseButtonDown = false;

                GrabbedMarker = null;

                if ((e.Location == MouseDownPoint) && (MousedMarker == null))
                {
                    //was clicked. but not on a marker... deselect and hide the panel

                    SelectedMarker         = null;
                    SelectionPanel.Visible = false;
                }
            }
        }
Exemplo n.º 10
0
        private void AddMarker(string markerstr)
        {
            MapMarker m = new MapMarker();

            m.Parse(markerstr.Trim());
            m.Icon = MarkerIcon;

            UpdateMarkerTexturePos(m);

            Markers.Add(m);

            //////sort by Y
            ////Markers.Sort((m1, m2) => m1.TexturePos.Y.CompareTo(m2.TexturePos.Y));

            ListViewItem lvi = new ListViewItem(new string[] { m.Name, m.WorldPos.X.ToString(), m.WorldPos.Y.ToString(), m.WorldPos.Z.ToString() });

            lvi.Tag = m;
            MarkersListView.Items.Add(lvi);
        }
Exemplo n.º 11
0
        private void SetCoordButton_Click(object sender, EventArgs e)
        {
            if (CurrentMap == null)
            {
                return;
            }

            string[] comps = WorldCoordTextBox.Text.Split(',');
            if (comps.Length > 1)
            {
                Vector3 coord = new Vector3(0.0f);
                float.TryParse(comps[0].Trim(), out coord.X);
                float.TryParse(comps[1].Trim(), out coord.Y);

                //assume the entered coord is the world coord for the locator's tex coord.
                //find the appropriate scaling factor to make it so.

                float tdx = LocatorMarker.TexturePos.X - CurrentMap.Origin.X; //texel dist from origin
                float tdy = LocatorMarker.TexturePos.Y - CurrentMap.Origin.Y;
                float tdl = (float)Math.Sqrt(tdx * tdx + tdy * tdy);

                float wcl = (float)Math.Sqrt(coord.X * coord.X + coord.Y * coord.Y);

                float upt  = wcl / tdl;
                float uptx = upt * Math.Sign(tdx * coord.X);
                float upty = upt * Math.Sign(tdy * coord.Y);

                CurrentMap.UnitsPerTexelX = uptx;
                CurrentMap.UnitsPerTexelY = upty;

                RecalculateAllMarkers();

                LocatorMarker.WorldPos     = coord;
                GrabbedMarker              = LocatorMarker; //don't force the marker update when updating textbox..
                LocateTextBox.Text         = LocatorMarker.ToString();
                GrabbedMarker              = null;
                WorldCoordTextBox.Text     = LocatorMarker.Get2DWorldPosString();
                TextureCoordTextBox.Text   = LocatorMarker.Get2DTexturePosString();
                UnitsPerTexelXTextBox.Text = uptx.ToString();
                UnitsPerTexelYTextBox.Text = upty.ToString();
            }
        }
Exemplo n.º 12
0
 private void UpdateMarkerTexAndScreenPos(MapMarker marker)
 {
     marker.TexturePos = GetTextureCoordFromWorldCoord(marker.WorldPos);
     marker.ScreenPos  = GetScreenCoordFromTextureCoord(marker.TexturePos);
 }
Exemplo n.º 13
0
 private void UpdateMarkerScreenPos(MapMarker marker)
 {
     marker.ScreenPos = GetScreenCoordFromTextureCoord(marker.TexturePos);
 }
Exemplo n.º 14
0
 private void UpdateMarkerTexturePos(MapMarker marker)
 {
     marker.TexturePos = GetTextureCoordFromWorldCoord(marker.WorldPos);
 }
Exemplo n.º 15
0
        public MapForm()
        {
            InitializeComponent();


            Icons = new List <MapIcon>();
            AddIcon("Google Marker", "icon_google_marker_64x64.png", 64, 64, 11.0f, 40.0f, 1.0f);
            AddIcon("Glokon Marker", "icon_glokon_normal_32x32.png", 32, 32, 11.0f, 32.0f, 1.0f);
            AddIcon("Glokon Debug", "icon_glokon_debug_32x32.png", 32, 32, 11.5f, 32.0f, 1.0f);
            MarkerIcon  = Icons[1];
            LocatorIcon = Icons[2];
            foreach (MapIcon icon in Icons)
            {
                MarkerStyleComboBox.Items.Add(icon);
                LocatorStyleComboBox.Items.Add(icon);
            }
            MarkerStyleComboBox.SelectedItem  = MarkerIcon;
            LocatorStyleComboBox.SelectedItem = LocatorIcon;
            LocatorMarker           = new MapMarker();
            LocatorMarker.Icon      = LocatorIcon;
            LocatorMarker.IsMovable = true;


            ////for google map calibration...
            //var game_1_x = 1972.606; //var map_1_lng = -60.8258056640625;
            //var game_1_y = 3817.044; //var map_1_lat = 72.06379257078102;
            //var game_2_x = -1154.11; //var map_2_lng = -72.1417236328125;
            //var game_2_y = -2715.203; //var map_2_lat = 48.41572128171852;

            ////reference point:
            //501.4398, 5603.9600, 795.9738, 0x4CC3BAFC, cs1_10_redeye

            //origin in 8192x8192 textures is at approx:
            //3755.2, 5525.5

            float ox   = 3755.2f;
            float oy   = 5525.5f;
            float uptx = 1.517952f; //this seems pretty close...
            float upty = -1.517952f;

            Images = new List <MapImage>();
            AddImage("Satellite", "gtav_satellite_8192x8192.jpg", 8192, 8192, ox, oy, uptx, upty);
            AddImage("Roads", "gtav_roadmap_8192x8192.jpg", 8192, 8192, ox, oy, uptx, upty);
            AddImage("Atlas", "gtav_atlas_8192x8192.jpg", 8192, 8192, ox, oy, uptx, upty);
            foreach (MapImage mi in Images)
            {
                MapComboBox.Items.Add(mi);
            }

            InitializeDevice();

            if (Images.Count > 0)
            {
                MapImage mi = Images[0];
                MapComboBox.SelectedItem = mi;
                TargetViewCenter         = mi.Origin;
                CurrentViewCenter        = mi.Origin;
            }

            this.MouseWheel += MapForm_MouseMove;

            FrameTimer.Restart();
            SlimDX.Windows.MessagePump.Run(this, new SlimDX.Windows.MainLoop(SlimDX_Render));
        }
Exemplo n.º 16
0
        private void MapForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Delta != 0)
            {
                float zoomfac = 1.0f + 0.1f * ((float)ZoomSpeedUpDown.Value);
                float oldzoom = TargetZoom;
                float newzoom = oldzoom * (e.Delta > 0 ? zoomfac : 1.0f / zoomfac);

                if (newzoom < 1e-2f)
                {
                    newzoom = 1e-2f;
                }
                if (newzoom > 1e4f)
                {
                    newzoom = 1e4f;
                }

                //figure out the new target center based on current mouse pos
                float w  = ClientSize.Width;
                float h  = ClientSize.Height;
                float mx = MouseLastPoint.X - w * 0.5f;
                float my = MouseLastPoint.Y - h * 0.5f;

                Vector3 mpold  = new Vector3(mx, my, 0.0f) / oldzoom;
                Vector3 mpnew  = new Vector3(mx, my, 0.0f) / newzoom;
                Vector3 mpdelt = mpnew - mpold;

                TargetViewCenter -= mpdelt;
                TargetZoom        = newzoom;


                NeedsUpdate = true;
            }
            if (MouseButtonDown)
            {
                float dx = (e.X - MouseLastPoint.X) / CurrentZoom;
                float dy = (e.Y - MouseLastPoint.Y) / CurrentZoom;

                if (GrabbedMarker == null)
                {
                    //pan the view.
                    TargetViewCenter.X -= dx;
                    TargetViewCenter.Y -= dy;
                    NeedsUpdate         = true;
                }
                else
                {
                    //move the grabbed marker...
                    float   uptx = (CurrentMap != null) ? CurrentMap.UnitsPerTexelX : 1.0f;
                    float   upty = (CurrentMap != null) ? CurrentMap.UnitsPerTexelY : 1.0f;
                    Vector3 wpos = GrabbedMarker.WorldPos;
                    wpos.X += dx * uptx;
                    wpos.Y += dy * upty;
                    GrabbedMarker.WorldPos = wpos;
                    UpdateMarkerTexturePos(GrabbedMarker);

                    if (GrabbedMarker == LocatorMarker)
                    {
                        LocateTextBox.Text       = LocatorMarker.ToString();
                        WorldCoordTextBox.Text   = LocatorMarker.Get2DWorldPosString();
                        TextureCoordTextBox.Text = LocatorMarker.Get2DTexturePosString();
                    }
                }
            }


            if (NeedsUpdate)
            {
                //limit to the texture.
                float tvcmaxx = 8192.0f;
                float tvcminx = 0.0f;
                float tvcmaxy = 8192.0f;
                float tvcminy = 0.0f;
                if (!((TargetViewCenter.X > tvcmaxx) && (TargetViewCenter.X < tvcminx)))
                {
                    if (TargetViewCenter.X > tvcmaxx)
                    {
                        TargetViewCenter.X = tvcmaxx;
                    }
                    if (TargetViewCenter.X < tvcminx)
                    {
                        TargetViewCenter.X = tvcminx;
                    }
                }
                if (!((TargetViewCenter.Y > tvcmaxy) && (TargetViewCenter.Y < tvcminy)))
                {
                    if (TargetViewCenter.Y > tvcmaxy)
                    {
                        TargetViewCenter.Y = tvcmaxy;
                    }
                    if (TargetViewCenter.Y < tvcminy)
                    {
                        TargetViewCenter.Y = tvcminy;
                    }
                }
            }


            MouseLastPoint = e.Location;

            MousedMarker = FindMousedMarker();

            if (MousedMarker != null)
            {
                if (MousedMarker.IsMovable)
                {
                    Cursor = Cursors.SizeAll;
                }
                else
                {
                    Cursor = Cursors.Hand;
                }
            }
            else
            {
                Cursor = Cursors.Default;
            }
        }