I'm trying to port the Aether.Physics2D library from C# to Xojo. This is essentially a tweaked version of the Farseer physics engine. It's mostly done but there's one part of the source code that I can't work out (it may be because C# is not my main language).
In Dynamics/Contacts/Contact.cs there are multiple references to what looks like a global Collision object but I can't find it's definition. For instance, on line 405, in the switch
:
case ContactType.Polygon:
Collision.Collision.CollidePolygons(ref manifold, (PolygonShape)FixtureA.Shape, ref transformA, (PolygonShape)FixtureB.Shape, ref transformB);
break;
I have already ported the Collision
class and its CollidePolygons
static method (defined here) but why is this code not just:
Collision.CollidePolygons(ref manifold, (PolygonShape)FixtureA.Shape, ref transformA, (PolygonShape)FixtureB.Shape, ref transformB);
Instead of:
Collision.Collision.CollidePolygons(ref manifold, (PolygonShape)FixtureA.Shape, ref transformA, (PolygonShape)FixtureB.Shape, ref transformB);
Essentially, why are there two Collision
calls?
Any help is greatly appreciated.
No, that's just because it's a class called Collision
within a namespace called Collision
:
namespace tainicom.Aether.Physics2D.Collision
{
public static class Collision
{
}
}
If you're porting the code anyway, I'd strongly recommend that you fix this mistake.
You could also change the calling code with a using
directive:
using Collision = tainicom.Aether.Physics2D.Collision.Collision;
...
// Calling the method is simpler now
Collision.CollidePolygons(...);
You might want to provide your alias with a different name, actually:
// TODO: Think of a better name to use :)
using CollisionClass = tainicom.Aether.Physics2D.Collision.Collision;
...
CollisionClass.CollidePolygons(...);
That way the name Collision
doesn't change its meaning at all, but you don't need to use Collision.Collision
anywhere.