Continuous collision detection (CCD) 连续式碰撞检测 Physics物理系列之三

Continuous collision detection (CCD) 连续式碰撞检测

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.4版本
参考链接:https://docs.unity3d.com/Manual/ContinuousCollisionDetection.html

CCD ensures that fast-moving bodies collide with objects instead of passing, or tunnelling, through those objects. Unity provides the following CCD methods:
CCD确保快速移动的物体与物体发生碰撞,而不是穿过这些物体,或穿入物体。Unity提供了以下CCD方法:

  • Sweep-based CCD
  • Speculative CCD

To use sweep-based CCD, select a RigidBody in the Inspector window and set Collision Detection to Continuous or Continuous Dynamic. For speculative CCD, set Collision Detection to Continuous Speculative.
要使用基于扫描式的CCD,请在Inspector 窗口中选择刚体,并将碰撞检测设置为连续或连续动态。对于推测式的CCD,将碰撞检测设置为连续推测。

Sweep-based CCD

Sweep-based CCD uses a Time Of Impact (TOI) algorithm to compute potential collisions for an object by sweeping its forward trajectory using its current velocity. If there are contacts along the object’s moving direction, the algorithm computes the time of impact and moves the object until that time. The algorithm can perform sub steps from that time onwards, computing the velocity after TOI then re-sweep, at the expense of more CPU cycles.
基于扫描式的CCD用撞击时间(TOI)算法,把物体当前的速度扫描其前进轨迹,计算出物体可能发生的碰撞。如果在物体的运动方向上有接触点,算法会计算出撞击的时间并将物体移动到那个时间。该算法从那时起执行子步骤,计算TOI之后的速度,然后重新扫描,花费更多的CPU周期。

However, because this method relies on linear sweep, it ignores the body’s angular motion, which can cause tunnelling effects when objects are rotating at speed. For example, the flipper in a pinball machine is fixed at one end and rotates around a fixed point. The flipper only has angular motion and no linear motion. Therefore, it can easily miss the collision with the pinball:
然而,由于该方法依赖于线性扫描,忽略了物体的角运动,当物体高速旋转时会产生挖隧道效应。例如,弹珠机的弹片一端固定,围绕一个定点旋转。弹片只有角运动,没有直线运动。因此,它很容易错过与弹珠的碰撞:

在这里插入图片描述
Another issue with this method is performance. If you have a large number of high-speed objects with CCD in close proximity, the CCD overhead increases quickly because of the extra sweeping, and the physics engine has to perform more CCD sub-steps.
这种方法的另一个问题是性能。如果有大量高速运动的CCD对象与之非常接近,由于额外的扫描,CCD开销会迅速增加,而物理引擎必须执行更多的CCD子步骤。

Speculative CCD

Speculative CCD works by increasing an object’s broad-phase axis-aligned minimum bounding box (AABB), based on the object’s linear and angular motion. The algorithm is speculative because it picks all potential contacts during the next physics step. All contacts are then fed into the solver, which makes sure that all contact constraints are satisfied so that an object does not tunnel through any collision.
推测式CCD的工作原理是根据物体的直线运动和角运动,增加物体的面板形状的轴向对齐的最小边框(AABB)。这个算法是推测性的,因为它在接下来的物理帧中选择了所有可能的接触点。然后将所有接触点输入求解器,这将确保满足所有接触约束,从而使对象不会穿过任何碰撞。

The following diagram shows how a sphere moving from t0 could have an expected position at t1 if there were no walls in its path. By inflating the AABB with its target pose, the speculative algorithm picks up two contacts with the n1 and n2 normals. The algorithm then tells the solver to respect those contacts so that the sphere doesn’t tunnel through the walls.
下图显示了一个从t0开始运动的球体,如果在它的路径上没有墙,那么它在t1的期望位置是怎样的。通过用目标位置对AABB进行膨胀,推测算法获得了n1和n2法线的两个接触点。然后,算法告诉求解器响应这些接触,这样球体就不会穿墙而过。

在这里插入图片描述

Speculative CCD is generally cheaper than the sweep-based method because contacts are only computed during the collision detection phase, not during the solving and integrating phase. Also, because Speculative CCD expands the broad-phase AABB based on the object’s linear and angular motion, it finds the contacts that sweep-based CCD can miss.
推测式CCD通常比基于扫描的方法便宜,因为接触只在碰撞检测阶段才计算,而不是在求解和积分阶段。同时,由于推测式CCD根据物体的直线运动和角运动对面板形状的AABB进行了扩展,发现了基于扫描的CCD可能遗漏的触点。

在这里插入图片描述
However, speculative CCD can cause a ghost collision, where an object’s motion is affected by a speculative contact point when it shouldn’t be. This is because speculative CCD collects all potential contacts based on the closest point algorithm, so the contact normal is less accurate. This can often make high speed objects slide along tessellated collision features and jump up, even though they shouldn’t. For example, in the following diagram, a sphere starts at t0 and moves horizontally towards the right, with a predicted position at t1 after integration. An inflated AABB overlaps the boxes b0 and b1, and the CCD yields two speculative contacts at c0 and c1. Because speculative CCD generates contacts using the closest point algorithm, c0 has a very inclined normal, which appears to be a ramp to the solver.
然而,推测式CCD会导致幽灵碰撞,当一个物体的运动不应该受到影响的时候,受到推测性接触点的影响。这是因为推测式CCD是基于最近点算法采集所有可能的接触点,所以接触法线的精度较低。这通常会使高速物体沿着细分的碰撞特征滑动并跳起来,尽管它们不应该跳起来。例如,在下面的图中,一个球体从t0开始向右水平移动,积分后的预测位置为t1。膨胀的AABB与b0和b1重叠,CCD在c0和c1处产生两个推测触点。由于推测式CCD使用最近点算法生成触点,c0有一个非常倾斜的法线,这似乎是一个斜坡被传到求解器。

在这里插入图片描述

在这里插入图片描述

Speculative CCD can also cause tunneling because speculative contacts are only computed during the collision detection phase. During contact solving, if an object gains too much energy from the solver, it may end up outside the initial inflated AABB after integration. If there are collisions just outside the AABB, the object will tunnel right though.
推测式CCD也会造成穿隧道效应,因为推测性接触只在碰撞检测阶段计算。在触点解算过程中,如果一个物体从解算器中获得了过多的能量,那么它在整合后可能会在初始膨胀的AABB之外结束。如果在AABB外有碰撞,物体就会穿过隧道。

For example, the following diagram shows a sphere is moving left from t0 while a stick is rotating clockwise. If the sphere gains too much energy from the impact, it may end up exiting the inflated AABB (red dotted rectangle) at t1. If there are collisions just outside the AABB, as shown by the blue box below, the sphere may end up tunneling right through it. This is because the solver only computes contacts inside the inflated AABB, and collision detection isn’t performed during the solving and integrating phase.
例如,下图显示了一个球体从t0向左移动,而一根木棍顺时针旋转。如果球体从撞击中获得太多的能量,它可能最终会在t1离开膨胀的AABB(红点矩形)。如果在AABB外部有碰撞,如下面的蓝色框所示,球体可能会直接穿过去。这是因为求解器只计算膨胀AABB内部的接触,在求解和整合阶段没有进行碰撞检测。

在这里插入图片描述

你可能感兴趣的:(Physics)