Skip to main content
GameDev.net gamedev.net
🔒 Locked

mouse-clicks problem

Started by athos_musketeer Dec 15, 2002 at 9:12 AM 0 replies 150+ views
Original Post
athos_musketeer
athos_musketeer
hello there. i''m developing a TBS with SDL and hex tile based map, and theres something that don''t let me sleep at night . that is how do i know in where tile the player is clicking. i didn''t put a lot of thought neither.. thanks.
Doolwind
Doolwind
You will need to be slightly more specific, but here goes...

In screen space (which pixel on the actual screen)...
In your message handler catch the Left mouse click message LMOUSEDOWN. You can get the X and Y location of where the user clicked. Have a look at the C++ SDK help for more info.

In World space (where abouts in the game world)...
Look at the "picking" example in the DirectX SDK. I just cut this code and made a couple of changes to suit my RTS.

There is a function in this example (D3DXINTERSECT or something similar) which you pass in a triangle, and where you clicked (after you have transformed it into world coordinates, this is done for you by the SDK, just cut and paste the code). It will tell you if you clicked on that triangle.

So if you want to know if you clicked on a unit, just make a bounding cube for this unit and call the function 16 times passing in each triangle of that bounding cube. If any of the calls returns true you know the user just clicked on that unit.


Doolwind

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.