30 using System.Globalization;
31 using System.Runtime.InteropServices;
32 using System.ComponentModel;
33 using SiliconStudio.Core.Serialization;
35 namespace SiliconStudio.Core.Mathematics
41 [StructLayout(LayoutKind.Sequential, Pack = 4)]
66 this.Minimum = minimum;
67 this.Maximum = maximum;
75 get {
return (Minimum + Maximum)/2; }
83 get {
return (Maximum - Minimum) / 2; }
93 results[0] =
new Vector3(Minimum.X, Maximum.Y, Maximum.Z);
94 results[1] =
new Vector3(Maximum.X, Maximum.Y, Maximum.Z);
95 results[2] =
new Vector3(Maximum.X, Minimum.Y, Maximum.Z);
96 results[3] =
new Vector3(Minimum.X, Minimum.Y, Maximum.Z);
97 results[4] =
new Vector3(Minimum.X, Maximum.Y, Minimum.Z);
98 results[5] =
new Vector3(Maximum.X, Maximum.Y, Minimum.Z);
99 results[6] =
new Vector3(Maximum.X, Minimum.Y, Minimum.Z);
100 results[7] =
new Vector3(Minimum.X, Minimum.Y, Minimum.Z);
112 return Collision.RayIntersectsBox(ref ray, ref
this, out distance);
124 return Collision.RayIntersectsBox(ref ray, ref
this, out distance);
136 return Collision.RayIntersectsBox(ref ray, ref
this, out point);
146 return Collision.PlaneIntersectsBox(ref plane, ref
this);
157 public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
159 return Collision.BoxIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3);
170 return Collision.BoxIntersectsBox(ref
this, ref box);
180 return Collision.BoxIntersectsSphere(ref
this, ref sphere);
190 return Collision.BoxContainsPoint(ref
this, ref point);
201 public ContainmentType Contains(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
203 return Collision.BoxContainsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3);
214 return Collision.BoxContainsBox(ref
this, ref box);
224 return Collision.BoxContainsSphere(ref
this, ref sphere);
236 throw new ArgumentNullException(
"points");
241 for (
int i = 0; i < points.Length; ++i)
243 Vector3.Min(ref min, ref points[i], out min);
244 Vector3.Max(ref max, ref points[i], out max);
259 throw new ArgumentNullException(
"points");
264 for (
int i = 0; i < points.Length; ++i)
266 Vector3.Min(ref min, ref points[i], out min);
267 Vector3.Max(ref max, ref points[i], out max);
280 result.Minimum =
new Vector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius);
281 result.Maximum =
new Vector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius);
305 Vector3.Min(ref value1.Minimum, ref value2, out result.Minimum);
306 Vector3.Max(ref value1.Maximum, ref value2, out result.Maximum);
317 Vector3.Min(ref value1.Minimum, ref value2.Minimum, out result.Minimum);
318 Vector3.Max(ref value1.Maximum, ref value2.Maximum, out result.Maximum);
330 Vector3.Min(ref value1.Minimum, ref value2.Minimum, out box.Minimum);
331 Vector3.Max(ref value1.Maximum, ref value2.Maximum, out box.Maximum);
343 return left.Equals(right);
354 return !left.Equals(right);
365 return string.Format(CultureInfo.CurrentCulture,
"Minimum:{0} Maximum:{1}", Minimum.ToString(), Maximum.ToString());
380 return string.Format(CultureInfo.CurrentCulture,
"Minimum:{0} Maximum:{1}", Minimum.ToString(
format, CultureInfo.CurrentCulture),
381 Maximum.ToString(format, CultureInfo.CurrentCulture));
391 public string ToString(IFormatProvider formatProvider)
393 return string.Format(formatProvider,
"Minimum:{0} Maximum:{1}", Minimum.ToString(), Maximum.ToString());
407 return ToString(formatProvider);
409 return string.Format(formatProvider,
"Minimum:{0} Maximum:{1}", Minimum.ToString(
format, formatProvider),
410 Maximum.ToString(format, formatProvider));
421 return Minimum.GetHashCode() + Maximum.GetHashCode();
433 return Minimum == value.Minimum && Maximum == value.Maximum;
443 public override bool Equals(
object value)
448 if (value.GetType() != GetType())
460 public static implicit
operator SlimDX.BoundingBox(
BoundingBox value)
462 return new SlimDX.BoundingBox(value.Minimum, value.Maximum);
470 public static implicit
operator BoundingBox(SlimDX.BoundingBox value)
472 return new BoundingBox(value.Minimum, value.Maximum);
482 public static implicit
operator Microsoft.Xna.Framework.BoundingBox(BoundingBox value)
484 return new Microsoft.Xna.Framework.BoundingBox(value.Minimum, value.Maximum);
492 public static implicit
operator BoundingBox(Microsoft.Xna.Framework.BoundingBox value)
494 return new BoundingBox(value.Min, value.Max);
Represents an axis-aligned bounding box in three dimensional space.
override bool Equals(object value)
Determines whether the specified System.Object is equal to this instance.
bool Equals(BoundingBox value)
Determines whether the specified SiliconStudio.Core.Mathematics.Vector4 is equal to this instance...
BoundingBox(Vector3 minimum, Vector3 maximum)
Initializes a new instance of the SiliconStudio.Core.Mathematics.BoundingBox struct.
string ToString(string format)
Returns a System.String that represents this instance.
float Y
The Y component of the vector.
bool Intersects(ref Ray ray)
Determines if there is an intersection between the current object and a SiliconStudio.Core.Mathematics.Ray.
override int GetHashCode()
Returns a hash code for this instance.
bool Intersects(ref BoundingBox box)
Determines if there is an intersection between the current object and a SiliconStudio.Core.Mathematics.BoundingBox.
static BoundingBox Merge(BoundingBox value1, BoundingBox value2)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox that is as large as the total combined area o...
float X
The X component of the vector.
Represents a three dimensional mathematical vector.
ContainmentType Contains(ref Vector3 point)
Determines whether the current objects contains a point.
override string ToString()
Returns a System.String that represents this instance.
static void Merge(ref BoundingBox value1, ref BoundingBox value2, out BoundingBox result)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox that is as large as the total combined area o...
Vector3 Minimum
The minimum point of the box.
Represents a bounding sphere in three dimensional space.
static void FromPoints(Vector3[] points, out BoundingBox result)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox that fully contains the given points...
PlaneIntersectionType Intersects(ref Plane plane)
Determines if there is an intersection between the current object and a SiliconStudio.Core.Mathematics.Plane.
static void FromSphere(ref BoundingSphere sphere, out BoundingBox result)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox from a given sphere.
bool Intersects(ref BoundingSphere sphere)
Determines if there is an intersection between the current object and a SiliconStudio.Core.Mathematics.BoundingSphere.
Represents a plane in three dimensional space.
ContainmentType
Describes how one bounding volume contains another.
Vector3 Center
The center of the sphere in three dimensional space.
static BoundingBox FromPoints(Vector3[] points)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox that fully contains the given points...
Vector3 Maximum
The maximum point of the box.
Represents a three dimensional line based on a point in space and a direction.
PlaneIntersectionType
Describes the result of an intersection with a plane in three dimensions.
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
bool Intersects(ref Ray ray, out float distance)
Determines if there is an intersection between the current object and a SiliconStudio.Core.Mathematics.Ray.
SiliconStudio.Core.Mathematics.Vector3 Vector3
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
float Z
The Z component of the vector.
Vector3[] GetCorners()
Retrieves the eight corners of the bounding box.
bool Intersects(ref Ray ray, out Vector3 point)
Determines if there is an intersection between the current object and a SiliconStudio.Core.Mathematics.Ray.
ContainmentType Contains(ref BoundingSphere sphere)
Determines whether the current objects contains a SiliconStudio.Core.Mathematics.BoundingSphere.
ContainmentType Contains(ref BoundingBox box)
Determines whether the current objects contains a SiliconStudio.Core.Mathematics.BoundingBox.
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
static BoundingBox FromSphere(BoundingSphere sphere)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox from a given sphere.
float Radius
The radious of the sphere.
static void Merge(ref BoundingBox value1, ref Vector3 value2, out BoundingBox result)
Constructs a SiliconStudio.Core.Mathematics.BoundingBox that is as large enough to contains the bound...