Can't properly scale down mouse coordinates to a smaller RenderTarget

Using the wrong values in normalization (I have no idea what “R” is either).

You normalize/denormalize X against width and Y against height. Your range is 0->width and 0->height.

Single xpos1 = Extra.Normalize(ms.X - r.X, 
    0.0f, 
    (Single)Globals.WindowSize.Width
);
Single ypos1 = Extra.Normalize(ms.Y - r.Y, 
    0.0f, 
    (Single)Globals.WindowSize.Height
);
Single xpos2 = Extra.Denormalize(xpos1, 
    0.0f, 
    (Single)Globals.RenderSize.Width
);
Single ypos2 = Extra.Denormalize(ypos1, 
    0.0f, 
    (Single)Globals.RenderSize.Height
);

I’m not sure what you mean by make the Y value Height?

Mouse coordinates are relative to the top left of the window with Y going down. Usually your world coordinates are the other way around with Y going up. That means to get a world relative Y you have to make the mouse position relative to the screen coordinate system (WindowHeight - MouseY). See the diagram here, part way down on the page - note that the diagram is for viewport coordinates.

If you wanted to get pure viewport coordinates you’d denormalize as Denormalize(x, -1, 1) and Denormalize(y, -1, 1), though depending on mouse basis (ie. flip Y or not, why may have to be Denormalize(y, 1, -1)).

1 Like