1

我正在使用光线投射来确定绳索接头的锚点位置。通过使用一些简单的绘图调用,我可以看到在光线投射返回的点可靠地创建了ropejoint。我的问题在于返回点。它偶尔会穿过身体,返回对面边界上的一个点,有时会在身体内部。它似乎总是失败,也就是说,如果我投射一条重复穿过的光线,它会继续穿过并返回相同的错误点。这让我相信我的身体有问题。我正在为有问题的身体使用 TextureToBody 转换器。

另一个较小的问题是我必须从我的关节位置在每个方向上减去 10/64 才能使其准确连接。我不知道为什么会这样。(64pixels=1meter是我使用的转换比例)

光线投射方法:

    Private Sub castRay(startPoint As Vector2, direction As Vector2)
        direction *= 25
        direction.Y = (-direction.Y)
        world.RayCast(Function(fixture As Fixture, point As Vector2, normal As Vector2, fraction As Single)
                          Dim body As Body = fixture.Body

                          ropeContactFixture = fixture
                          ropeContactPoint = point
                          ropeJoint = New RopeJoint(Me.body, fixture.Body, New Vector2(0, 0), point - ropeContactFixture.Body.Position - (New Vector2(10, 10) / 64))
                          Return 0
                      End Function, startPoint, startPoint + direction)
    End Sub
4

1 回答 1

0

根据我对 Farseer 的使用,您应该列出 RayCast 返回的所有点,然后按距离对它们进行排序。

取自 Farseers 代码 -

     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.

     Inside the callback:
     return -1: ignore this fixture and continue
     return 0: terminate the ray cast
     return fraction: clip the ray to this point
     return 1: don't clip the ray and continue

因此,利用这些知识,您应该能够列出沿射线的点,找到最近的点,然后制作绳索。

作为旁注,我不确定你为什么要 inverting direction.Y,但你应该确保这是你打算做的。

于 2012-11-16T17:15:21.917 回答