Update J3ML && OBB
This commit is contained in:
@@ -49,7 +49,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.25.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.26.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
@@ -59,7 +59,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.zip
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Release-4.zip
|
||||
)
|
||||
#Broken
|
||||
#CPMAddPackage(
|
||||
|
@@ -10,4 +10,5 @@ using J3ML::Geometry::Sphere;
|
||||
namespace Collision {
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray& vA);
|
||||
Sphere genMinimallyEnclosingSphere(const VertexArray& vA);
|
||||
OBB genMinimallyEnclosingOBB(const VertexArray& vA, const Vector3& rotation);
|
||||
}
|
||||
|
@@ -29,9 +29,26 @@ AABB Collision::genMinimallyEnclosingAABB(const VertexArray& vA) {
|
||||
}
|
||||
|
||||
Sphere Collision::genMinimallyEnclosingSphere(const VertexArray& vA) {
|
||||
AABB aabb = genMinimallyEnclosingAABB(vA);
|
||||
Sphere result;
|
||||
result.Position = {0, 0, 0};
|
||||
result.Radius = Vector3::Distance(result.Position, aabb.maxPoint);
|
||||
return result;
|
||||
return genMinimallyEnclosingAABB(vA).MinimalEnclosingSphere();
|
||||
}
|
||||
|
||||
OBB Collision::genMinimallyEnclosingOBB(const VertexArray& vA, const Vector3& rotation) {
|
||||
Vector3 centroid(0, 0, 0);
|
||||
Vector3 radii(0, 0, 0);
|
||||
Matrix3x3 rotationMatrix = Matrix3x3::FromQuat(Quaternion((EulerAngle) rotation));
|
||||
Vector3 axis0 = Vector3(rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]);
|
||||
Vector3 axis1 = Vector3(rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]);
|
||||
Vector3 axis2 = Vector3(rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]);
|
||||
|
||||
for (const auto& vertex : vA.vertices)
|
||||
centroid += vertex;
|
||||
centroid /= vA.vertices.size();
|
||||
|
||||
for (const auto& vertex : vA.vertices) {
|
||||
Vector3 diff = vertex - centroid;
|
||||
radii.x = std::max(radii.x, std::abs(diff.x));
|
||||
radii.y = std::max(radii.y, std::abs(diff.y));
|
||||
radii.z = std::max(radii.z, std::abs(diff.z));
|
||||
}
|
||||
return {centroid, radii, axis0, axis1, axis2};
|
||||
}
|
Reference in New Issue
Block a user