using System;
using System.Runtime.CompilerServices;
using OpenTK;
namespace SM.OGL.Mesh
{
///
/// Contains information about bounding boxes of meshes
///
public class BoundingBox
{
///
/// The minimum corner.
///
public Vector3 Min = Vector3.Zero;
///
/// The maximum corner.
///
public Vector3 Max = Vector3.Zero;
///
/// Returns specific configurations of corners
///
/// If true, it takes the X-value of maximum, otherwise the minimum.
/// If true, it takes the Y-value of maximum, otherwise the minimum.
/// If true, it takes the Z-value of maximum, otherwise the minimum.
///
public Vector3 this[bool x, bool y, bool z] => new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
///
/// Empty constructor
///
public BoundingBox() {}
///
/// Creates the bounding box with predefined min and max values
///
///
///
public BoundingBox(Vector3 min, Vector3 max)
{
Min = min;
Max = max;
}
///
/// Updates the bounding box.
///
///
public void Update(Vector2 vector)
{
for (int i = 0; i < 2; i++)
{
Min[i] = Math.Min(Min[i], vector[i]);
Max[i] = Math.Max(Max[i], vector[i]);
}
}
///
/// Updates the bounding box.
///
///
public void Update(Vector3 vector)
{
for (int i = 0; i < 3; i++)
{
Min[i] = Math.Min(Min[i], vector[i]);
Max[i] = Math.Max(Min[i], vector[i]);
}
}
}
}