示例#1
0
        public static AABB3D CreateMerged(AABB3D a, AABB3D b)
        {
            Vector3 min = Vector3.Min(a.Pos - a.HalfExtents, b.Pos - b.HalfExtents);
            Vector3 max = Vector3.Max(a.Pos + a.HalfExtents, b.Pos + b.HalfExtents);

            return(CreateFromMinMax(min, max));
        }
示例#2
0
        public bool Intersects(AABB3D b)
        {
            if (Math.Abs(this.Pos.X - b.Pos.X) > (this.HalfExtents.X + b.HalfExtents.X)) return false;
            if (Math.Abs(this.Pos.Y - b.Pos.Y) > (this.HalfExtents.Y + b.HalfExtents.Y)) return false;

            return true;
        }
示例#3
0
        public static AABB3D CreateMerged(AABB3D a, AABB3D b)
        {
            Vector3 min = Vector3.Min(a.Pos - a.HalfExtents, b.Pos - b.HalfExtents);
            Vector3 max = Vector3.Max(a.Pos + a.HalfExtents, b.Pos + b.HalfExtents);

            return CreateFromMinMax(min, max);
        }
示例#4
0
        public override void GenerateMotionAABB(float dt)
        {
            Vector3 predictedPos = Pos + (Vel * dt);

            Vector3 center = (Pos + predictedPos) / 2f;
            Vector3 halfExtents = new Vector3((Math.Abs(predictedPos.X - Pos.X) * 0.5f) + radius, (Math.Abs(predictedPos.Y - Pos.Y) * 0.5f) + radius, (Math.Abs(predictedPos.Z - Pos.Z) * 0.5f) + radius);

            motionBounds = new AABB3D(center, halfExtents);
        }
示例#5
0
        public PlaneBody(Vector3 normal, Vector3 p)
            : base(p, Vector3.Zero, 0f, 0, 0f)
        {
            this.normal = Vector3.Normalize(normal);
            this.p = p;

            //A line extends infinitely, so make our AABB as big as possible
            motionBounds = new AABB3D(Vector3.Zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue));
        }
示例#6
0
        public bool Intersects(AABB3D b)
        {
            if (Math.Abs(this.Pos.X - b.Pos.X) > (this.HalfExtents.X + b.HalfExtents.X))
            {
                return(false);
            }
            if (Math.Abs(this.Pos.Y - b.Pos.Y) > (this.HalfExtents.Y + b.HalfExtents.Y))
            {
                return(false);
            }

            return(true);
        }
示例#7
0
        public static Sphere CreateFromPoints(Vector3[] points)
        {
            Sphere sphere = new Sphere();
            AABB3D box    = AABB3D.CreateFromPoints(points);

            sphere.Pos = box.Pos;
            float maxDist = float.MinValue;

            for (int i = 0; i < points.Length; i++)
            {
                if ((points[i] - sphere.Pos).LengthSquared() > maxDist)
                {
                    maxDist = (points[i] - sphere.Pos).LengthSquared();
                }
            }

            maxDist = (float)Math.Sqrt(maxDist);

            sphere.Radius = maxDist;

            return(sphere);
        }