Original Post
Hi, I'm using a billboard sprite in my MDX application to represent small markers in 3D-space. The application is based on the sample framework of the DirectX SDK. I'd like to implement hit-testing for mouse clicks on these sprites (actually, it is only one at different positions), but I don't really know if I am on the right track. At first some code that I use for the sprite: At first I concentrated on implementing hit-testing by projecting the relevant part of the sprite texture to screen coordinates. But this does not fit into my other hit-testing code where I unproject a ray into object space. So how do I do the hit-testing in object space? Is it a good idea to create a plane and use plane.IntersectLine(...)? How do I get the depth information to compare it with other objects that are also hit by the ray? Any help is welcome, Jack P.S. I use managed DirectX, but I think it's not relevant for the problem.
// excerpt from DrawSprite function
// set the sprite's worldView matrix, needed for billboarding
markerSprite.SetWorldViewLH(Matrix.Translation(this.basePoint), viewMatrix);
markerSprite.Begin(SpriteFlags.Billboard | SpriteFlags.AlphaBlend);
markerSprite.Draw(texture,
textureRect, // rectangle used from texture in pixels
new Vector3(textureRect.Width / 2, textureRect.Height, 0), // center of sprite defined on whole texture in pixels used when billboarding
new Vector3(0, 0, 0), // offset position of sprite in world defined on whole texture in pixels,
Color.White.ToArgb());
markerSprite.End();