Esempio n. 1
0
        public CollisionResult MoveHitTestWithWorld(Vector3 velocityAmount)
        {
            CollideSphere playerSphere = Collide as CollideSphere;
            float radius = playerSphere.Radius;

            //  calculate simulated position for collision.
            Matrix transformSimulate = TransformedMatrix *
                                       Matrix.CreateTranslation(velocityAmount);

            // first, check using sphere.
            {
                CollideSphere simulateSphere =
                                new CollideSphere(playerSphere.LocalCenter, radius);

                simulateSphere.Transform(transformSimulate);
                simulateSphere.Id = playerSphere.Id;

                CollisionResult result = FrameworkCore.CollisionContext.HitTest(
                                                                simulateSphere,
                                                                ref colLayerMoveWorld,
                                                                ResultType.NearestOne);

                if (result != null)
                {
                    return result;
                }
            }

            //  second, check using ray.
            {
                Vector3 direction = velocityAmount;
                direction.Normalize();

                CollideRay simulateRay =
                        new CollideRay(playerSphere.BoundingSphere.Center, direction);

                simulateRay.Id = playerSphere.Id;

                CollisionResult result = FrameworkCore.CollisionContext.HitTest(
                                                                simulateRay,
                                                                ref colLayerMoveWorld,
                                                                ResultType.NearestOne);

                if (result != null)
                {
                    if (result.distance <= radius)
                        return result;
                }
            }

            return null;
        }
Esempio n. 2
0
        public CollisionResult MoveHitTestWithItem(Vector3 velocityAmount)
        {
            CollideSphere playerSphere = Collide as CollideSphere;
            float radius = playerSphere.Radius;

            //  creates simulation sphere for collision.
            Matrix transformSimulate = TransformedMatrix *
                                       Matrix.CreateTranslation(velocityAmount);

            CollideSphere sphereSimulate =
                            new CollideSphere(playerSphere.LocalCenter, radius);

            sphereSimulate.Transform(transformSimulate);
            sphereSimulate.Id = playerSphere.Id;

            //  checks for the collision with items.
            CollisionResult result = FrameworkCore.CollisionContext.HitTest(
                                                            sphereSimulate,
                                                            ref colLayerItems,
                                                            ResultType.NearestOne);

            if (result != null)
            {
                if (0.0f >= result.distance)
                {
                    return result;
                }
            }

            return null;
        }