bbox fixes

This commit is contained in:
h4570
2022-07-23 18:34:35 +02:00
parent 1ae7939cc3
commit 23e98afe91
5 changed files with 36 additions and 2 deletions
+14
View File
@@ -25,8 +25,22 @@ BBox::BBox(Vec4* t_vertices, u32* faces, u32 count)
setData();
}
BBox::BBox(const BBox& t_bbox) : CoreBBox(t_bbox) { setData(); }
BBox::BBox(const BBox& t_bbox, const M4x4& t_matrix) {
for (u32 i = 0; i < 8; i++) {
_vertices[i] = t_matrix * _vertices[i];
}
setData();
}
BBox::BBox(Vec4* t_vertices) : CoreBBox(t_vertices) { setData(); }
BBox BBox::getTransformed(const M4x4& t_matrix) {
return BBox(*this, t_matrix);
}
void BBox::setData() {
// This might be shortened with Vec4 operator overloading, but current
// implementation is more human readable.
+13 -2
View File
@@ -14,6 +14,12 @@
namespace Tyra {
CoreBBox::CoreBBox() {
for (u32 i = 0; i < 8; i++) {
_vertices[i] = Vec4(0.0F, 0.0F, 0.0F, 1.0F);
}
}
CoreBBox::CoreBBox(CoreBBox** t_bboxes, const u32& count) {
float lowX = t_bboxes[0]->_vertices[0].x;
float lowY = t_bboxes[0]->_vertices[0].y;
@@ -131,6 +137,11 @@ CoreBBox::CoreBBox(Vec4* t_vertices, u32 count) {
_vertices[7].set(hiX, hiY, hiZ);
}
CoreBBox::CoreBBox(const CoreBBox& t_bbox) {
for (auto i = 0; i < 8; i++)
Vec4::copy(&_vertices[i], t_bbox._vertices[i].xyzw);
}
CoreBBox::CoreBBox(Vec4* t_vertices) {
for (auto i = 0; i < 8; i++) Vec4::copy(&_vertices[i], t_vertices[i].xyzw);
}
@@ -167,8 +178,8 @@ std::string CoreBBox::getPrint(const char* name) const {
}
CoreBBoxFrustum CoreBBox::isInFrustum(const Plane* frustumPlanes,
const M4x4& model,
const float* margins) const {
const M4x4& model,
const float* margins) const {
CoreBBoxFrustum result = IN_FRUSTUM;
Vec4 boxCalcTemp;
u8 boxIn = 0, boxOut = 0;