示例#1
0
        public static void ClosestHit(IntPtr rayOrigin,
                                      IntPtr rayDirection,
                                      float minDistance,
                                      float maxDistance,
                                      ref float hitDistance,
                                      ref Vector3 hitNormal,
                                      ref IntPtr hitMaterial,
                                      IntPtr userData)
        {
            if (s_origin == null)
            {
                s_origin = new float[3];
            }

            if (s_direction == null)
            {
                s_direction = new float[3];
            }

            Marshal.Copy(rayOrigin, s_origin, 0, 3);
            Marshal.Copy(rayDirection, s_direction, 0, 3);

            Vector3 o = new Vector3 {
                x = s_origin[0], y = s_origin[1], z = s_origin[2]
            };
            Vector3 d = new Vector3 {
                x = s_direction[0], y = s_direction[1], z = s_direction[2]
            };

            UnityEngine.Vector3 origin    = Common.ConvertVector(o);
            UnityEngine.Vector3 direction = Common.ConvertVector(d);

            origin += minDistance * direction;

            LayerMask layerMask = Scene.GetSteamAudioLayerMask();

            if (s_hits == null)
            {
                s_hits = new RaycastHit[1];
            }

            int numHits = Physics.RaycastNonAlloc(origin, direction, s_hits, maxDistance, layerMask);

            if (numHits == 0)
            {
                hitDistance = Mathf.Infinity;
                return;
            }

            hitDistance = s_hits[0].distance;
            hitNormal   = Common.ConvertVector(s_hits[0].normal);
            hitMaterial = Scene.GetSteamAudioMaterialBuffer(s_hits[0].collider.transform);
        }
示例#2
0
        public static void AnyHit(IntPtr rayOrigin,
                                  IntPtr rayDirection,
                                  float minDistance,
                                  float maxDistance,
                                  ref int hitExists,
                                  IntPtr userData)
        {
            if (s_origin == null)
            {
                s_origin = new float[3];
            }

            if (s_direction == null)
            {
                s_direction = new float[3];
            }

            Marshal.Copy(rayOrigin, s_origin, 0, 3);
            Marshal.Copy(rayDirection, s_direction, 0, 3);

            Vector3 o = new Vector3 {
                x = s_origin[0], y = s_origin[1], z = s_origin[2]
            };
            Vector3 d = new Vector3 {
                x = s_direction[0], y = s_direction[1], z = s_direction[2]
            };

            UnityEngine.Vector3 origin    = Common.ConvertVector(o);
            UnityEngine.Vector3 direction = Common.ConvertVector(d);

            origin += minDistance * direction;

            LayerMask layerMask = Scene.GetSteamAudioLayerMask();

            if (s_hits == null)
            {
                s_hits = new RaycastHit[1];
            }

            int numHits = Physics.RaycastNonAlloc(origin, direction, s_hits, maxDistance, layerMask);

            hitExists = (numHits > 0) ? 1 : 0;
        }
示例#3
0
        public static void AnyHit(float[] rayOrigin,
                                  float[] rayDirection,
                                  float minDistance,
                                  float maxDistance,
                                  ref int hitExists,
                                  IntPtr userData)
        {
            UnityEngine.Vector3 origin = Common.ConvertVector(new Vector3 {
                x = rayOrigin[0],
                y = rayOrigin[1],
                z = rayOrigin[2]
            });

            UnityEngine.Vector3 direction = Common.ConvertVector(new Vector3 {
                x = rayDirection[0],
                y = rayDirection[1],
                z = rayDirection[2]
            });

            origin += minDistance * direction;

#if IPL_USE_RAYCASTALL
            var hits = Physics.RaycastAll(origin, direction, maxDistance);

            hitExists = 0;
            foreach (var hit in hits)
            {
                if (Scene.HasSteamAudioGeometry(hit.collider.transform))
                {
                    hitExists = 1;
                    return;
                }
            }
#else
            LayerMask layerMask = Scene.GetSteamAudioLayerMask();

            var hitValid = Physics.Raycast(origin, direction, maxDistance, layerMask);
            hitExists = (hitValid) ? 1 : 0;
#endif
        }
示例#4
0
        public static void ClosestHit(float[] rayOrigin,
                                      float[] rayDirection,
                                      float minDistance,
                                      float maxDistance,
                                      ref float hitDistance,
                                      ref Vector3 hitNormal,
                                      ref IntPtr hitMaterial,
                                      IntPtr userData)
        {
            UnityEngine.Vector3 origin = Common.ConvertVector(new Vector3 {
                x = rayOrigin[0],
                y = rayOrigin[1],
                z = rayOrigin[2]
            });

            UnityEngine.Vector3 direction = Common.ConvertVector(new Vector3 {
                x = rayDirection[0],
                y = rayDirection[1],
                z = rayDirection[2]
            });

            origin += minDistance * direction;

#if IPL_USE_RAYCASTALL
            var hits = Physics.RaycastAll(origin, direction, maxDistance);

            hitDistance = Mathf.Infinity;
            var closestHit = new RaycastHit();
            var found      = false;
            foreach (var hit in hits)
            {
                if (Scene.HasSteamAudioGeometry(hit.collider.transform))
                {
                    if (hit.distance < hitDistance)
                    {
                        hitDistance = hit.distance;
                        closestHit  = hit;
                        found       = true;
                    }
                }
            }

            if (found)
            {
                hitNormal   = Common.ConvertVector(closestHit.normal); // FIXME: not the correct transform?
                hitMaterial = Scene.GetSteamAudioMaterialBuffer(closestHit.collider.transform);
            }
#else
            LayerMask layerMask = Scene.GetSteamAudioLayerMask();

            RaycastHit hit;
            var        hitValid = Physics.Raycast(origin, direction, out hit, maxDistance, layerMask);
            if (!hitValid)
            {
                hitDistance = Mathf.Infinity;
                return;
            }

            hitDistance = hit.distance;
            hitNormal   = Common.ConvertVector(hit.normal);
            hitMaterial = Scene.GetSteamAudioMaterialBuffer(hit.collider.transform);
#endif
        }