help calculating

E43dddef16529bb248e98b88a1098460
0
john_lin 101 Dec 19, 2012 at 21:49

http://www.gamedev.net/topic/636063-help-calculating-this/

Hi guys ,
Please check the above link . I don’t know how to post images here . Any one know how to calculate this and solve this issuel.Thanks in advance.

john lin

5 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 19, 2012 at 22:01

This type of problem is called “unprojection”, “ray casting”, or “picking”. Googling for those terms will probably provide you some useful links.

The basic idea is to use the mouse click position to generate a ray in the 3D world space. It will start at the camera and pass through the pixel you clicked. Then you find where the ray intersects the scene. In your case you’d do a ray-plane intersection with the ground plane, and use the coordinates of the intersection point to tell which tile was clicked.

E43dddef16529bb248e98b88a1098460
0
john_lin 101 Dec 20, 2012 at 05:06

@reedbeta thanks for your reply . I have to do it in 2D space so ray cast is not possible . Is there any way to take mouse click position and calculate this to get in return which tile is selected ? ex: (0,0) for Top_Left tile . thank you

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 20, 2012 at 06:03

If you define a 2D polygon for the outline of each tile in the image, you can use a point-in-polygon test (google it) to see whether the mouse is over a given tile.

E43dddef16529bb248e98b88a1098460
0
john_lin 101 Dec 20, 2012 at 21:13

thank you for response reedbeta

how the peoples used to calculate the input(mouse click) to select tiles in farm vile like games . I really need that farm vile like solution please help me guys . thank you

Dcdc1f8da93317d730963bffabbd78c3
0
TheHermit 101 Aug 13, 2013 at 06:28

A simple trick for this kind of thing is to assign each separate thing you want to select a unique color, then render the scene to a hidden buffer. When the user clicks, find what color is under the mouse at the point - this tells you what they clicked on. So long as your scene is not too expensive to render and has less than 16 million different things to select, this can be a pretty good solution that avoids raycasting. If you have a fixed 2D image that you’re selecting from, then it also lets you have odd-shaped selection areas since you just have to paint out the map of the various hotspots.