Download

Coordinate System for GetMouseLocation ?

Good morning guys,

I was wondering, how does the coordinate system for GetMouseLocation work? Meaning, what is the reference? It clearly has nothing to do with the viewport (the center of the screen being (0,0) and working as the reference), which is basically what I need. So any idea how does it work and, if possible, to get the coordinates relative to the center of the screen only?

The origin is the upper left corner. So to get the center you have to take the views width and height into account. The center of the screen is at position (Width/2.f, Height/2.f). So if you want to have that one as your origin you have to transform if from that position subtracting the origin. For example:

You have a screen size of 8x8 (width x height). The center is so the point C(4,4) while the origin is still O(0,0) which is the upper left corner. Now you get a mouse location of A(1,2) relative to the upper left corner C(0,0). To transform it to be relative to the center just subtract the center from that point (the new origin): A’ = A - C = (-3, -2) which is exactly the relative from the point C if we take it as the new origin.

You could also flip the vertical (Y axis) in case you have to. You can get the Viewport size from any PlayerControler with a function called GetViewportSize (or similar :D).

Thank you Moss for taking the time, I will give it a try as soon as I get home!

Gracias =)

Np mate :smiley:

De nada ^^ Nicht der Rede wert! (I’m actually German hahaha)