stuff
This commit is contained in:
@@ -30,31 +30,18 @@ public:
|
||||
return tr;
|
||||
}
|
||||
|
||||
BoundingBox GetAABB() {
|
||||
std::vector<glm::vec3> corners = {
|
||||
{0.5f,0.5f,0.5f},
|
||||
{0.5f,-0.5f,0.5f},
|
||||
{0.5f,-0.5f,-0.5f},
|
||||
{0.5f,0.5f,-0.5f},
|
||||
{-0.5f,0.5f,0.5f},
|
||||
{-0.5f,-0.5f,0.5f},
|
||||
{-0.5f,0.5f,-0.5f},
|
||||
{-0.5f,-0.5f,-0.5f},
|
||||
};
|
||||
BoundingBox GetAABB() const {
|
||||
// Each world axis reaches as far as the rotated box's axes add up to, no need to visit the corners
|
||||
const glm::mat3 rotation = glm::mat3_cast(orient);
|
||||
const glm::vec3 half = scale * 0.5f;
|
||||
const glm::vec3 extent =
|
||||
glm::abs(rotation[0]) * half.x +
|
||||
glm::abs(rotation[1]) * half.y +
|
||||
glm::abs(rotation[2]) * half.z;
|
||||
|
||||
glm::vec3 min(FLT_MAX);
|
||||
glm::vec3 max(-FLT_MAX);
|
||||
for (glm::vec3& corner : corners) {
|
||||
corner *= scale;
|
||||
corner = orient * corner;
|
||||
corner += pos;
|
||||
min = { glm::min(min.x, corner.x) ,glm::min(min.y, corner.y), glm::min(min.z, corner.z) };
|
||||
max = { glm::max(max.x, corner.x) ,glm::max(max.y, corner.y), glm::max(max.z, corner.z) };
|
||||
}
|
||||
BoundingBox tr;
|
||||
tr.min = min;
|
||||
tr.max = max;
|
||||
//std::cout << tr.min.x << ' ' << tr.min.y << ' ' << tr.min.z << ' ' << tr.max.x << ' ' << tr.max.y << ' ' << tr.max.z << '\n';
|
||||
tr.min = pos - extent;
|
||||
tr.max = pos + extent;
|
||||
return tr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user