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)); }
private void LocatorStyleComboBox_SelectedIndexChanged(object sender, EventArgs e) { MapIcon icon = LocatorStyleComboBox.SelectedItem as MapIcon; if (icon != LocatorIcon) { LocatorIcon = icon; LocatorMarker.Icon = icon; } }
private void MarkerStyleComboBox_SelectedIndexChanged(object sender, EventArgs e) { MapIcon icon = MarkerStyleComboBox.SelectedItem as MapIcon; if (icon != MarkerIcon) { MarkerIcon = icon; foreach (MapMarker m in Markers) { m.Icon = icon; } } }
private void LoadIconTexture(MapIcon mi) { try { if (device != null) { mi.Tex = Texture.FromFile(device, mi.Filepath); } } catch (Exception ex) { MessageBox.Show("Could not load map icon " + mi.Filepath + " for " + mi.Name + "!\n\n" + ex.ToString()); } }
private MapIcon AddIcon(string name, string filename, int texw, int texh, float centerx, float centery, float scale) { string filepath = "maps\\" + filename; try { MapIcon mi = new MapIcon(name, filepath, texw, texh, centerx, centery, scale); Icons.Add(mi); return(mi); } catch (Exception ex) { MessageBox.Show("Could not load map icon " + filepath + " for " + name + "!\n\n" + ex.ToString()); } return(null); }
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)); }
private void SlimDX_Render() { if (device == null) { return; } if (LoadingImages) { return; } device.Clear(ClearFlags.Target, new Color4(BackColor), 1.0f, 0); device.BeginScene(); device.SetRenderState(RenderState.AlphaBlendEnable, true); device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); if (NeedsUpdate) { } if ((CurrentMap != null) && (CurrentMap.Tex != null)) { float smooth = 1.0f - (((float)SmoothingUpDown.Value) * 0.9f); float elapsed = (float)Math.Min(FrameTimer.Elapsed.TotalSeconds, 0.1); CurrentZoom = CurrentZoom + (TargetZoom - CurrentZoom) * smooth; CurrentViewCenter = CurrentViewCenter + (TargetViewCenter - CurrentViewCenter) * smooth; float w = ClientSize.Width; float h = ClientSize.Height; Matrix scale = Matrix.Scaling(CurrentZoom, CurrentZoom, 0.0f); Matrix trans = Matrix.Translation(-CurrentViewCenter); Matrix offset = Matrix.Translation(w * 0.5f, h * 0.5f, 0.0f); Matrix matrix = Matrix.Multiply(Matrix.Multiply(trans, scale), offset); sprite.Begin(SpriteFlags.None); sprite.Transform = matrix; sprite.Draw(CurrentMap.Tex, Color.White); sprite.End(); sprite.Begin(SpriteFlags.None); sprite.Transform = Matrix.Identity; //sort by Y to make markers look correct RenderMarkers.Clear(); RenderMarkers.AddRange(Markers); RenderMarkers.Sort((m1, m2) => m1.TexturePos.Y.CompareTo(m2.TexturePos.Y)); //draw all the markers foreach (MapMarker m in RenderMarkers) { if ((m.Icon != null) && (m.Icon.Tex != null)) { UpdateMarkerScreenPos(m); sprite.Transform = GetMarkerRenderMatrix(m); sprite.Draw(m.Icon.Tex, Color.White); } } //draw the locator marker MapIcon locic = LocatorMarker.Icon; if ((ShowLocatorCheckBox.Checked) && (locic != null) && (locic.Tex != null)) { UpdateMarkerScreenPos(LocatorMarker); sprite.Transform = GetMarkerRenderMatrix(LocatorMarker); sprite.Draw(locic.Tex, Color.White); } sprite.End(); } device.EndScene(); device.Present(); if (SelectedMarker != null) { UpdateSelectionPanel(); } FrameTimer.Restart(); }