コード例 #1
0
        private bool IntersectsWithSelection(Vehicle vehicle, Vector2 topLeftV, Vector2 bottomRightV)
        {
            //Buffer selection
            topLeftV.X     -= 20f;
            topLeftV.Y     -= 20f;
            bottomRightV.X += 20f;
            bottomRightV.Y += 20f;

            //Cheap calculation if our selection box has intersected with the center of a vehicle
            Vector2 vehicleLocation = vehicle.GetPosition();

            if (vehicleLocation.X > topLeftV.X && vehicleLocation.X < bottomRightV.X && vehicleLocation.Y > topLeftV.Y && vehicleLocation.Y < bottomRightV.Y)
            {
                return(true);
            }

            //Else we will do a rotated bounding box detection
            BoundingBox boundingBoxVehicle   = new BoundingBox(vehicle.GetSize(), vehicleLocation, vehicle.GetDirectionRadian());
            BoundingBox boundingBoxSelection = new BoundingBox(topLeftV, bottomRightV);

            return(Intersects.IsBoundingBoxCollision(boundingBoxVehicle, boundingBoxSelection));
        }