Beispiel #1
0
        private bool InternalRayTest(Vec3 ray_origin, Vec3 ray_dir, ref Vec3 result, int num_dim)
        {
            // implementation based upon https://www.gamedev.net/forums/topic/495636-raybox-collision-intersection-point/
            Vec3 tmin = (Min - ray_origin) / ray_dir;
            Vec3 tmax = (Max - ray_origin) / ray_dir;

            Vec3 real_min = Vec3.Min(tmin, tmax);
            Vec3 real_max = Vec3.Max(tmin, tmax);

            float minmax = Math.Min(real_max.X, real_max.Y);
            float maxmin = Math.Max(real_min.X, real_min.Y);

            if (num_dim > 2)
            {
                minmax = Math.Min(minmax, real_max.Z);
                maxmin = Math.Max(maxmin, real_min.Z);
            }

            // when both values are negative origin is 'after' aabb when looking in ray direction
            if (minmax >= maxmin && minmax >= 0)
            {
                // when maxmin is negative we are inside the aabb
                result = new Vec3(ray_origin + ray_dir * (maxmin < 0 ? minmax : maxmin));
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public AABB Extend(AABB aabb)
        {
            if (IsZero())
            {
                return(aabb);
            }

            return(new AABB(Vec3.Min(Min, aabb.Min), Vec3.Max(Max, aabb.Max)));
        }
Beispiel #3
0
        public AABB Intersect(AABB aabb, bool tangential_ok = false)
        {
            if (!Overlaps2D(aabb, tangential_ok))
            {
                return(null);
            }

            return(new AABB(Vec3.Max(min, aabb.min), Vec3.Min(max, aabb.max)));
        }
Beispiel #4
0
        public bool Intersect(AABB aabb, ref AABB output, bool tangential_ok = false)
        {
            if (!Overlaps2D(aabb, tangential_ok))
            {
                return(false);
            }

            output.Min = Vec3.Max(Min, aabb.Min);
            output.Max = Vec3.Min(Max, aabb.Max);
            return(true);
        }
Beispiel #5
0
        public void Extend(AABB aabb)
        {
            if (IsZero())
            {
                Min = new Vec3(aabb.Min);
                Max = new Vec3(aabb.Max);
                return;
            }

            Min = Vec3.Min(Min, aabb.Min);
            Max = Vec3.Max(Max, aabb.Max);
        }
Beispiel #6
0
        public AABB Intersect2D(AABB aabb, bool tangential_ok = false)
        {
            if (!Overlaps2D(aabb, tangential_ok))
            {
                return(null);
            }

            AABB inter = new AABB(Vec3.Max(min, aabb.min), Vec3.Min(max, aabb.max));

            inter.min.Z = inter.max.Z = 0;
            return(inter);
        }
Beispiel #7
0
        public void Extend(AABB aabb)
        {
            if (is_empty)
            {
                min      = new Vec3(aabb.min);
                max      = new Vec3(aabb.max);
                is_empty = aabb.is_empty;
                return;
            }

            min = Vec3.Min(min, aabb.min);
            max = Vec3.Max(max, aabb.max);
        }
Beispiel #8
0
 public Vec3 Align(Vec3 p)
 {
     return(Vec3.Min(Vec3.Max(Min, p), Max));
 }
Beispiel #9
0
 public static AABB Mininum(AABB aabb1, AABB aabb2)
 {
     return(new AABB(Vec3.Max(aabb1.Min, aabb2.Min), Vec3.Min(aabb1.Max, aabb2.Max)));
 }
Beispiel #10
0
 public AABB Extend(Vec3 point)
 {
     return(new AABB(Vec3.Min(Min, point), Vec3.Max(Max, point)));
 }