This project has moved and is read-only. For the latest updates, please go here.

find closest geom and Ray Casting

Mar 21, 2009 at 9:31 PM
I'm looking for a way to find the closest geom to a given geom. I'm planning on implementing a "Homing Missile" that will target the nearest geom and head towards it. I was thinking of iterating through the array of objects I have, and comparing all of their positions. I was wondering if there is a more efficient way of doing this using the farseer physics engine?

Also, I'm planning on adding "laser" weapons. I did a search and found that the accepted way of doing this is ray casting. It seems farseer hasn't implemented this yet, but you are planning to. I was wondering if you know when this will be added? I ask because I can implement beams differently, but if its going to be added soon I might as well just wait.

One more thing I would like to add is you guys have done great work here. I'm sure you get this all the time, but bravo!
Mar 22, 2009 at 1:38 PM
If you want to find the closest geometry you could use an AABB (Axis Aligned Bounding Box). All Farseer Physics geometries use AABB to make preliminary checks in the collision system, just use the attached AABB on the geometry to make your checks aswell.

Create an AABB that is larger than the homing missile. Update it's position on each update to be at the same position as the missile.
Check the AABB against all geometies. If their AABB intersects with the AABB you made for the missile, they will be in the vicinity. You could also use the Geom.Position property instead of the AABB of the geometry. This will make sure the center of the geometry is the vicinity. It depends on what you want.

I'm in the progress of writing some ray-testing into Farseer Physics. It already have the basics but they need some higher level API's to help people use it more. If you have any good articles, I would like to have a look at them. :)
Mar 23, 2009 at 3:32 AM
Well I'll hold off on lasers now. And sorry, I don't think I know of any great articles on ray-testing. I'll keep an eye open though.

Thanks for the AABB idea, that should be more efficient then how I was going to implement it.