Table of Contents

约束

Warning

Bullet Physics is being phased out. We no longer plan to support or expand its features as our focus shifts to Bepu Physics. We recommend transitioning to Bepu Physics for access to the latest updates and ongoing improvements.

Warning

This documentation is under construction.

高级 程序员

约束(Constraint) 将刚体限制在特定的运动模式内。例如,一个真实的膝关节只能沿一个轴移动,不能向前弯曲。

约束既可以将两个刚体连接在一起,也可以将单个刚体连接到世界中的某个点。它们允许刚体之间的交互和依赖。

共有六种约束类型:

  • 铰链(hinges)
  • 齿轮(gears)
  • 滑块(sliders)
  • 锥体(扭转和转动,cones)
  • 点对点(两个碰撞体之间的固定距离,point to point)
  • 六自由度(six degrees of freedom)

要演示不同的约束,请加载 PhysicsSample 示例项目。

创建约束

Note

目前,你只能在脚本中使用约束。

要创建约束,请使用 Simulation 的静态方法 CreateConstraint:

CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA);

这会将 RigidBodyA 在其当前位置链接到世界。 布尔值 useReferenceFrameA 指定限制应用于哪个坐标系(RigidBodyA 或世界)。

Note
CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA)

此方法将 RigidBodyA 链接到 RigidBodyB。

Note

布尔值 useReferenceFrameA 决定限制应用于哪个坐标系(RigidBodyA 或 RigidBodyB)。

将约束添加到模拟

创建约束后,从脚本中通过调用以下方法将其添加到模拟:

this.GetSimulation().AddConstraint(constraint);

或:

var disableCollisionsBetweenLinkedBodies = true;
this.GetSimulation().AddConstraint(constraint, disableCollisionsBetweenLinkedBodies);

参数 disableCollisionsBetweenLinkedBodies 会阻止链接的刚体之间发生碰撞。

同样,要从模拟中移除约束,请使用:

this.GetSimulation().RemoveConstraint(constraint);

另请参阅