2018-10-06 20:39:40 -07:00
|
|
|
#pragma once
|
2015-08-11 18:41:28 -07:00
|
|
|
|
2019-09-01 00:38:45 -07:00
|
|
|
#include "zeus/CAABox.hpp"
|
2016-03-04 15:03:26 -08:00
|
|
|
#include "zeus/CTransform.hpp"
|
|
|
|
#include "zeus/CVector3f.hpp"
|
2019-09-01 00:38:45 -07:00
|
|
|
|
2018-12-07 17:16:50 -08:00
|
|
|
namespace zeus {
|
|
|
|
class COBBox {
|
2015-08-11 18:41:28 -07:00
|
|
|
public:
|
2018-12-07 17:16:50 -08:00
|
|
|
CTransform transform;
|
|
|
|
CVector3f extents;
|
2015-08-11 18:41:28 -07:00
|
|
|
|
2019-02-23 23:15:32 -08:00
|
|
|
constexpr COBBox() = default;
|
2015-08-11 18:41:28 -07:00
|
|
|
|
2018-12-07 17:16:50 -08:00
|
|
|
COBBox(const CAABox& aabb) : extents(aabb.extents()) { transform.origin = aabb.center(); }
|
2015-08-11 18:41:28 -07:00
|
|
|
|
2019-02-23 23:15:32 -08:00
|
|
|
constexpr COBBox(const CTransform& xf, const CVector3f& extents) : transform(xf), extents(extents) {}
|
2016-04-26 03:36:44 -07:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] CAABox calculateAABox(const CTransform& worldXf = CTransform()) const;
|
2016-04-26 03:36:44 -07:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] static COBBox FromAABox(const CAABox& box, const CTransform& xf) {
|
|
|
|
const CVector3f center = box.center();
|
2019-03-07 20:15:58 -08:00
|
|
|
const CVector3f extents = box.max - center;
|
|
|
|
const CTransform newXf = xf * CTransform::Translate(center);
|
2018-12-07 17:16:50 -08:00
|
|
|
return COBBox(newXf, extents);
|
|
|
|
}
|
2016-12-22 12:35:29 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] bool OBBIntersectsBox(const COBBox& other) const;
|
2017-01-23 02:10:35 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] bool AABoxIntersectsBox(const CAABox& other) const {
|
|
|
|
return OBBIntersectsBox(FromAABox(other, CTransform()));
|
|
|
|
}
|
2015-08-11 18:41:28 -07:00
|
|
|
};
|
2018-12-07 21:23:50 -08:00
|
|
|
} // namespace zeus
|