Quantcast
Channel: D3Scene
Viewing all articles
Browse latest Browse all 21080

Unit x,y to minimap x,y (Different screen sizes)

$
0
0
Hi guys,

I am trying to update my SC2 code that I wrote a while ago, mainly with help from RHCP's autoit source. I have this minimap code which works but it does not align the units properly on the minimap, does anyone have any tips on how to make this code work correctly for my resolution (1920 x 1200) ? possibly would be cool to have it handle any resolution too.

Thanks!

Code:

unsigned int GetMapLeft(HANDLE Process) //Might return float?
{
    unsigned int A = 0;
    DWORD N;
    ReadProcessMemory(Process, (LPCVOID)O_mLeft, &A, sizeof(unsigned int), &N);
    return A / 4096;
}


unsigned int GetMapBottom(HANDLE Process)
{
    unsigned int A = 0;
    DWORD N;
    ReadProcessMemory(Process, (LPCVOID)O_mBottom, &A, sizeof(unsigned int), &N);
    return A / 4096;
}


unsigned int GetMapRight(HANDLE Process)
{
    unsigned int A = 0;
    DWORD N;
    ReadProcessMemory(Process, (LPCVOID)O_mRight, &A, sizeof(unsigned int), &N);
    return A / 4096;
}


unsigned int GetMapTop(HANDLE Process)
{
    unsigned int A = 0;
    DWORD N;
    ReadProcessMemory(Process, (LPCVOID)O_mTop, &A, sizeof(unsigned int), &N);
    return A / 4096;
}


void Minimap::Init(HANDLE Process, unsigned int iScreenWidth, unsigned int iScreenHeight)
{
    MapLeft  = GetMapLeft(Process);
    MapRight  = GetMapRight(Process);   
    MapTop    = GetMapTop(Process);
    MapBottom = GetMapBottom(Process);


    float TenEighty = 1200.0f;
   
    ScreenLeft          = (29.0f/1920.0f)  * iScreenWidth;
    ScreenBottom    = (1066.0f/TenEighty) * TenEighty;
    ScreenRight        = (289.0f/1920.0f)  * iScreenWidth;
    ScreenTop          = (807.0f/TenEighty)  * TenEighty;
   
    ScreenWidth      = ScreenRight  - ScreenLeft; //Minimap LED screen
    ScreenHeight      = ScreenBottom - ScreenTop;  //Minimap LED screen
    MapPlayableWidth  = MapRight    - MapLeft;    //In game coords of the map extents?
    MapPlayableHeight = MapTop      - MapBottom;  //In game coords of the map extents?


    First = false;


    if(MapPlayableWidth >= MapPlayableHeight)
    {
        Scale = ScreenWidth / MapPlayableWidth;
        X_Offset = 0;
        ScreenLeft = ScreenLeft + X_Offset;
        Y_offset = (ScreenHeight - Scale * MapPlayableHeight) / 2;
        ScreenTop = ScreenTop + Y_offset;
        ScreenBottom = ScreenBottom - Y_offset;
        Height = ScreenBottom - ScreenTop;
        Width = ScreenWidth;


        First = true;
    }
    else
    {
        Scale = ScreenHeight / MapPlayableHeight;
        X_Offset = (ScreenWidth - Scale * MapPlayableWidth) / 2;
        ScreenLeft = ScreenLeft + X_Offset;
        ScreenRight = ScreenRight - X_Offset;   
        Y_offset = 0;
        ScreenTop = ScreenTop + Y_offset;
        ScreenBottom = ScreenBottom - Y_offset;
        Height = ScreenHeight;
        Width = ScreenRight - ScreenLeft;


        First = false;
    }   
 }


int GlobalAdderX = -15;
int GlobalAdderY =  90;


void Minimap::GetUnitMinimapXY(unsigned int UnitX, unsigned UnitY, unsigned int& Xvar, unsigned int& Yvar)
{
    float uX = UnitX;
    float uY = UnitY;


    uX -= MapLeft;
    uY -= MapBottom; //correct units position as mapleft/start of map can be >0
    Xvar = ScreenLeft + (uX / MapPlayableWidth * Width);
    Yvar = ScreenBottom - (uY / MapPlayableHeight * Height); //think about rounding mouse clicks igornore decimals


    Xvar += GlobalAdderX;
    Yvar += GlobalAdderY; //To adjust to 1920x1200 from 1920x1080
}


struct MINIMAP_COORD
{
    unsigned int X, Y;
};


const float UnitRadius = 5;
const float BaseRadius = 10;


RECT GetRECT(unsigned int MX, unsigned int MY, bool Unit)
{
    RECT R;


    if(Unit)
    {
        R.left  = MX - UnitRadius;
        R.right  = MX + UnitRadius;
        R.top    = MY - UnitRadius;
        R.bottom = MY + UnitRadius;
    }
    else
    {
        R.left  = MX - BaseRadius;
        R.right  = MX + BaseRadius;
        R.top    = MY - BaseRadius;
        R.bottom = MY + BaseRadius;
    }


    return R;
}


Viewing all articles
Browse latest Browse all 21080

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>