views:

70

answers:

1

Everybody in my game world has fixtures with sensor shapes attached. When I raycast, it hits these fixtures, but I only want to hit fixtures with at least one shape that is not a sensor. Is this possible?

I'm using Box2dx - the C# port.

Also, what does the callback do?

     world.PhysicsWorld.RayCast((f, p, n, fr) =>
        {
            fixture = f;
            position = p;
            return fr;
        }, point1, point2);

This is the raycast function I'm calling. The documentation says that the callback can be used to specify the number of shapes to get back, but I'm not sure how to do that:

    /// Ray-cast the world for all fixtures in the path of the ray. Your callback
    /// controls whether you get the closest point, any point, or n-points.
    /// The ray-cast ignores shapes that contain the starting point.
    /// @param callback a user implemented callback class.
    /// @param point1 the ray starting point
    /// @param point2 the ray ending point
    public void RayCast(Func<Fixture, Vector2, Vector2, float, float> callback, Vector2 point1, Vector2 point2)
    {
        RayCastInput input = new RayCastInput();
        input.maxFraction = 1.0f;
        input.p1 = point1;
        input.p2 = point2;

        _rayCastCallback = callback;
        _contactManager._broadPhase.RayCast(_rayCastCallbackWrapper, ref input);
        _rayCastCallback = null;
    }
A: 

Since no one else has answered I'll give you what I can figure, the documentation provided is a bit sketchy, the function clearly rely on another piece of code to do the actual work and I don't know C#, so I can't tell you everything.

The callback is the functions method of giving you the result, you have to write a function that accepts the given set of parameters . You pass that function as a parameter when calling RayCast, in turn your function will be called when an overlapping is found, your callback function may then return some value to indicate whether to continue the raycast, I'd presume you should return either true or false.

Your best bet for choosing only fixtures with non-sensor arrays is probably to check this in your callback function and only act if that criteria is met.

eBusiness