小地图 线程中的图形绘制问题



>我正在尝试为叠加创建一个小地图。目前雷达部分正在工作,目标以正确的距离围绕中心点旋转。我在打印将小地图固定到屏幕上的图形时遇到问题。除地图之外的所有内容都使用 SlimDx.Direct3D9 库打印到屏幕上,但根据我的研究,基于玩家位置创建子图像的最佳方法是使用图形,此方法避免了克隆位图的 OutOfMemory 异常,并且效率更高。

if (ShowRadar)
{
  //Draw background
  //DrawFilledBox(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, Color.DarkOliveGreen, RadarTransparency);
  RadarCenter = new Vector2(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 125 + 25);
  if (DXTextrureMap != null)
  {
    //Transpose player posistion to map position and create the current mini map image
    x = (int)player_X / 8;// +/- 4000 is max player range /8 = 500 = max map range
    z = (int)player_Z / 8;
    mini = new Rectangle(x, z, 100, 100);
    Graphics g = Graphics.FromImage(originalBitmap);
    g.DrawImage(originalBitmap, mini, new Rectangle((int)this.GameWindowRect.Right - 125, (int)this.GameWindowRect.Top + 125, 100, 100), System.Drawing.GraphicsUnit.Pixel);
  }//the rest works as it should and displays on screen
  if (RadarCenter.Length() > 0f)
  {
    //Display each entity in correct relational position
    foreach (ENTITY entity in Entity)
    {
      Vector2 pointToRotate = new Vector2(entity.Pos.X, entity.Pos.Z);
      Vector2 vector3 = new Vector2(player_X, player_Z);
      pointToRotate = vector3 - pointToRotate;
      float num30 = pointToRotate.Length() * 0.5f;
      num30 = Math.Min(num30, 90f);
      pointToRotate.Normalize();
      pointToRotate = (Vector2)(pointToRotate * num30);
      pointToRotate += RadarCenter;
      pointToRotate = RotatePoint(pointToRotate, RadarCenter, player_D, true);
      if (entity.Type == 0x04 && RadarPlayers)
      {
        DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.SkyBlue);
      }
      if ((entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b) && RadarAggressive)
      {
        DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.Red);
      }
      if ((entity.Type == 0x13 || entity.Type == 0x55) && RadarAnimals)
      {
        DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.LightGreen);
      }
      if ((entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) && RadarVehicles)
      {
        DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.HotPink);
      }
    }
  }
  //Draw radar border
  DrawBoxAbs(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, 1f, Color.Black);
  //Draw radar axis
  DrawLine(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 50, this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 251, 1f, Color.Black);
  DrawLine(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 150, this.GameWindowRect.Right - 24, this.GameWindowRect.Top + 150, 1f, Color.Black);
  //Center point
  DrawFilledBox(RadarCenter.X - 1f, RadarCenter.Y - 1f, 3f, 3f, Color.White);
}

打印图形的正确方法是什么?

当你意识到一个图形绘制它抓取的图像时,也不得不处理一些元素时,这更有意义。是时候让它旋转了,然后也许添加标题。

if (DXTextrureMap != null)
{ 
  DXSprite.Begin(SpriteFlags.None);
  //Transpose player posistion to map position and create the current mini map image
  x = (int)player_X / 4;// +/- 4000 is max player range and  /4 = 1000 = max map range
  z = (int)player_Z / 4;
  mini = new Rectangle(x-78, z-78, 157, 157);
  croppedBitmap = new Bitmap(200, 200);
  using (Graphics grD = Graphics.FromImage(croppedBitmap))
  {
    grD.DrawImage(originalBitmap, new Rectangle(0, 0, 157, 157), mini, GraphicsUnit.Pixel);
  }
  //croppedBitmap = Copy(originalBitmap, mini);
  using (MemoryStream s = new MemoryStream())//s is a MemoryStream
  {
    croppedBitmap.Save(s, System.Drawing.Imaging.ImageFormat.Png);
    s.Seek(0, SeekOrigin.Begin); //must do this, or error is thrown in next line
    currentMinimap = Texture.FromStream(DXDevice, s);
    s.Dispose();
  }
  //croppedImage.Dispose();
  DXSprite.Draw(currentMinimap, new Vector3(100f, 100f, 0f), new Vector3(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 135, 0f), Color.White);
  DXSprite.End();
  currentMinimap.Dispose();
}

相关内容

  • 没有找到相关文章

最新更新