Exemplo n.º 1
0
        public static bool CastRay(Vector3D from, Vector3D to, out HitInfo hitInfo, uint raycastCollisionFilter, bool ignoreConvexShape)
        {
            m_resultWorlds.Clear();
            Clusters.CastRay(from, to, m_resultWorlds);

            hitInfo = new HitInfo();
            foreach (var world in m_resultWorlds)
            {
                Vector3 fromF = from - world.AABB.Center;
                Vector3 toF   = to - world.AABB.Center;

                m_resultHits.Clear();
                HkWorld.HitInfo info = new HkWorld.HitInfo();
                bool            hit  = ((HkWorld)world.UserData).CastRay(fromF, toF, out info, raycastCollisionFilter, ignoreConvexShape);

                if (hit)
                {
                    hitInfo.Position  = (Vector3D)info.Position + world.AABB.Center;
                    hitInfo.HkHitInfo = info;
                    m_resultWorlds.Clear();
                    return(hit);
                }
            }
            m_resultWorlds.Clear();

            return(false);
        }
Exemplo n.º 2
0
        public static HitInfo?CastShapeReturnContactBodyData(Vector3D to, HkShape shape, ref MatrixD transform, uint collisionFilter, float extraPenetration, bool ignoreConvexShape = true)
        {
            m_resultWorlds.Clear();
            Clusters.Intersects(to, m_resultWorlds);

            if (m_resultWorlds.Count == 0)
            {
                return(null);
            }

            var world = m_resultWorlds[0];

            Matrix transformF = transform;

            transformF.Translation = (Vector3)(transform.Translation - world.AABB.Center);

            Vector3 toF = (Vector3)(to - world.AABB.Center);

            HkWorld.HitInfo?result = ((HkWorld)world.UserData).CastShapeReturnContactBodyData(toF, shape, ref transformF, collisionFilter, extraPenetration);
            if (result == null)
            {
                return(null);
            }
            HkWorld.HitInfo cpd     = result.Value;
            HitInfo         hitInfo = new HitInfo(cpd, cpd.Position + world.AABB.Center);

            return(hitInfo);
        }
Exemplo n.º 3
0
        public static float GetConvexRadius(this HkWorld.HitInfo hitInfo)
        {
            foreach (var shape in hitInfo.Body.GetShape().GetAllShapes())
            {
                if (shape.IsConvex)
                {
                    return(shape.ConvexRadius);
                }
            }

            return(0);
        }
        public static float GetConvexRadius(this HkWorld.HitInfo hitInfo)
        {
            if (hitInfo.Body == null)
            {
                return(0);
            }

            HkShape shape = hitInfo.Body.GetShape();

            for (int i = 0; i < HkWorld.HitInfo.ShapeKeyCount; i++)
            {
                var shapeKey = hitInfo.GetShapeKey(i);
                if (HkShape.InvalidShapeKey != shapeKey)
                {
                    if (!shape.IsContainer())
                    {
                        break;
                    }
                    //shape = shape.GetContainer().GetShape(shapeKey);
                }
                else
                {
                    break;
                }
            }
            if (shape.ShapeType == HkShapeType.ConvexTransform || shape.ShapeType == HkShapeType.ConvexTranslate || shape.ShapeType == HkShapeType.Transform)
            {
                shape = shape.GetContainer().GetShape(0);
            }
            if (shape.ShapeType == HkShapeType.Sphere || shape.ShapeType == HkShapeType.Capsule)
            {
                return(0);
            }
            if (!shape.IsConvex)
            {
                return(HkConvexShape.DefaultConvexRadius);
            }

            return(shape.ConvexRadius);
        }
Exemplo n.º 5
0
        public static bool CastShapeReturnContactBodyDatas(Vector3D to, HkShape shape, ref MatrixD transform, uint collisionFilter, float extraPenetration, List <HitInfo> result, bool ignoreConvexShape = true)
        {
            m_resultWorlds.Clear();
            Clusters.Intersects(to, m_resultWorlds);

            if (m_resultWorlds.Count == 0)
            {
                return(false);
            }

            var world = m_resultWorlds[0];

            Matrix transformF = transform;

            transformF.Translation = (Vector3)(transform.Translation - world.AABB.Center);

            Vector3 toF = (Vector3)(to - world.AABB.Center);

            m_resultShapeCasts.Clear();

            if (((HkWorld)world.UserData).CastShapeReturnContactBodyDatas(toF, shape, ref transformF, collisionFilter, extraPenetration, m_resultShapeCasts))
            {
                foreach (var res in m_resultShapeCasts)
                {
                    HkWorld.HitInfo cpd     = res.Value;
                    HitInfo         hitInfo = new HitInfo()
                    {
                        HkHitInfo = cpd,
                        Position  = cpd.Position + world.AABB.Center
                    };
                    result.Add(hitInfo);
                }

                return(true);
            }


            return(false);
        }
Exemplo n.º 6
0
        public static bool CastRay(Vector3D from, Vector3D to, out HitInfo hitInfo, uint raycastCollisionFilter, bool ignoreConvexShape)
        {
            m_resultWorlds.Clear();
            Clusters.CastRay(from, to, m_resultWorlds);

            hitInfo = new HitInfo();
            foreach (var world in m_resultWorlds)
            {
                Vector3 fromF = from - world.AABB.Center;
                Vector3 toF = to - world.AABB.Center;

                m_resultHits.Clear();
                HkWorld.HitInfo info = new HkWorld.HitInfo();
                bool hit = ((HkWorld)world.UserData).CastRay(fromF, toF, out info, raycastCollisionFilter, ignoreConvexShape);

                if (hit)
                {
                    hitInfo.Position = (Vector3D)info.Position + world.AABB.Center;
                    hitInfo.HkHitInfo = info;
                    m_resultWorlds.Clear();
                    return hit;
                }
            }
            m_resultWorlds.Clear();

            return false;
        }
 public static IMyEntity GetHitEntity(this HkWorld.HitInfo hitInfo)
 {
     return(hitInfo.Body.GetEntity(hitInfo.GetShapeKey(0)));
 }
Exemplo n.º 8
0
 public HitInfo(HkWorld.HitInfo hi, Vector3D worldPosition)
 {
     HkHitInfo = hi;
     Position  = worldPosition;
 }