69 LargeBox.max =
new TSVector(FP.MaxValue);
70 SmallBox.min =
new TSVector(FP.MaxValue);
71 SmallBox.max =
new TSVector(FP.MinValue);
91 internal void InverseTransform(ref
TSVector position, ref
TSMatrix orientation)
98 center.
x *= FP.Half; center.y *= FP.Half; center.z *= FP.Half;
102 halfExtents.
x *= FP.Half; halfExtents.y *= FP.Half; halfExtents.z *= FP.Half;
109 TSVector.
Add(ref center, ref halfExtents, out max);
113 public void Transform(ref
TSMatrix orientation)
123 max = center + halfExtents;
124 min = center - halfExtents;
132 #region public Ray/Segment Intersection 134 private bool Intersect1D(FP start, FP dir, FP min, FP max,
135 ref FP enter,ref FP exit)
139 FP t0 = (min - start) / dir;
140 FP t1 = (max - start) / dir;
142 if (t0 > t1) { FP tmp = t0; t0 = t1; t1 = tmp; }
144 if (t0 > exit || t1 < enter)
return false;
146 if (t0 > enter) enter = t0;
147 if (t1 < exit) exit = t1;
154 FP enter = FP.Zero, exit = FP.One;
156 if (!Intersect1D(origin.x, direction.x, min.x, max.x,ref enter,ref exit))
159 if (!Intersect1D(origin.y, direction.y, min.y, max.y, ref enter, ref exit))
162 if (!Intersect1D(origin.z, direction.z, min.z, max.z,ref enter,ref exit))
170 FP enter = FP.Zero, exit = FP.MaxValue;
172 if (!Intersect1D(origin.x, direction.x, min.x, max.x, ref enter, ref exit))
175 if (!Intersect1D(origin.y, direction.y, min.y, max.y, ref enter, ref exit))
178 if (!Intersect1D(origin.z, direction.z, min.z, max.z, ref enter, ref exit))
186 return SegmentIntersect(ref origin, ref direction);
191 return RayIntersect(ref origin, ref direction);
212 return ((((this.min.x <= point.x) && (point.x <=
this.max.x)) &&
213 ((
this.min.y <= point.y) && (point.y <=
this.max.y))) &&
223 #region public void GetCorners(JVector[] corners) 227 corners[0].
Set(this.min.x,
this.max.y,
this.max.z);
228 corners[1].
Set(this.max.x,
this.max.y,
this.max.z);
229 corners[2].
Set(this.max.x,
this.min.y,
this.max.z);
230 corners[3].
Set(this.min.x,
this.min.y,
this.max.z);
231 corners[4].
Set(this.min.x,
this.max.y,
this.min.z);
232 corners[5].
Set(this.max.x,
this.max.y,
this.min.z);
233 corners[6].
Set(this.max.x,
this.min.y,
this.min.z);
234 corners[7].
Set(this.min.x,
this.min.y,
this.min.z);
240 public void AddPoint(
TSVector point)
245 public void AddPoint(ref
TSVector point)
247 TSVector.
Max(ref this.max, ref point, out this.max);
248 TSVector.
Min(ref this.min, ref point, out this.min);
257 #region public static JBBox CreateFromPoints(JVector[] points) 264 for (
int i = 0; i < points.Length; i++)
266 TSVector.
Min(ref vector3, ref points[i], out vector3);
267 TSVector.
Max(ref vector2, ref points[i], out vector2);
269 return new TSBBox(vector3, vector2);
280 #region public ContainmentType Contains(JBBox box) 296 if ((((this.max.x >= box.min.x) && (
this.min.x <= box.max.x)) && ((
this.max.y >= box.min.y) && (
this.min.y <= box.max.y))) && ((
this.max.z >= box.min.z) && (
this.min.z <= box.max.z)))
298 result = ((((this.min.x <= box.min.x) && (box.max.x <=
this.max.x)) && ((this.min.y <= box.min.y) && (box.max.y <= this.max.y))) && ((this.min.z <= box.min.z) && (box.max.z <= this.max.z))) ?
ContainmentType.Contains :
ContainmentType.Intersects;
308 return new TSBBox (center - half, center + half);
317 #region public static JBBox CreateMerged(JBBox original, JBBox additional) 336 TSVector.
Min(ref original.min, ref additional.min, out vector2);
337 TSVector.
Max(ref original.max, ref additional.max, out vector);
338 result.min = vector2;
344 public TSVector center {
get {
return (min + max) * (FP.Half); } }
354 return size * FP.Half;
358 internal FP Perimeter
362 return (2 * FP.One) * ((max.x - min.x) * (max.y - min.y) +
363 (max.x - min.x) * (max.z - min.z) +
364 (max.z - min.z) * (max.y - min.y));
368 public override string ToString() {
369 return min +
"|" +
max;
static void Absolute(ref TSMatrix matrix, out TSMatrix result)
Changes every sign of the matrix entry to '+'
TSVector min
The maximum point of the box.
static void TransposedTransform(ref TSVector position, ref TSMatrix matrix, out TSVector result)
Transforms a vector by the transposed of the given Matrix.
ContainmentType Contains(ref TSBBox box)
Checks whether another bounding box is inside, outside or intersecting this box.
void GetCorners(TSVector[] corners)
Retrieves the 8 corners of the box.
static TSBBox CreateFromPoints(TSVector[] points)
Expands a bounding box with the volume 0 by all points given.
ContainmentType
Containment type used within the TSBBox structure.
ContainmentType Contains(TSVector point)
Checks wether a point is within a box or not.
Contains common math operations.
static readonly TSBBox LargeBox
Returns the largest box possible.
static TSVector Transform(TSVector position, TSMatrix matrix)
Transforms a vector by the given matrix.
ContainmentType Contains(TSBBox box)
Checks whether another bounding box is inside, outside or intersecting this box.
static void CreateMerged(ref TSBBox original, ref TSBBox additional, out TSBBox result)
Creates a new box containing the two given ones.
static TSBBox CreateMerged(TSBBox original, TSBBox additional)
Creates a new box containing the two given ones.
ContainmentType Contains(ref TSVector point)
Checks whether a point is inside, outside or intersecting a point.
FP x
The X component of the vector.
static readonly TSBBox SmallBox
Returns the smalltest box possible.
static TSVector Add(TSVector value1, TSVector value2)
Adds two vectors.
TSVector max
The minimum point of the box.
TSBBox(TSVector min, TSVector max)
Constructor
static TSVector Subtract(TSVector value1, TSVector value2)
Subtracts two vectors.
static TSVector Min(TSVector value1, TSVector value2)
Gets a vector with the minimum x,y and z values of both vectors.
void Set(FP x, FP y, FP z)
Sets all vector component to specific values.
static TSVector Max(TSVector value1, TSVector value2)
Gets a vector with the maximum x,y and z values of both vectors.
Bounding Box defined through min and max vectors.
static FP Epsilon
A small value often used to decide if numeric results are zero.