Sunday, July 12, 2015

xna - Game Editor - When screen is clicked, how do you identify which object that is clicked?


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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...