3

在我的游戏世界中,每个人都有附有传感器形状的固定装置。当我进行光线投射时,它会击中这些灯具,但我只想击中具有至少一种不是传感器的形状的灯具。这可能吗?

我正在使用Box2dx - C# 端口。

另外,回调有什么作用?

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

这是我正在调用的光线投射功能。文档说回调可用于指定要返回的形状数量,但我不知道如何做到这一点:

    /// 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;
    }
4

1 回答 1

1

由于没有其他人回答我会给你我能想到的,提供的文档有点粗略,该函数显然依赖另一段代码来完成实际工作,我不懂 C#,所以我可以' t告诉你一切。

回调是为您提供结果的函数方法,您必须编写一个接受给定参数集的函数。您在调用 RayCast 时将该函数作为参数传递,当发现重叠时将调用您的函数,然后您的回调函数可能会返回一些值以指示是否继续进行光线投射,我认为您应该返回 true 或错误的。

仅选择具有非传感器阵列的灯具的最佳选择可能是在您的回调函数中检查这一点,并且仅在满足该标准时才采取行动。

于 2010-04-08T23:54:30.820 回答