【问题标题】:Box2dx: Specify fixtures to ignore in raycasting?Box2dx:指定在光线投射中要忽略的固定装置?
【发布时间】:2010-04-09 07:54:30
【问题描述】:

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

我正在使用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;
    }

【问题讨论】:

    标签: c# xna box2d


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-05
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      相关资源
      最近更新 更多