0

I have a very simple terrain map, 256x256 tiles for example, it's divided into tiles (same squares...). every tile have height, slope... Something like figure below. My default look will be an iso view. (Each tile can be divied into smaller tiles for smooth, i called tesselation)

D3DXMatrixOrthoLH(&matProj, videoWidth , videoHeight , -100000, 100000);
float xPitch=0;
float yPitch=PI/3.0; //rotate yPitch 60 degree
float zPitch=PI/4.0; //rotate zPitch 45 degree

Now I need to select a unit tile onscreen with mouse (where to move to or build something...)! I have mouse position Mx,My I need to know what tile it is! If the map is flat, it's very easy! but with height, it's difficult. I'm planning to make the map quite static (not rotate often)... only translation. So I can store all the Vertex coordinate (x,y) on screen. By using D3DXVec3Project. And then search the triangles that contain the mouse position-> the tile we needed! However with this approach we may need to search 5-10 or 20 triangles. Do you know any betterway, more optimized or elegant ? Thanks!

I read about something like RayCasting for detection, maybe it can be used in my case. Because there is no eye pos in my view setup, the view vector is constant! 3D Screenspace Raycasting/Picking DirectX9

D3DXVec3Unproject also look quite promising!

Image : http://i1335.photobucket.com/albums/w666/greenpig83/sc4_zpsaaa61249.png

Community
  • 1
  • 1
greenpig83
  • 13
  • 4
  • possible duplicate of [3D Screenspace Raycasting/Picking DirectX9](http://stackoverflow.com/questions/19150215/3d-screenspace-raycasting-picking-directx9) – Roger Rowland Nov 29 '13 at 05:46
  • What's the problem with testing 20 triangles? As long as it's not 20k triangles this approach should be fine. In general there are two ways for the problem: Project the world onto the screen (as you mentioned) or project the mouse into the world (as with Vec3Unproject). Both approaches do not address the intersection test. And if your terrain is pretty static, the first approach is probably better suited. Subdivide the screen into tiles and create a dictionary that maps the tiles to the intersecting triangles. Then only test those triangles. – Nico Schertler Dec 01 '13 at 16:58
  • Yeah, I'm almost solved the problem by using first solution. But it only for mouse pos detection (use only 1 per frame). Or select units that appear on screen. – greenpig83 Dec 09 '13 at 01:11

0 Answers0