More contributed code - True Raycasts

Yay! Raycasts are cool. Just need a C++ port now :p Not that I'm working on any Box2D projects ATM.

But just for other users out there...raycasts are quite useful for (infinitely) fast projectiles...perhaps sniper rifles, or laser guns. You don't need to create an object and simulate the physics, just apply the damage directly (common in many FPSs). I'd also use it for enemy line-of-sight. You can use it to check if something is visible to an enemy by casting a ray from the enemies head, towards the player, for example, and see if anything is blocking its sight. *Maybe* useful for path-finding too? Anyways, lots of cool uses, so this is a great addition.
This is brilliant. Thanks for making it.
beautiful, this is becoming a full fledged game engine
Just as a clarification -- So in SVN 172, you've ported this over to C++? Because in SVN 171 Erin fixed a small bug in the TestSegment() code which works incorrectly when objects are aligned perfectly and I'm not sure if I've got the situation confused. I know that Boris's raycastOne improves performance a bit.


Edit: Unfortunately when I updated my code to SVN 174 my fairly robust laser code (which uses testSegment extensively) exhibited very bizarre behavior when using the old testSegment() function as well as when I adapted it for RaycastOne().... testSegment seems to be broken and raycastOne seems to miss collisions.
TestSegment now returns an enum, and it is unfortunately not backward compatible. It's a trivial change to your code, at least. I don't think I undid any of Erin's code when changing TestSegment; my changes were small, and SVN is pretty smart. RaycastOne not working: you probably have solidShapes = false, in which case if you press a segment up against a shape it will not find a hit.
If those aren't the solution to your problems, please do prepare a smallish example, and I'll fix it.
You do bring up good points, I will need to test it, however I did revert to my svn 171 version for the time being. I'm surprised that it compiled and ran even though it returns an enum now.
Yeah, me too, but ultimately the enum is just an int, so I'm sure it works quite happily if you have things like if(TestSegment(...)).

So, does anyone know if there's a way of setting things up so it produces a warning if used incorrectly, or an error. I knew changing the type would be a gotcha, but I honestly thought very few people actually used TestSegment in it's current state.
BorisTheBrave wrote:
it works quite happily if you have things like if(TestSegment(...)).


It makes sense but that is just really really nasty and i wish the C compiler was a little more careful about type checking.... but then again.. who doesn't...

Original thread: https://box2d.org/forum/viewtopic.php?t=1203