I'm trying to create a Game Editor, currently just placing different types of Shapes and such. I'm doing this in Windows Forms while drawing the 3D with XNA. So, if I have a couple of Shapes on the screen and I click the screen I want to be able to identify "which" of these objects you clicked.
What is the best method for this? Since having two objects one behind the other, it should be able to recognize the one in front and not the one behind it and also if I rotate the camera and click on the one behind it - it should identify it and not the first one.
Are there any smart ways to go about this?
Answer
In this video I show how do it with code...the projection/view is isometric, but all calcs are done in 3D...
http://www.youtube.com/watch?v=axHp1f3RlHM
When I calculate the mouse ray, I check for collision against a plane... but the procedure is analog to check against a list of boundingspheres associated with your objects.
The algorithm should be similar to this:
1. Calculate mouse ray
2. for every object
3. check if ray intersecs with it
4. if does then save the object and the distance in a sorted list by distance
5. choose from sorted list the nearest object.
No comments:
Post a Comment