Get world coordinates by pressing a map?

Can you get world coordinates by pressing on a minimap that’s rendered using

render.RenderView and how do you do it?

Depends on the implementation, but the centre of the minimap is going to be equal to the player’s position. From that, along with the distance one map unit is in the world, you can determine the clicked position.

[editline]September 29th, 2017[/editline]

This is under the assumption that this is drawn in a 2D context.

[lua]
– args:
– rv = RenderView table
– x,y = click coords relative to the viewbox, with 0,0 being the top-left corner

local function onClickViewBox(rv,x,y)
local fov = rv.fov or LocalPlayer():GetFOV()
local fwd = util.AimVector( rv.angles, fov, x,y,rv.w,rv.h )

local tr = util.TraceLine({
	start=rv.origin,
	endpos=rv.origin+fwd*32768,
	mask=MASK_NPCWORLDSTATIC
})
return tr.HitPos

end
[/lua]

Something like that.

For this thing I plan on having the map view in the center of the actual map. But how would I do the math for it? And it is in a 2D context.

Pseudocode:


local function 2DToWorld(x, y, xmax, ymax, flScale, vOrigin)
   return vOrigin + Vector((x - xmax/2) * flScale, (y - ymax/2) * flScale)
end

Where x = The x-coordinate of the click
y = The y-coordinate of the click
xmax = Max x-coordinate (width)
ymax = Max y-coordinate (height)
flScale = Number of world units each map unit represents. This will depends on how far out your map is drawn
vOrigin = Position of the player. This should coordinate to the centre of the minimap but in the world