Exemple #1
0
        //     CONSTRAINTS

        /// <summary>
        /// Allocates a constraint slot and sets up a constraint with the specified description.
        /// </summary>
        /// <typeparam name="TDescription">Type of the constraint description to add.</typeparam>
        /// <param name="bodyHandles">First body handle in a list of body handles used by the constraint.</param>
        /// <param name="bodyCount">Number of bodies used by the constraint.</param>
        /// <returns>Allocated constraint handle.</returns>
        public int Add <TDescription>(ref int bodyHandles, int bodyCount, ref TDescription description)
            where TDescription : IConstraintDescription <TDescription>
        {
            Solver.Add(ref bodyHandles, bodyCount, ref description, out int constraintHandle);
            for (int i = 0; i < bodyCount; ++i)
            {
                var bodyHandle = Unsafe.Add(ref bodyHandles, i);
                Bodies.ValidateExistingHandle(bodyHandle);
                Bodies.AddConstraint(Bodies.HandleToLocation[bodyHandle].Index, constraintHandle, i);
            }
            return(constraintHandle);
        }
 /// <summary>
 /// Wakes up a body if it is sleeping. All bodies that can be found by traversing the constraint graph from the body will also be awakened.
 /// If the body is already awake, this does nothing.
 /// </summary>
 /// <param name="bodyHandle">Handle of the body to awaken.</param>
 public void AwakenBody(int bodyHandle)
 {
     bodies.ValidateExistingHandle(bodyHandle);
     AwakenSet(bodies.HandleToLocation[bodyHandle].SetIndex);
 }