Exemplo n.º 1
0
        /// <summary>
        /// Converts all provided physics query hit infos retrieved from native code into managed physics query hits.
        /// </summary>
        /// <param name="scriptHits">Native physics query hits.</param>
        /// <returns>Converted managed physics query hits.</returns>
        private static PhysicsQueryHit[] ConvertPhysicsQueryHits(ScriptPhysicsQueryHit[] scriptHits)
        {
            PhysicsQueryHit[] output = new PhysicsQueryHit[scriptHits.Length];

            for (int i = 0; i < scriptHits.Length; i++)
            {
                ConvertPhysicsQueryHit(ref scriptHits[i], out output[i]);
            }

            return(output);
        }
Exemplo n.º 2
0
        /// <summary>Initializes the struct with default values.</summary>
        public static PhysicsQueryHit Default()
        {
            PhysicsQueryHit value = new PhysicsQueryHit();

            value.point       = new Vector3();
            value.normal      = new Vector3();
            value.uv          = new Vector2();
            value.distance    = 0f;
            value.triangleIdx = 0;
            value.collider    = null;

            return(value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs a sweep into the scene using a box and returns the closest found hit, if any.
        /// </summary>
        /// <param name="box">Box to sweep through the scene.</param>
        /// <param name="rotation">Orientation of the box.</param>
        /// <param name="unitDir">Unit direction towards which to perform the sweep.</param>
        /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
        /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.
        ///                     </param>
        /// <param name="max">Maximum distance at which to perform the query. Hits past this distance will not be detected.
        ///                   </param>
        /// <returns>True if something was hit, false otherwise.</returns>
        public static bool BoxCast(AABox box, Quaternion rotation, Vector3 unitDir, out PhysicsQueryHit hit,
                                   ulong layer = ulong.MaxValue, float max = float.MaxValue)
        {
            ScriptPhysicsQueryHit scriptHit = new ScriptPhysicsQueryHit();

            if (Internal_BoxCast(ref box, ref rotation, ref unitDir, out scriptHit, layer, max))
            {
                ConvertPhysicsQueryHit(ref scriptHit, out hit);
                return(true);
            }

            hit = new PhysicsQueryHit();
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Casts a ray into the scene and returns the closest found hit, if any.
        /// </summary>
        /// <param name="origin">Origin of the ray to cast into the scene.</param>
        /// <param name="unitDir">Unit direction of the ray to cast into the scene.</param>
        /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
        /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.
        ///                     </param>
        /// <param name="max">Maximum distance at which to perform the query. Hits past this distance will not be detected.
        ///                   </param>
        /// <returns>True if something was hit, false otherwise.</returns>
        public static bool RayCast(Vector3 origin, Vector3 unitDir, out PhysicsQueryHit hit,
                                   ulong layer = ulong.MaxValue, float max = float.MaxValue)
        {
            ScriptPhysicsQueryHit scriptHit = new ScriptPhysicsQueryHit();

            if (Internal_RayCast(ref origin, ref unitDir, out scriptHit, layer, max))
            {
                ConvertPhysicsQueryHit(ref scriptHit, out hit);
                return(true);
            }

            hit = new PhysicsQueryHit();
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checks does the ray hit this collider.
        /// </summary>
        /// <param name="origin">Origin of the ray to check.</param>
        /// <param name="unitDir">Unit direction of the ray to check.</param>
        /// <param name="hit">Information about the hit. Valid only if the method returns true.</param>
        /// <param name="maxDist">Maximum distance from the ray origin to search for hits.</param>
        /// <returns>True if the ray has hit the collider.</returns>
        public bool Raycast(Vector3 origin, Vector3 unitDir, out PhysicsQueryHit hit, float maxDist = float.MaxValue)
        {
            hit = new PhysicsQueryHit();

            if (native == null)
            {
                return(false);
            }

            ScriptPhysicsQueryHit scriptHit;
            bool wasHit = native.Raycast(origin, unitDir, out scriptHit, maxDist);

            hit.collider    = scriptHit.collider.Component;
            hit.distance    = scriptHit.distance;
            hit.normal      = scriptHit.normal;
            hit.point       = scriptHit.point;
            hit.triangleIdx = scriptHit.triangleIdx;
            hit.uv          = scriptHit.uv;

            return(wasHit);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs a sweep into the scene using a convex mesh and returns the closest found hit, if any.
        /// </summary>
        /// <param name="mesh">Mesh to sweep through the scene. Must be convex.</param>
        /// <param name="position">Starting position of the mesh.</param>
        /// <param name="rotation">Orientation of the mesh.</param>
        /// <param name="unitDir">Unit direction towards which to perform the sweep.</param>
        /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
        /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.
        ///                     </param>
        /// <param name="max">Maximum distance at which to perform the query. Hits past this distance will not be detected.
        ///                   </param>
        /// <returns>True if something was hit, false otherwise.</returns>
        public static bool ConvexCast(PhysicsMesh mesh, Vector3 position, Quaternion rotation,
                                      Vector3 unitDir, out PhysicsQueryHit hit, ulong layer = ulong.MaxValue, float max = float.MaxValue)
        {
            IntPtr meshPtr = IntPtr.Zero;

            if (mesh != null)
            {
                meshPtr = mesh.GetCachedPtr();
            }

            ScriptPhysicsQueryHit scriptHit = new ScriptPhysicsQueryHit();

            if (Internal_ConvexCast(meshPtr, ref position, ref rotation, ref unitDir, out scriptHit, layer, max))
            {
                ConvertPhysicsQueryHit(ref scriptHit, out hit);
                return(true);
            }

            hit = new PhysicsQueryHit();
            return(false);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Checks does the ray hit this collider.
 /// </summary>
 /// <param name="ray">Ray to check.</param>
 /// <param name="hit">Information about the hit. Valid only if the method returns true.</param>
 /// <param name="maxDist">Maximum distance from the ray origin to search for hits.</param>
 /// <returns>True if the ray has hit the collider.</returns>
 public bool Raycast(Ray ray, out PhysicsQueryHit hit, float maxDist)
 {
     return(Raycast(ray.origin, ray.direction, out hit, maxDist));
 }
Exemplo n.º 8
0
 private static extern bool Internal_rayCast0(ref Vector3 origin, ref Vector3 unitDir, out PhysicsQueryHit hit, ulong layer, float max);
Exemplo n.º 9
0
 /// <summary>Performs a sweep into the scene using a box and returns the closest found hit, if any.</summary>
 /// <param name="box">Box to sweep through the scene.</param>
 /// <param name="rotation">Orientation of the box.</param>
 /// <param name="unitDir">Unit direction towards which to perform the sweep.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.</param>
 /// <param name="max">
 /// Maximum distance at which to perform the query. Hits past this distance will not be detected.
 /// </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool BoxCast(AABox box, Quaternion rotation, Vector3 unitDir, out PhysicsQueryHit hit, ulong layer = 18446744073709551615, float max = 3.40282347E+38f)
 {
     return(Internal_boxCast(ref box, ref rotation, ref unitDir, out hit, layer, max));
 }
Exemplo n.º 10
0
 /// <summary>Performs a sweep into the scene using a sphere and returns the closest found hit, if any.</summary>
 /// <param name="sphere">Sphere to sweep through the scene.</param>
 /// <param name="unitDir">Unit direction towards which to perform the sweep.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.</param>
 /// <param name="max">
 /// Maximum distance at which to perform the query. Hits past this distance will not be detected.
 /// </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool SphereCast(Sphere sphere, Vector3 unitDir, out PhysicsQueryHit hit, ulong layer = 18446744073709551615, float max = 3.40282347E+38f)
 {
     return(Internal_sphereCast(ref sphere, ref unitDir, out hit, layer, max));
 }
Exemplo n.º 11
0
 /// <summary>Casts a ray into the scene and returns the closest found hit, if any.</summary>
 /// <param name="ray">Ray to cast into the scene.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.</param>
 /// <param name="max">
 /// Maximum distance at which to perform the query. Hits past this distance will not be detected.
 /// </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool RayCast(Ray ray, out PhysicsQueryHit hit, ulong layer = 18446744073709551615, float max = 3.40282347E+38f)
 {
     return(Internal_rayCast(ref ray, out hit, layer, max));
 }
Exemplo n.º 12
0
 /// <summary>Casts a ray into the scene and returns the closest found hit, if any.</summary>
 /// <param name="origin">Origin of the ray to cast into the scene.</param>
 /// <param name="unitDir">Unit direction of the ray to cast into the scene.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.</param>
 /// <param name="max">
 /// Maximum distance at which to perform the query. Hits past this distance will not be detected.
 /// </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool RayCast(Vector3 origin, Vector3 unitDir, out PhysicsQueryHit hit, ulong layer = 18446744073709551615, float max = 3.40282347E+38f)
 {
     return(Internal_rayCast0(ref origin, ref unitDir, out hit, layer, max));
 }
Exemplo n.º 13
0
 private static extern bool Internal_capsuleCast(ref Capsule capsule, ref Quaternion rotation, ref Vector3 unitDir, out PhysicsQueryHit hit, ulong layer, float max);
Exemplo n.º 14
0
 private static extern bool Internal_convexCast(RRef <PhysicsMesh> mesh, ref Vector3 position, ref Quaternion rotation, ref Vector3 unitDir, out PhysicsQueryHit hit, ulong layer, float max);
Exemplo n.º 15
0
 private static extern bool Internal_boxCast(ref AABox box, ref Quaternion rotation, ref Vector3 unitDir, out PhysicsQueryHit hit, ulong layer, float max);
Exemplo n.º 16
0
 private static extern bool Internal_sphereCast(ref Sphere sphere, ref Vector3 unitDir, out PhysicsQueryHit hit, ulong layer, float max);
Exemplo n.º 17
0
 /// <summary>
 /// Casts a ray into the scene and returns the closest found hit, if any.
 /// </summary>
 /// <param name="ray">Ray to cast into the scene.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.
 ///                     </param>
 /// <param name="max">Maximum distance at which to perform the query. Hits past this distance will not be detected.
 ///                   </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool RayCast(Ray ray, out PhysicsQueryHit hit, ulong layer = ulong.MaxValue, float max = float.MaxValue)
 {
     return(RayCast(ray.origin, ray.direction, out hit, layer, max));
 }
Exemplo n.º 18
0
 private static extern bool Internal_rayCast(ref Ray ray, out PhysicsQueryHit hit, ulong layer, float max);
Exemplo n.º 19
0
 /// <summary>Performs a sweep into the scene using a convex mesh and returns the closest found hit, if any.</summary>
 /// <param name="mesh">Mesh to sweep through the scene. Must be convex.</param>
 /// <param name="position">Starting position of the mesh.</param>
 /// <param name="rotation">Orientation of the mesh.</param>
 /// <param name="unitDir">Unit direction towards which to perform the sweep.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.</param>
 /// <param name="max">
 /// Maximum distance at which to perform the query. Hits past this distance will not be detected.
 /// </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool ConvexCast(RRef <PhysicsMesh> mesh, Vector3 position, Quaternion rotation, Vector3 unitDir, out PhysicsQueryHit hit, ulong layer = 18446744073709551615, float max = 3.40282347E+38f)
 {
     return(Internal_convexCast(mesh, ref position, ref rotation, ref unitDir, out hit, layer, max));
 }
Exemplo n.º 20
0
 /// <summary>Performs a sweep into the scene using a capsule and returns the closest found hit, if any.</summary>
 /// <param name="capsule">Capsule to sweep through the scene.</param>
 /// <param name="rotation">Orientation of the capsule.</param>
 /// <param name="unitDir">Unit direction towards which to perform the sweep.</param>
 /// <param name="hit">Information recorded about a hit. Only valid if method returns true.</param>
 /// <param name="layer">Layers to consider for the query. This allows you to ignore certain groups of objects.</param>
 /// <param name="max">
 /// Maximum distance at which to perform the query. Hits past this distance will not be detected.
 /// </param>
 /// <returns>True if something was hit, false otherwise.</returns>
 public static bool CapsuleCast(Capsule capsule, Quaternion rotation, Vector3 unitDir, out PhysicsQueryHit hit, ulong layer = 18446744073709551615, float max = 3.40282347E+38f)
 {
     return(Internal_capsuleCast(ref capsule, ref rotation, ref unitDir, out hit, layer, max));
 }
Exemplo n.º 21
0
        /// <summary>
        /// Converts a physics query hit info retrieved from native code into managed physics query hit.
        /// </summary>
        /// <param name="scriptHit">Native physics query hit info.</param>
        /// <param name="hit">Managed physics query hit info</param>
        private static void ConvertPhysicsQueryHit(ref ScriptPhysicsQueryHit scriptHit, out PhysicsQueryHit hit)
        {
            if (scriptHit.collider != null)
            {
                hit.collider = scriptHit.collider.Component;
            }
            else
            {
                hit.collider = null;
            }

            hit.distance    = scriptHit.distance;
            hit.normal      = scriptHit.normal;
            hit.point       = scriptHit.point;
            hit.triangleIdx = scriptHit.triangleIdx;
            hit.uv          = scriptHit.uv;
        }