예제 #1
0
        /// <summary>
        /// Casts a convex shape against the collidable.
        /// </summary>
        /// <param name="castShape">Shape to cast.</param>
        /// <param name="startingTransform">Initial transform of the shape.</param>
        /// <param name="sweep">Sweep to apply to the shape.</param>
        /// <param name="filter">Test to apply to the entry. If it returns true, the entry is processed, otherwise the entry is ignored. If a collidable hierarchy is present
        /// in the entry, this filter will be passed into inner ray casts.</param>
        /// <param name="result">Hit data, if any.</param>
        /// <returns>Whether or not the cast hit anything.</returns>
        public bool ConvexCast(ConvexShapes.ConvexShape castShape, ref RigidTransform startingTransform,
                               ref Vector3 sweep, Func <BroadPhaseEntry, bool> filter, out RayCastResult result)
        {
            RawList <Collidable> outputOverlappedElements = PhysicsResources.GetCollidableList();
            BoundingBox          boundingBox;

            castShape.GetSweptBoundingBox(ref startingTransform, ref sweep, out boundingBox);

            CollidableTree.GetOverlaps(boundingBox, outputOverlappedElements);
            result           = new RayCastResult();
            result.HitData.T = float.MaxValue;
            for (int i = 0; i < outputOverlappedElements.Count; ++i)
            {
                RayHit hit;
                if (outputOverlappedElements.Elements[i]
                    .ConvexCast(castShape, ref startingTransform, ref sweep, filter, out hit))
                {
                    if (hit.T < result.HitData.T)
                    {
                        result.HitData   = hit;
                        result.HitObject = outputOverlappedElements.Elements[i];
                    }
                }
            }

            PhysicsResources.GiveBack(outputOverlappedElements);
            return(result.HitData.T < float.MaxValue);
        }
예제 #2
0
 ///<summary>
 /// Constructs a new entry with identity orientation.
 ///</summary>
 ///<param name="shape">Shape of the entry.</param>
 public OrientedConvexShapeEntry(ConvexShape shape)
 {
     Orientation    = Quaternion.Identity;
     CollisionShape = shape;
 }
예제 #3
0
 ///<summary>
 /// Constructs a new entry.
 ///</summary>
 ///<param name="orientation">Orientation of the entry.</param>
 ///<param name="shape">Shape of the entry.</param>
 public OrientedConvexShapeEntry(Quaternion orientation, ConvexShape shape)
 {
     Orientation    = orientation;
     CollisionShape = shape;
 }
예제 #4
0
 ///<summary>
 /// Constructs a convex shape entry with identity transformation.
 ///</summary>
 ///<param name="shape">Shape of the entry.</param>
 public ConvexShapeEntry(ConvexShape shape)
 {
     Transform      = RigidTransform.Identity;
     CollisionShape = shape;
 }
예제 #5
0
 /// <summary>
 /// Constructs a convex shape entry.
 /// </summary>
 /// <param name="transform">Local transform of the entry.</param>
 /// <param name="shape">Shape of the entry.</param>
 public ConvexShapeEntry(RigidTransform transform, ConvexShape shape)
 {
     Transform      = transform;
     CollisionShape = shape;
 }
예제 #6
0
 /// <summary>
 /// Constructs a convex shape entry.
 /// </summary>
 /// <param name="orientation">Local orientation of the entry.</param>
 /// <param name="shape">Shape of the entry.</param>
 public ConvexShapeEntry(Quaternion orientation, ConvexShape shape)
 {
     Transform      = new RigidTransform(orientation);
     CollisionShape = shape;
 }
예제 #7
0
 /// <summary>
 /// Constructs a convex shape entry.
 /// </summary>
 /// <param name="position">Local position of the entry.</param>
 /// <param name="shape">Shape of the entry.</param>
 public ConvexShapeEntry(Vector3 position, ConvexShape shape)
 {
     Transform      = new RigidTransform(position);
     CollisionShape = shape;
 }