Logic for finding an object under the cursor on the screen

I want to know the general logic to find the display object under the dot.

Let there be various figures on the screen, and I want to find the figure (or figures) at some point, possibly the point of the mouse cursor. If all these shapes are rectangles, this will be a trivial question. But what about triangles and ovals and ...

In other words, what is the general logic of any gui systems that detect which object is clicked or under the cursor? Or, what is the logic of games that detect which character is pressed or under the cursor?

Probably this question was asked before, but I could not find.

edit) At least I want to know a two-dimensional pixel based algorithm. I found Point-in-polygon there , but this is not about ovals and other irregular shapes.

+3
source share
1 answer

It's a little wide ... the general logic is to use the API of what you interact with.

This may vary depending on what you are dealing with - the general logic will be completely different for a 3D application compared to a 2D window system. Again, if you are dealing with a 2D application, this is a full-screen application, so you only need to consider the absolute values ​​of X, Y - or this is under the window system, in which case you are more interested in X, Y relative to the window, unlike everything screen.

+1
source

Source: https://habr.com/ru/post/1773940/


All Articles