1
$\begingroup$

What would be the best way to make a texture a clickable button? Suppose I have a Room (respresented by a 2D texture), where there are buttons.

Would I in the main loop:

  • check when the mouse is clicked if it is in any region of a button? ($\mathcal{O}(n_{Button})$)

  • Do something entirely different that I can't think of?

I may be overthinking this, maybe this isn't a problem at all, but somehow, what I came up with sounds way to "stupid" to me to be the right solution. It sounds like a hack to me, but maybe this is the way to do it? In 3D Games, would the check than be just radial coordinates ($r,\phi,\theta$)?

$\endgroup$

1 Answer 1

3
$\begingroup$

In games and other 3D scenes, generally when the user clicks the mouse, a ray is cast into the scene in the direction the camera is facing, and a check is done to see what geometry in the scene it intersects. If it intersects nothing, it is ignored. If it intersects a single object, then the application processes a click on that object (at the location of the intersection). If more than one object is intersected, then usually the front-most object is assumed to be the on the user wanted to click on, so that is processed.

In general, geometry is stored using x,y,z coordinates rather than spherical coordinates, as the GPU hardware works in cartesian coordinates.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.