6namespace XXSharpKmyMath
15 Aabb(
const Vector3 min,
const Vector3 max)
26 Vector3 getCenter() {
return center; }
27 void setCenter(Vector3 v) { center = v; }
28 Vector3 getSize() {
return Vector3(hsize.x * 2, hsize.y * 2, hsize.z * 2); }
29 void setSize(Vector3 v) { hsize = v * 0.5f; }
31 Vector3 getMin() {
return center + -hsize; }
32 Vector3 getMax() {
return center + hsize; }
33 float getVolume() {
return hsize.x * 2 * hsize.y * 2 * hsize.z * 2; }
40 void inflateRate(
float r)
45 bool intersect(Aabb^ p)
47 Vector3 min = getMin();
48 Vector3 max = getMax();
49 Vector3 pmin = p->getMin();
50 Vector3 pmax = p->getMax();
53 (min.x <= pmax.x && max.x >= pmin.x) &&
54 (min.y <= pmax.y && max.y >= pmin.y) &&
55 (min.z <= pmax.z && max.z >= pmin.z);
58 bool intersectAabb(Aabb^ p, Aabb^res)
60 Vector3 min = getMin();
61 Vector3 max = getMax();
62 Vector3 pmin = p->getMin();
63 Vector3 pmax = p->getMax();
65 Vector3 _min(0), _max(0);
67 res->construct(_min, _max);
69 if (min.x > pmax.x || max.x < pmin.x)
70 return (res->getVolume() > 0);
73 _min.x = (min.x > pmin.x) ? min.x : pmin.x;
74 _max.x = (max.x < pmax.x) ? max.x : pmax.x;
77 if (min.y > pmax.y || max.y < pmin.y)
78 return (res->getVolume() > 0);
81 _min.y = (min.y > pmin.y) ? min.y : pmin.y;
82 _max.y = (max.y < pmax.y) ? max.y : pmax.y;
85 if (min.z > pmax.z || max.z < pmin.z)
86 return (res->getVolume() > 0);
89 _min.z = (min.z > pmin.z) ? min.z : pmin.z;
90 _max.z = (max.z < pmax.z) ? max.z : pmax.z;
92 res->construct(_min, _max);
93 return (res->getVolume() > 0);
96 bool intersectPlane(Plane^ plane)
98 Vector3 min = getMin();
99 Vector3 max = getMax();
100 array<Vector3>^ points = gcnew array<Vector3>(8);
101 points[0] = Vector3(min.x, min.y, min.z);
102 points[1] = Vector3(max.x, min.y, min.z);
103 points[2] = Vector3(min.x, min.y, max.z);
104 points[3] = Vector3(max.x, min.y, max.z);
105 points[4] = Vector3(min.x, max.y, min.z);
106 points[5] = Vector3(max.x, max.y, min.z);
107 points[6] = Vector3(min.x, max.y, max.z);
108 points[7] = Vector3(max.x, max.y, max.z);
113 for (
int i = 0; i < 8; i++)
115 if (plane->distanceTo(points[i]) > 0)
121 return under && over;
124 void expand(
const Vector3 p)
126 Vector3 min = getMin();
127 Vector3 max = getMax();
129 if (p.x < min.x) min.x = p.x;
130 if (p.y < min.y) min.x = p.y;
131 if (p.z < min.z) min.x = p.z;
133 if (p.x > max.x) max.x = p.x;
134 if (p.y > max.y) max.x = p.y;
135 if (p.z > max.z) max.x = p.z;
140 void expand(Aabb^ aabb)
142 Vector3 min = getMin();
143 Vector3 max = getMax();
144 Vector3 amin = aabb->getMin();
145 Vector3 amax = aabb->getMax();
147 if (amin.x < min.x) min.x = amin.x;
148 if (amin.y < min.y) min.x = amin.y;
149 if (amin.z < min.z) min.x = amin.z;
151 if (amax.x > max.x) max.x = amax.x;
152 if (amax.y > max.y) max.x = amax.y;
153 if (amax.z > max.z) max.x = amax.z;
160 void construct(
const Vector3 min,
const Vector3 max)
162 hsize = (max + -min) * 0.5f;
163 center = min + hsize;
164 hsize = Vector3(fabs(hsize.x), fabs(hsize.y), fabs(hsize.z));