Пример #1
0
        public SweepResult Sweep(ConvexShape Shape, Vector3 From, Vector3 To)
        {
            ClosestConvexResult.ClosestHitFraction = 1.0f;
            ClosestConvexResult.ConvexFromWorld    = From;
            ClosestConvexResult.ConvexToWorld      = To;

            World.ConvexSweepTest(Shape, Matrix4x4.CreateTranslation(From), Matrix4x4.CreateTranslation(To), ClosestConvexResult);
            SweepResult Result = new SweepResult();

            Result.SweepFrom = From;
            Result.HasHit    = ClosestConvexResult.HasHit;
            Result.Fraction  = 1;
            Result.HitPoint  = Result.HitCenterOfMass = To;

            if (ClosestConvexResult.HasHit)
            {
                Result.Fraction = ClosestConvexResult.ClosestHitFraction;
                Result.Normal   = Vector3.Normalize(ClosestConvexResult.HitNormalWorld);

                Result.HitPoint        = ClosestConvexResult.HitPointWorld;
                Result.HitCenterOfMass = Vector3.Lerp(From, To, Result.Fraction);

                Result.Distance = Vector3.Distance(From, Result.HitCenterOfMass);
            }
            else
            {
                Result.Distance = Vector3.Distance(From, To);
            }

            return(Result);
        }