|
@@ -1,85 +1,28 @@
|
|
|
# Constraints
|
|
# Constraints
|
|
|
|
|
|
|
|
> [!WARNING]
|
|
> [!WARNING]
|
|
|
-> This page is outdated, the information contained therein are for Bullet, the previous physics engine
|
|
|
|
|
|
|
+> This page is WIP
|
|
|
|
|
|
|
|
[!INCLUDE [stride-studio-note](../../includes/under-construction-note.md)]
|
|
[!INCLUDE [stride-studio-note](../../includes/under-construction-note.md)]
|
|
|
|
|
|
|
|
<span class="badge text-bg-primary">Advanced</span>
|
|
<span class="badge text-bg-primary">Advanced</span>
|
|
|
<span class="badge text-bg-success">Programmer</span>
|
|
<span class="badge text-bg-success">Programmer</span>
|
|
|
|
|
|
|
|
-**Constraints** restrict rigidbodies to certain movement patterns. For example, a realistic knee joint can only move along one axis and can't bend forwards.
|
|
|
|
|
|
|
+**Constraints** restrict bodies to certain movement patterns. For example, a realistic knee joint can only move along one axis and can't bend forwards.
|
|
|
|
|
|
|
|
-Constraints can either link two rigidbodies together, or link a single rigidbody to a point in the world. They allow for interaction and dependency among rigidbodies.
|
|
|
|
|
|
|
+Constraints can either link two collidables together. They allow for interaction and dependency between bodies.
|
|
|
|
|
|
|
|
-There are six [types of constraints](xref:Stride.Physics.ConstraintTypes):
|
|
|
|
|
|
|
+## Performance And Stability
|
|
|
|
|
|
|
|
-* hinges
|
|
|
|
|
-* gears
|
|
|
|
|
-* sliders
|
|
|
|
|
-* cones (twist and turn)
|
|
|
|
|
-* point to point (fixed distance between two colliders)
|
|
|
|
|
-* six degrees of freedom
|
|
|
|
|
|
|
+The following are relevant excerpts from [Bepu's documentation](https://github.com/bepu/bepuphysics2/blob/master/Documentation/PerformanceTips.md)
|
|
|
|
|
|
|
|
-For a demonstration of the different constraints, load the **PhysicsSample** sample project.
|
|
|
|
|
|
|
+Try using the minimum number of solver iterations sufficient to retain stability. The cost of the solver stage is linear with the number of iterations, and some simulations can get by with very few.
|
|
|
|
|
|
|
|
-## Create a constraint
|
|
|
|
|
|
|
+For some simulations with very complex constraint configurations, there may be no practical number of solver iterations that can stabilize the simulation. In these cases, you may need to instead use substepping or a shorter time step duration for the entire simulation. More frequent solver execution can massively improve simulation quality, allowing you to drop velocity iteration counts massively (even to just 1 per substep). See the Substepping documentation for more details.
|
|
|
|
|
|
|
|
-> [!Note]
|
|
|
|
|
-> Currently, you can only use constraints from scripts.
|
|
|
|
|
-
|
|
|
|
|
-To create a constraint, use the [Simulation](xref:Stride.Physics.Simulation) static method [CreateConstraint](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)):
|
|
|
|
|
-
|
|
|
|
|
-```cs
|
|
|
|
|
-CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA);
|
|
|
|
|
-```
|
|
|
|
|
-
|
|
|
|
|
-This links [RigidBodyA](xref:Stride.Physics.Constraint.RigidBodyA) to the world at its current location.
|
|
|
|
|
-The boolean [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) specifies which coordinate system the limit is applied to (either [RigidBodyA](xref:Stride.Physics.Constraint.RigidBodyA) or the world).
|
|
|
|
|
-
|
|
|
|
|
-> [!Note]
|
|
|
|
|
-> * In the case of [ConstraintTypes.Point2Point](xref:Stride.Physics.ConstraintTypes), the frame represents a pivot in A. Only the translation vector is considered. [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) is ignored.
|
|
|
|
|
-> * In the case of [ConstraintTypes.Hinge](xref:Stride.Physics.ConstraintTypes), the frame represents a pivot in A and Axis in A. This is because the hinge allows only a limited angle of rotation between the rigidbody and the world.
|
|
|
|
|
-> * In the case of [ConstraintTypes.ConeTwist](xref:Stride.Physics.ConstraintTypes), [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) is ignored.
|
|
|
|
|
-> * [ConstraintTypes.Gear](xref:Stride.Physics.ConstraintTypes) needs two rigidbodies to be created. This function will throw an exception.
|
|
|
|
|
-
|
|
|
|
|
-```cs
|
|
|
|
|
-CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA)
|
|
|
|
|
-```
|
|
|
|
|
-
|
|
|
|
|
-This method links [RigidBodyA](xref:Stride.Physics.Constraint.RigidBodyA) to [RigidBodyB](xref:Stride.Physics.Constraint.RigidBodyB).
|
|
|
|
|
-
|
|
|
|
|
-> [!Note]
|
|
|
|
|
-> * In the case of [ConstraintTypes.Point2Point](xref:Stride.Physics.ConstraintTypes), the frame represents a pivot in A or B. Only the translation vector is considered. [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) is ignored.
|
|
|
|
|
-> * In the case of [ConstraintTypes.Hinge](xref:Stride.Physics.ConstraintTypes) the frame represents pivot in A/B and Axis in A/B. This is because the hinge allows only a limited angle of rotation between the rigidbody and the world in this case.
|
|
|
|
|
-> * In the case of [ConstraintTypes.ConeTwist](xref:Stride.Physics.ConstraintTypes), [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) is ignored.
|
|
|
|
|
-> * In the case of [ConstraintTypes.Gear](xref:Stride.Physics.ConstraintTypes), [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) is ignored. The frame just represents the axis either in A or B; only the translation vector (which should contain the axis) is used.
|
|
|
|
|
-
|
|
|
|
|
-The boolean [useReferenceFrameA](xref:Stride.Physics.Simulation.CreateConstraint\(Stride.Physics.ConstraintTypes,Stride.Physics.RigidbodyComponent,Stride.Core.Mathematics.Matrix,System.Boolean\)) determines which coordinate system ([RigidBodyA](xref:Stride.Physics.Constraint.RigidBodyA) or [RigidBodyB](xref:Stride.Physics.Constraint.RigidBodyB)) the limits are applied to.
|
|
|
|
|
-
|
|
|
|
|
-## Add constraints to the simulation
|
|
|
|
|
-
|
|
|
|
|
-After you create a constraint, add it to the simulation from a script by calling:
|
|
|
|
|
-
|
|
|
|
|
-```cs
|
|
|
|
|
-this.GetSimulation().AddConstraint(constraint);
|
|
|
|
|
-```
|
|
|
|
|
-
|
|
|
|
|
-or:
|
|
|
|
|
-
|
|
|
|
|
-```cs
|
|
|
|
|
-var disableCollisionsBetweenLinkedBodies = true;
|
|
|
|
|
-this.GetSimulation().AddConstraint(constraint, disableCollisionsBetweenLinkedBodies);
|
|
|
|
|
-```
|
|
|
|
|
-
|
|
|
|
|
-The parameter [disableCollisionsBetweenLinkedBodies](xref:Stride.Physics.Simulation.AddConstraint\(Stride.Physics.Constraint,System.Boolean\))
|
|
|
|
|
- stops linked bodies colliding with each other.
|
|
|
|
|
-
|
|
|
|
|
-Likewise, to remove a constraint from the simulation, use:
|
|
|
|
|
-
|
|
|
|
|
-```cs
|
|
|
|
|
-this.GetSimulation().RemoveConstraint(constraint);
|
|
|
|
|
-```
|
|
|
|
|
|
|
+> [!WARNING]
|
|
|
|
|
+> Probably need to adapt and extend some parts of the above to our implementation, not sure how relevant everything is. Take stuff from https://github.com/bepu/bepuphysics2/blob/master/Documentation/StabilityTips.md and https://github.com/bepu/bepuphysics2/blob/master/Documentation/Substepping.md
|
|
|
|
|
+> - Eideren
|
|
|
|
|
|
|
|
## See also
|
|
## See also
|
|
|
|
|
|