Box2dx:指定要在光线投射中忽略的灯具?
问题描述:
我的游戏世界中的每个人都有附加传感器形状的灯具。当我进行光线投射时,它会击中这些灯具,但我只想用至少一个不是传感器的形状击中灯具。这可能吗?Box2dx:指定要在光线投射中忽略的灯具?
我正在使用Box2dx - C#端口。
此外,回调是做什么的?
world.PhysicsWorld.RayCast((f, p, n, fr) =>
{
fixture = f;
position = p;
return fr;
}, point1, point2);
这是我打来的raycast函数。该文件说,回调可用于指定形状的数量回去,但我不知道该怎么做:
/// 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#,所以我不能告诉你所有的东西。
回调函数是给你结果的函数方法,你必须编写一个接受给定参数集的函数。您在调用RayCast时将该函数作为参数传递,当您找到重叠时您的函数将被调用,您的回调函数可能会返回一些值来指示是否继续进行射线广播,我假定您应该返回true或假。
对于只选择非传感器阵列灯具的最佳选择可能是在您的回调函数中检查此设置,并且只有在满足该条件时才会执行此操作。