Пример #1
0
 /// <summary>
 /// Intersect a segment with the world. If non-zero the predicate
 /// allows certain skins to be excluded
 /// </summary>
 /// <param name="seg"></param>
 /// <param name="collisionPredicate"></param>
 /// <returns></returns>
 public abstract bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut,
                                       Segment seg, CollisionSkinPredicate1 collisionPredicate);
Пример #2
0
        /// <summary>
        /// SegmentIntersect
        /// </summary>
        /// <param name="fracOut"></param>
        /// <param name="skinOut"></param>
        /// <param name="posOut"></param>
        /// <param name="normalOut"></param>
        /// <param name="seg"></param>
        /// <param name="collisionPredicate"></param>
        /// <returns>bool</returns>
        public override bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Microsoft.Xna.Framework.Vector3 posOut, out Microsoft.Xna.Framework.Vector3 normalOut, JigLibX.Geometry.Segment seg, CollisionSkinPredicate1 collisionPredicate)
        {
            fracOut = float.MaxValue;
            skinOut = null;
            posOut  = normalOut = Vector3.Zero;

            float   frac;
            Vector3 pos;
            Vector3 normal;

            Vector3 segmentBeginning = seg.Origin;
            Vector3 segmentEnd       = seg.Origin + seg.Delta;

            Vector3 min = Vector3.Min(segmentBeginning, segmentEnd);
            Vector3 max = Vector3.Max(segmentBeginning, segmentEnd);

            active_.Clear();

            BoundingBox box = new BoundingBox(min, max);

            Extract(min, max, active_);

            float distanceSquared = float.MaxValue;
            int   nActive         = active_.Count;

            for (int i = 0; i != nActive; ++i)
            {
                CollisionSkin skin = active_[i];
                if (collisionPredicate == null || collisionPredicate.ConsiderSkin(skin))
                {
                    if (BoundingBoxHelper.OverlapTest(ref box, ref skin.WorldBoundingBox))
                    {
                        if (skin.SegmentIntersect(out frac, out pos, out normal, seg))
                        {
                            if (frac >= 0)
                            {
                                float newDistanceSquared = Vector3.DistanceSquared(segmentBeginning, pos);
                                if (newDistanceSquared < distanceSquared)
                                {
                                    distanceSquared = newDistanceSquared;

                                    fracOut   = frac;
                                    skinOut   = skin;
                                    posOut    = pos;
                                    normalOut = normal;
                                }
                            }
                        }
                    }
                }
            }

            return(fracOut <= 1);
        }
Пример #3
0
 /// <summary>
 /// Intersect a segment with the world. If non-zero the predicate
 /// allows certain skins to be excluded
 /// </summary>
 /// <param name="seg"></param>
 /// <param name="collisionPredicate"></param>
 /// <returns></returns>
 public abstract bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut,
     Segment seg, CollisionSkinPredicate1 collisionPredicate);
Пример #4
0
        public override bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Microsoft.Xna.Framework.Vector3 posOut, out Microsoft.Xna.Framework.Vector3 normalOut, JigLibX.Geometry.Segment seg, CollisionSkinPredicate1 collisionPredicate)
        {
            fracOut = float.MaxValue;
            skinOut = null;
            posOut  = normalOut = Vector3.Zero;

            Vector3 min = seg.GetPoint(0);
            Vector3 tmp = seg.GetEnd();
            Vector3 max;

            Vector3.Max(ref min, ref tmp, out max);
            Vector3.Min(ref min, ref tmp, out min);

            BoundingBox box = new BoundingBox(min, max);
            float       frac;
            Vector3     pos;
            Vector3     normal;

            active_.Clear();
            Extract(min, max, active_);

            int nActive = active_.Count;

            for (int i = 0; i != nActive; ++i)
            {
                CollisionSkin skin = active_[i];
                if (collisionPredicate == null || collisionPredicate.ConsiderSkin(skin))
                {
                    if (BoundingBoxHelper.OverlapTest(ref box, ref skin.WorldBoundingBox))
                    {
                        if (skin.SegmentIntersect(out frac, out pos, out normal, seg))
                        {
                            if (frac >= 0 && frac < fracOut)
                            {
                                fracOut   = frac;
                                skinOut   = skin;
                                posOut    = pos;
                                normalOut = normal;
                            }
                        }
                    }
                }
            }
            return(fracOut <= 1);
        }
        public override bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut, Segment seg, CollisionSkinPredicate1 collisionPredicate)
        {
            int numSkins = skins.Count;
            BoundingBox segBox = BoundingBoxHelper.InitialBox;
            BoundingBoxHelper.AddSegment(seg, ref segBox);

            //initialise the outputs
            fracOut = float.MaxValue;
            skinOut = null;
            posOut = normalOut = Vector3.Zero;

            // working vars
            float frac;
            Vector3 pos;
            Vector3 normal;

            for (int iskin = 0; iskin < numSkins; ++iskin)
            {
                CollisionSkin skin = skins[iskin];
                if ((collisionPredicate == null) ||
                    collisionPredicate.ConsiderSkin(skin))
                {
                    // basic bbox test
                    if (BoundingBoxHelper.OverlapTest(ref skin.WorldBoundingBox, ref segBox))
                    {
                        if (skin.SegmentIntersect(out frac, out pos, out normal, seg))
                        {
                            if (frac < fracOut)
                            {
                                posOut = pos;
                                normalOut = normal;
                                skinOut = skin;
                                fracOut = frac;
                            }
                        }

                    }
                }
            }

            if (fracOut > 1.0f) return false;
            fracOut = MathHelper.Clamp(fracOut, 0.0f, 1.0f);
            return true;
        }
Пример #6
0
        }             // void

        public override bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut, Segment seg, CollisionSkinPredicate1 collisionPredicate)
        {
            int         numSkins = skins.Count;
            BoundingBox segBox   = BoundingBoxHelper.InitialBox;

            BoundingBoxHelper.AddSegment(seg, ref segBox);

            //initialise the outputs
            fracOut = float.MaxValue;
            skinOut = null;
            posOut  = normalOut = Vector3.Zero;

            // working vars
            float   frac;
            Vector3 pos;
            Vector3 normal;

            for (int iskin = 0; iskin < numSkins; ++iskin)
            {
                CollisionSkin skin = skins[iskin];
                if ((collisionPredicate == null) ||
                    collisionPredicate.ConsiderSkin(skin))
                {
                    // basic bbox test
                    if (BoundingBoxHelper.OverlapTest(ref skin.WorldBoundingBox, ref segBox))
                    {
                        if (skin.SegmentIntersect(out frac, out pos, out normal, seg))
                        {
                            if (frac < fracOut)
                            {
                                posOut    = pos;
                                normalOut = normal;
                                skinOut   = skin;
                                fracOut   = frac;
                            }
                        }
                    }
                }
            }

            if (fracOut > 1.0f)
            {
                return(false);
            }
            fracOut = MathHelper.Clamp(fracOut, 0.0f, 1.0f);
            return(true);
        }
Пример #7
0
        public override bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut, Segment seg, CollisionSkinPredicate1 collisionPredicate)
        {
            fracOut = float.MaxValue;
            skinOut = null;
            posOut  = normalOut = Vector3.Zero;

            var segmentBeginning = seg.Origin;
            var segmentEnd       = seg.Origin + seg.Delta;

            var min = Vector3.Min(segmentBeginning, segmentEnd);
            var max = Vector3.Max(segmentBeginning, segmentEnd);

            active_.Clear();

            var box = new BoundingBox(min, max);

            Extract(min, max, active_);

            var distanceSquared = float.MaxValue;
            var nActive         = active_.Count;

            for (var i = 0; i != nActive; ++i)
            {
                var skin = active_[i];
                if (collisionPredicate == null || collisionPredicate.ConsiderSkin(skin))
                {
                    if (BoundingBoxHelper.OverlapTest(ref box, ref skin.WorldBoundingBox))
                    {
                        if (skin.SegmentIntersect(out var frac, out var pos, out var normal, seg))
                        {
                            if (frac >= 0)
                            {
                                var newDistanceSquared = Vector3.DistanceSquared(segmentBeginning, pos);
                                if (newDistanceSquared < distanceSquared)
                                {
                                    distanceSquared = newDistanceSquared;

                                    fracOut   = frac;
                                    skinOut   = skin;
                                    posOut    = pos;
                                    normalOut = normal;
                                }
                            }
                        }
                    }
                }
            }

            return(fracOut <= 1);
        }