|
|
@@ -15,6 +15,31 @@ Obb Obb::getTransformed(const Transform& transform) const
|
|
|
}
|
|
|
|
|
|
|
|
|
+//======================================================================================================================
|
|
|
+// getCompoundShape =
|
|
|
+//======================================================================================================================
|
|
|
+Obb Obb::getCompoundShape(const Obb& b) const
|
|
|
+{
|
|
|
+ Obb out;
|
|
|
+
|
|
|
+ boost::array<Vec3, 8> points0;
|
|
|
+ boost::array<Vec3, 8> points1;
|
|
|
+
|
|
|
+ getExtremePoints(points0);
|
|
|
+ b.getExtremePoints(points1);
|
|
|
+
|
|
|
+ boost::array<Vec3, 16> points;
|
|
|
+ for(uint i = 0; i < 8; i++)
|
|
|
+ {
|
|
|
+ points[i] = points0[i];
|
|
|
+ points[i + 8] = points1[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ out.set(points);
|
|
|
+ return out;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//======================================================================================================================
|
|
|
// testPlane =
|
|
|
//======================================================================================================================
|
|
|
@@ -41,3 +66,47 @@ float Obb::testPlane(const Plane& plane) const
|
|
|
return d - r;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+//======================================================================================================================
|
|
|
+// getExtremePoints =
|
|
|
+//======================================================================================================================
|
|
|
+void Obb::getExtremePoints(boost::array<Vec3, 8>& points) const
|
|
|
+{
|
|
|
+ // L: left, R: right, T: top, B: bottom, F: front, B: back
|
|
|
+ enum
|
|
|
+ {
|
|
|
+ RTF,
|
|
|
+ LTF,
|
|
|
+ LBF,
|
|
|
+ RBF,
|
|
|
+ RTB,
|
|
|
+ LTB,
|
|
|
+ LBB,
|
|
|
+ RBB
|
|
|
+ };
|
|
|
+
|
|
|
+ Vec3 er = rotation * extends; // extend rotated
|
|
|
+
|
|
|
+ points[RTF] = er;
|
|
|
+ points[LBB] = -er;
|
|
|
+
|
|
|
+ Vec3 xAxis = rotation.getColumn(0);
|
|
|
+ Vec3 yAxis = rotation.getColumn(1);
|
|
|
+ Vec3 zAxis = rotation.getColumn(2);
|
|
|
+
|
|
|
+ // Reflection: x1' = x1 - 2n|x1.n|
|
|
|
+
|
|
|
+ points[RBB] = er - 2.0 * er.dot(xAxis) * xAxis;
|
|
|
+ points[LTB] = er - 2.0 * er.dot(yAxis) * yAxis;
|
|
|
+ points[LBF] = er - 2.0 * er.dot(zAxis) * zAxis;
|
|
|
+
|
|
|
+ points[LTF] = points[LBB] - 2.0 * points[LBB].dot(-xAxis) * -xAxis;
|
|
|
+ points[RTB] = points[LTF] - 2.0 * points[LTF].dot(yAxis) * yAxis;
|
|
|
+ points[RBF] = points[LTF] - 2.0 * points[LTF].dot(zAxis) * zAxis;
|
|
|
+
|
|
|
+ BOOST_FOREACH(Vec3& point, points)
|
|
|
+ {
|
|
|
+ point += center;
|
|
|
+ }
|
|
|
+}
|