Map Coord picking in 3d

Started by
12 comments, last by ktuluorion 21 years, 5 months ago
I created a map made up of squares a la RollerCoaster Tycoon with DirectXGraphics. It is in 3d, and the tiles are made up of tiled meshes. The tiles are all of equal size, just as in any isometric game, with different heights created by simply stacking them on top of each other for different heights. Basically what i need to do is find a way to figure out what block the mouse cursor is on top of. I have the world matrix rotated so that the world is being looked down upon at a 45 degree angle. I''m not really sure about how to go about this, transforming 2d coords to 3d coords, in addition to figuring out how to take into consideration the rotation. Any ideas/tutorials I could look at on this?
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
Advertisement

If you work with OpenGL try reading the "selection and picking" of the OpenGL Programming Guide (Red Book). For 3d to 2d coordinates transformation use gluProject.

I hope this helps you,

c_gatzman
c_gatzman
Try the "Pick" sample in the DirectX SDK.

Jim
quote:Original post by Anonymous Poster
Try the "Pick" sample in the DirectX SDK.

Jim



Here''s the thing: I''m just redrawing the same mesh over and over again to make several squares. So thats not exactly what I need. What I need to know is what map coords match up to the boxes I need.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
ktuluorion-

I would suggest you take another look at the "pick" example in the SDK.

All you need to use is:
D3DXIntersectTri

For all cells in the map
Figure out the 4 corners/points for that cell (a, b, c ,d)
Call D3DXIntersectTri twice passing in
1. a, b, c
2. b, c, d

If either of these two calls returns true, your user just clicked on that cell.
quote:Original post by Doolwind
ktuluorion-

I would suggest you take another look at the "pick" example in the SDK.

All you need to use is:
D3DXIntersectTri

For all cells in the map
Figure out the 4 corners/points for that cell (a, b, c ,d)
Call D3DXIntersectTri twice passing in
1. a, b, c
2. b, c, d

If either of these two calls returns true, your user just clicked on that cell.



OK now I see what you are saying. I''ll check it out once I get to work, but it sounds about right. Thanks a lot! I was thinking of it in the wrong way. The only problem I can think of is the fact that that may be taxing on the cpu, but I could probably narrow that down to a general area in some way.

Thx!
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
quote:Original post by ktuluorion
The only problem I can think of is the fact that that may be taxing on the cpu, but I could probably narrow that down to a general area in some way.


Nah, it shouldn''t be an issue, if it is however you just need to use some algorithm to cut down how you search for the square.

A simple way would be a binary search. Get the entire map, split it in half and test each half (the user must have clicked somewhere in either one). Whichever half D3DXIntersectTri returns true for, break that half into half again and test it etc etc until you get down to a small enough square to see exactly where they clicked, that should seriously reduce the number of D3DXIntersectTri calls you make.

However you shouldn''t need to worry about it, just depends how lightening fast you need your code to be, and seeing as it is only run when the user clicks the button, not every frame, it isn''t THAT much of an issue.

Doolwind
quote:Original post by Doolwind
Original post by ktuluorion
The only problem I can think of is the fact that that may be taxing on the cpu, but I could probably narrow that down to a general area in some way.


Nah, it shouldn''t be an issue, if it is however you just need to use some algorithm to cut down how you search for the square.

A simple way would be a binary search. Get the entire map, split it in half and test each half (the user must have clicked somewhere in either one). Whichever half D3DXIntersectTri returns true for, break that half into half again and test it etc etc until you get down to a small enough square to see exactly where they clicked, that should seriously reduce the number of D3DXIntersectTri calls you make.

However you shouldn''t need to worry about it, just depends how lightening fast you need your code to be, and seeing as it is only run when the user clicks the button, not every frame, it isn''t THAT much of an issue.

Doolwind

It actually IS run every frame


[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
quote:Original post by ktuluorion
Basically what i need to do is find a way to figure out what block the mouse cursor is on top of.



Sorry I didn''t read the post exactly . I was thinking you would be doing this whenever you clicked the button.

Anyway, just try it out the simplest way and you can always optimize later (with the binary search). I would not be suprised however if it runs just fine checking every cell every frame.

Doolwind
quote:Original post by Doolwind
Original post by ktuluorion
Basically what i need to do is find a way to figure out what block the mouse cursor is on top of.



Sorry I didn''t read the post exactly . I was thinking you would be doing this whenever you clicked the button.

Anyway, just try it out the simplest way and you can always optimize later (with the binary search). I would not be suprised however if it runs just fine checking every cell every frame.

Doolwind


The only thing is that function doesn''t exist. There is one called D3DXIntersect, but it works on Meshes, and that won''t work.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]

This topic is closed to new replies.

Advertisement