Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm building a top-view 3ed person shooter. I have a HUD and in the HUD I have a minimap. I'm trying to draw on this minimap a rectangle which shows me my "visual field", meaning i see on the minimap which part of the map I'm currently seeing.

I've nearly achieved this, except for a scaling problem. Here's my code:

float distX = ScreenWidth - Tools.MapToCamera(Camera.pos.X, Camera.pos.Y).X;
float distY = ScreenHeight - Tools.MapToCamera(Camera.pos.X, Camera.pos.Y).Y;

Vector2 topLeft = new Vector2((calcX((Camera.pos.X - distX) / (Bg.Width / Tools.minimap.Width) + Tools.minimap.X)),
            (calcY((Camera.pos.Y - distY) / (Bg.Height / Tools.minimap.Height) + Tools.minimap.Y)));

Vector2 rightBottom = new Vector2 ((calcX((Camera.pos.X + distX) / (Bg.Width / Tools.minimap.Width) + Tools.minimap.X)),
            (calcY((Camera.pos.Y + distY) / (Bg.Height / Tools.minimap.Height) + Tools.minimap.Y)));

Tools.DrawLine(topLeft, new Vector2 (rightBottom.X, topLeft.Y), Color.WhiteSmoke);
Tools.DrawLine(topLeft, new Vector2 (topLeft.X, rightBottom.Y), Color.WhiteSmoke);
Tools.DrawLine(new Vector2 (topLeft.X, rightBottom.Y), rightBottom, Color.WhiteSmoke);
Tools.DrawLine(new Vector2 (rightBottom.X, topLeft.Y), rightBottom, Color.WhiteSmoke);
  • ScreenWidth/ScreenHeight are the current PreferredBackBuffer sizes.
  • Bg means BackGround, contains height/width, etc. of the map.
  • calcX(float num) : multiplies num by the current scale of the HUD.
    • HUD scale is measured by: hudScale = ScreenWidth / hudWidth
  • calcY:
    float calcY(float y) { return y * hudScale + (ScreenHeight - (hudHeight * hudScale)); }

internal static V2 MapToCamera(float X,float Y)
{
    return new V2(X * (Tools.w / Bg.Width), Y * (Tools.h / Bg.Height));
} 

public static void DrawLine(V2 start, V2 end, Color clr)
{
    sb.Draw(pointTex,start, null, clr,(float)Math.Atan2(end.X - start.X, start.Y - end.Y),
        new V2(0.5f, 1), new V2(1, (start - end).Length()), SpriteEffects.None,0);
}
  • pointTex = new Texture2D(gd, 1, 1); (Color set: White)

These are all the functions in use.
The end result is a rectangular frame around my position on the minimap. It follows me and i'm mostly in it's center.

The problem is, this rectangle comes out about twice larger than it should be.

Anyone care to help me with this?

P.S: I don't use any scaling on the map or the other sprites. Scaling is done only on the HUD and it's objects. Although, I use a zoom factor for my Camera class.

Thanks in advance.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.