Exemplo n.º 1
0
        unsafe RayCastResult GetRayCastResultFromNative(NativeRayCastResult *native)
        {
            RayCastResult result = new RayCastResult();

            if (native->shape != IntPtr.Zero)
            {
                result.Shape    = PhysXPhysicsWorld.Instance.GetShapeByNativePointer(native->shape);
                result.Position = native->worldImpact;
                result.Normal   = native->worldNormal;
                result.Distance = native->distance;
                if (result.Shape.ShapeType == Shape.Type.Mesh)
                {
                    MeshShape meshShape = (MeshShape)result.Shape;
                    if (meshShape.MeshType != MeshShape.MeshTypes.ConvexHullDecomposition)
                    {
                        result.TriangleID = native->faceID;
                    }
                }
                else if (result.Shape.ShapeType == Shape.Type.HeightField)
                {
                    result.TriangleID = native->faceID;
                }
                else
                {
                    result.TriangleID = 0;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        protected override RayCastResult OnRayCast(Ray ray, int contactGroup)
        {
            if (float.IsNaN(ray.Origin.X))
            {
                Log.Fatal("PhysicsWorld.RayCast: Single.IsNaN(ray.Origin.X)");
            }
            if (float.IsNaN(ray.Direction.X))
            {
                Log.Fatal("PhysicsWorld.RayCast: Single.IsNaN(ray.Direction.X)");
            }
            if (ray.Direction == Vec3.Zero)
            {
                return(new RayCastResult());
            }

            Vec3  normalDir = ray.Direction;
            float length    = normalDir.Normalize();
            Vec3  origin    = ray.Origin;
            int   count     = PhysXNativeWrapper.PhysXNativeScene.RayCast(nativeScene, ref origin, ref normalDir, length,
                                                                          GetContactGroupMask(contactGroup), false);

            if (count == 0)
            {
                return(new RayCastResult());
            }

            unsafe
            {
                NativeRayCastResult *results      = PhysXNativeScene.GetLastRayCastResults(nativeScene);
                NativeRayCastResult *nativeResult = results;
                return(GetRayCastResultFromNative(nativeResult));
            }
        }
Exemplo n.º 3
0
        unsafe protected override RayCastResult[] OnRayCastPiercing(Ray ray, int contactGroup)
        {
            if (float.IsNaN(ray.Origin.X))
            {
                Log.Fatal("PhysicsWorld.RayCast: Single.IsNaN(ray.Origin.X)");
            }
            if (float.IsNaN(ray.Direction.X))
            {
                Log.Fatal("PhysicsWorld.RayCast: Single.IsNaN(ray.Direction.X)");
            }
            if (ray.Direction == Vec3.Zero)
            {
                return(emptyPiercingRayCastResult);
            }

            Vec3  normalDir = ray.Direction;
            float length    = normalDir.Normalize();
            Vec3  origin    = ray.Origin;
            int   count     = PhysXNativeWrapper.PhysXNativeScene.RayCast(nativeScene, ref origin, ref normalDir,
                                                                          length, GetContactGroupMask(contactGroup), true);

            if (count == 0)
            {
                return(emptyPiercingRayCastResult);
            }

            NativeRayCastResult *results = PhysXNativeScene.GetLastRayCastResults(nativeScene);

            RayCastResult[]      items        = new RayCastResult[count];
            NativeRayCastResult *nativeResult = results;

            for (int n = 0; n < count; n++)
            {
                items[n] = GetRayCastResultFromNative(nativeResult);
                nativeResult++;
            }

            return(items);
        }