# 2D D3DXSprite picking

This topic is 3633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm in the process of creating a tile map editor, using GDI for the forms, and menus, but I have a question in regards to picking a 2D entity. For example, I'm having a static-sized tile editor, where you can specify the standard tile size, width and height, but my concern is.. how do I pick the cells in Direct3D? With GDI, I have done the following:
case WM_LBUTTONDOWN:
{
POINT pt;
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);

map[pt.y / TILE_HEIGHT][pt.x / TILE_WIDTH] = selected;
}


"map" and "selected" being entities of a struct, containing HBITMAP variables. which basically, draws the item I have selected from my tileset, to place on the map. How do I accomplish something similar using Direct3D? or rather pick it from a tile set... of D3DXSprites? is there a quick function to access those 2d coordinates? any recommendations or snippets? pseudocode? Gahh.. I make no sense, basically, how do I access the x/y position of the cell? so I can pick and draw to/from them? Thanks in advance. -Quinn [Edited by - QuinnJohns on March 15, 2008 7:22:07 PM]

##### Share on other sites
I don't follow... How does your code now differ from your GDI code? Surely you know the position and size of al lthe tiles, so your code will be exactly the same?

##### Share on other sites
Well, that is how I access the information if I was using GDI to draw and select my tiles, however, I want to do the same thing in Direct3D, using D3DXSprites, will the same code work? using Point, etc? or is there a better alternative?

I know I need to alter my struct to hold D3DXSprite now, instead of HBitmap, but what about locating the actual x,y position? lol. thanks.

##### Share on other sites
Whether you're using D3D, GDI, OpenGL, or something else, the mouse coordinates will be the same. You'll still end up with a 2D point in client coordinates for your mouse, it's just how you determine what that point means that differs. You'll still use that point to compare agains the position of your tiles.

##### Share on other sites
Thanks Steve, that answered my question. :)

##### Share on other sites
A quick question, if anyone reads this again, assuming I will only do 2D on this game, I will want to use D3DXMatrixOrthoLH right?

##### Share on other sites
There's two options:

1) Either use an ortho matrix (like the one you mentioned). This has the advantage that you can still apply matrices to rotate/scale. Also the 2d scene can be scaled to fit every resolution

2) Or use pretransformed vertices (D3DVERT_RHWXYZ). These allow you to use screen coordinates, but any matrices and lighting will be bypassed.

##### Share on other sites
Thanks much, Endurion. I definetely think I'll be doing D3DXMatrixOrthoLH, since you mentioned the scaling to fit resolution. It totally didn't dawn on me till just now, that that was one aspect I truly needed.