So you have screen width and screen height as integers, correct? And you want this to be converted to between 0 and 1?
Why not just do something like this:
When you have a screen coordinate, you just need to divide the value by the total width and height to get a percentage (a number between 0 and 1). So if you are at 400, 300 position on 800x600 screen, the value will be 0.5, 0.5.
To go from 0.5 back to real screen coordinates, just multiply instead of dividing.
The below code is untested and just written in the forum without any IDE or testing/debugging, so YMMV.
int screenWidth; //init this somewhere
int screenHeight; //init this somewhere
public float GetLocalWidthFromScreenX(int screenX)
{
float myWidth = screenX / screenWidth;
return myWidth;
}
public float GetLocalHeightFromScreenY(int screenY)
{
float myHeight = screenY / screenHeight;
return myHeight ;
}
public Vector2 GetLocalCoordinateFromScreenCoordinates(Point screenXY)
{
return new Vector2( GetLocalWidthFromScreenX(screenXY.X), GetLocalHeightFromScreenY(screenXY.Y) );
}
-----------------------------------------------
Jim Welch