Mouse to Screen in 3D Iso Map
If any could help me out with this it would be appreciated. I have a isometric view, rendered with d3d. I''ve taken advantage of 3d and implementated a heightmap to create rolling terrian. This of course eliminates tradional methods of screen to map coordinate methods used in 2d since my tile size on the screen is variable.
I''m pretty basic on some areas of 3d still so any help would be great. In addition (don''t know of this will kill me or not) I''m using d3d''s already transformed vertices (D3DTLVERTEX) and my vertex data never really is in a true 3d state as I build it directly into screen coordinates and adjust it based on the height map offset.
Thanks in advance for the help,
Sieggy
I''ve asked this a lot since I wrote that D3D-isometric article, so I''ll cut''n''paste the reply I sent to the last person to ask. :-)
(snip)
Mouse tracing in a heightmapped isometric context has been troubling me for a while, although I''ve found a few approaches that can be made to work.
My favourite approach is to use a mouse-map (TANSTAAFL''s tutorial sort-of talks about this, I think Jim Adams has written a LOT about this topic for simple isometric engines). Basically, you render unshaded polys (coloured according to which tile you are rendering) to an offscreen surface at the same time you render the main scene (or less frequently - there is no point in redrawing when the camera/POV hasn''t moved). Then you can simply check the pixel colour of a point on the offscreen surface and have pixel-perfect mouse accuracy. You can shrink the surface if you want - this reduces accuracy a bit, but saves memory. [If you can, you might want to use an 8 bit surface for this, too - if you have >255 polys, you can always recycle numbers if you are careful to sectorize the screen]. I don''t have any example code for this, mainly because I''ve been working on a bunch of other projects, but I''m pretty sure that this is implementable.
I hope that helps,
Bracket.
(snip)
Mouse tracing in a heightmapped isometric context has been troubling me for a while, although I''ve found a few approaches that can be made to work.
My favourite approach is to use a mouse-map (TANSTAAFL''s tutorial sort-of talks about this, I think Jim Adams has written a LOT about this topic for simple isometric engines). Basically, you render unshaded polys (coloured according to which tile you are rendering) to an offscreen surface at the same time you render the main scene (or less frequently - there is no point in redrawing when the camera/POV hasn''t moved). Then you can simply check the pixel colour of a point on the offscreen surface and have pixel-perfect mouse accuracy. You can shrink the surface if you want - this reduces accuracy a bit, but saves memory. [If you can, you might want to use an 8 bit surface for this, too - if you have >255 polys, you can always recycle numbers if you are careful to sectorize the screen]. I don''t have any example code for this, mainly because I''ve been working on a bunch of other projects, but I''m pretty sure that this is implementable.
I hope that helps,
Bracket.
Thanks Bracket,
That seems like a very doable solution, thanks for the idea. Another idea that I managed to come with on my own after mulling over this last night was to test for point inclusion of all the polys/tiles close to the mouse. Since the vertices are all transformed to screen coordinates this should also be possible. However, that is still pretty math intensive so I'll have to see how it plays out. Thanks for the help and btw, it was an excellent article you posted. I enjoyed it a great deal!
Sieggy
Edited by - Sieggy on 5/5/00 6:54:16 PM
That seems like a very doable solution, thanks for the idea. Another idea that I managed to come with on my own after mulling over this last night was to test for point inclusion of all the polys/tiles close to the mouse. Since the vertices are all transformed to screen coordinates this should also be possible. However, that is still pretty math intensive so I'll have to see how it plays out. Thanks for the help and btw, it was an excellent article you posted. I enjoyed it a great deal!
Sieggy
Edited by - Sieggy on 5/5/00 6:54:16 PM
This sounds like a good idea Bracket but how do I setup the offscreen surface and how do I draw to it.
Do I use DrawPrimitive to draw on that surface ?
Do I draw those unshaded polys in the same loop has the DrawPrimitive ?
I would like to have more informations on that subject please. Perhaps even a little code
Thanks,
Darkening
P.S: Everybody, feel free to reply to this post, not just Bracket. I'll welcome very post you can make.
Edited by - Darkening on May 24, 2000 8:27:36 PM
Do I use DrawPrimitive to draw on that surface ?
Do I draw those unshaded polys in the same loop has the DrawPrimitive ?
I would like to have more informations on that subject please. Perhaps even a little code
Thanks,
Darkening
P.S: Everybody, feel free to reply to this post, not just Bracket. I'll welcome very post you can make.
Edited by - Darkening on May 24, 2000 8:27:36 PM
---------------------------Unfortunately, no one can be told what a bug is.You have to see it for yourself...
i''ve been playing with the d3d im heightmapping idea as well, and i''ve come up with a slightly different solution.
based on the fact that the x coordinates of a heightmapped 3d iso field do not change for the center(the north-south axis) or the edges(east and west), we can determine a columnar position of the mouse based on the x coordinate. within this column, we are either in the right half of one column of tiles, or in the left half of the next column of tiles.
from a mouse Y position, we can determine the base for this tile. (i.e., the normal position of the tile, i.e. flat with all heights=0)
if we take this y position, and calculate the row of tiles that MIGHT overlap this base tile (by using the maximum height for the field), we will have a short list of tiles that the mouse may be on.
now, we can shimmy up this short list of possible tiles, checking the y coordinate ranges for the top and bottom of the tiles. This will leave us with two possible tiles on which the mouse can be. (we will get rid of trivial cases where the bottom of the tile is higher than the top)
so, two tiles left, and the separator is the upper line of the lower of the two tiles. check the mouse position to see if it is higher or lower than this line. if higher, its in the upper tile, if lower, than its in the lower of the tiles.
based on the fact that the x coordinates of a heightmapped 3d iso field do not change for the center(the north-south axis) or the edges(east and west), we can determine a columnar position of the mouse based on the x coordinate. within this column, we are either in the right half of one column of tiles, or in the left half of the next column of tiles.
from a mouse Y position, we can determine the base for this tile. (i.e., the normal position of the tile, i.e. flat with all heights=0)
if we take this y position, and calculate the row of tiles that MIGHT overlap this base tile (by using the maximum height for the field), we will have a short list of tiles that the mouse may be on.
now, we can shimmy up this short list of possible tiles, checking the y coordinate ranges for the top and bottom of the tiles. This will leave us with two possible tiles on which the mouse can be. (we will get rid of trivial cases where the bottom of the tile is higher than the top)
so, two tiles left, and the separator is the upper line of the lower of the two tiles. check the mouse position to see if it is higher or lower than this line. if higher, its in the upper tile, if lower, than its in the lower of the tiles.
Get off my lawn!
I posted a question on optimized math behind checking a point in a polygon (based on my thoughts from above) and recieved a nice little algorithm based on the signed area of a triangle from WitchLord. Its under D3D/OpenGL (I think) "Stupid poly math question" and posted by yours truly.
I implemented it and it works beautifully and is pretty painless to do. I basically check the tiles from the bottom up looking for a match to the mouse location. Going from the bottom up is a critical piece, as some of your tiles are likely to be actually a backface, that is not viewable. Second, I''m currently rendering the tiles with transformed vertices, so that makes it really easy since I have access to all the screen positions right of the bat and I eliminates having to do the raycasting approach to determine location (something I''m not totally familiar with yet). I''ve heard questions about retrieving the transformed vertices from D3D (when letting it do the transforms for you) but I don''t know how or if that is possible and besides I imagine that''s a whole another discussion.
Performance seems to be great. I''m currently using this in my editor which is an MFC interface app (with a rendering window in it for D3D) on my dog slow laptop and in software as well. No noticable lag in my world coordinate updates at all so I''ve been extrememly pleased with it. I''ll be happy to tell more if anyone is interested.
Sieggy
I implemented it and it works beautifully and is pretty painless to do. I basically check the tiles from the bottom up looking for a match to the mouse location. Going from the bottom up is a critical piece, as some of your tiles are likely to be actually a backface, that is not viewable. Second, I''m currently rendering the tiles with transformed vertices, so that makes it really easy since I have access to all the screen positions right of the bat and I eliminates having to do the raycasting approach to determine location (something I''m not totally familiar with yet). I''ve heard questions about retrieving the transformed vertices from D3D (when letting it do the transforms for you) but I don''t know how or if that is possible and besides I imagine that''s a whole another discussion.
Performance seems to be great. I''m currently using this in my editor which is an MFC interface app (with a rendering window in it for D3D) on my dog slow laptop and in software as well. No noticable lag in my world coordinate updates at all so I''ve been extrememly pleased with it. I''ll be happy to tell more if anyone is interested.
Sieggy
I''m really interested in learning more about your world coordinates update system and your editor.
You can e-mail me at elcoloc@globetrotter.net if you want, I would like to hear from you.
Thanks,
Darkening
You can e-mail me at elcoloc@globetrotter.net if you want, I would like to hear from you.
Thanks,
Darkening
---------------------------Unfortunately, no one can be told what a bug is.You have to see it for yourself...
BTW Sieggy,
the post you just talked, wrote, about is under "General and Game Programming" with the title "stupid poly math question" posted on May 6, 2000 9:02:58 AM.
So if anyone else want to look at it, it''s there.
Darkening
the post you just talked, wrote, about is under "General and Game Programming" with the title "stupid poly math question" posted on May 6, 2000 9:02:58 AM.
So if anyone else want to look at it, it''s there.
Darkening
---------------------------Unfortunately, no one can be told what a bug is.You have to see it for yourself...
June 19, 2000 06:18 PM
I would also like to know more about your way of doing the world co-ord system.
I''ve been trying to work out the world co-ord for this type of ISO map since reading the atrical
my e-mail address is steven.harrison@libertysurf.co.uk
I''ve been trying to work out the world co-ord for this type of ISO map since reading the atrical
my e-mail address is steven.harrison@libertysurf.co.uk
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement