mirror of
https://github.com/AxioDL/zeus.git
synced 2025-07-06 21:26:00 +00:00
Given this aims to be a general purpose math library for use in various other libraries applications for axiodl, we can annotate functions that return by value or reference with [[nodiscard]] where it's very obvious that not making use of the return value is a bug. This allows the compiler to diagnose and emit warnings for these API misuses at compile-time, preventing silent bugs from occurring. Any cases where not using the return value is desirable may still be casted to void in order to silence warnings.
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "zeus/CAABox.hpp"
|
|
#include "zeus/CTransform.hpp"
|
|
#include "zeus/CVector3f.hpp"
|
|
|
|
#if ZE_ATHENA_TYPES
|
|
#include <athena/IStreamReader.hpp>
|
|
#endif
|
|
|
|
namespace zeus {
|
|
class COBBox {
|
|
public:
|
|
#if ZE_ATHENA_TYPES
|
|
|
|
void readBig(athena::io::IStreamReader& in) {
|
|
transform.read34RowMajor(in);
|
|
extents.readBig(in);
|
|
}
|
|
|
|
[[nodiscard]] static COBBox ReadBig(athena::io::IStreamReader& in) {
|
|
COBBox out;
|
|
out.readBig(in);
|
|
return out;
|
|
}
|
|
|
|
#endif
|
|
|
|
CTransform transform;
|
|
CVector3f extents;
|
|
|
|
constexpr COBBox() = default;
|
|
|
|
COBBox(const CAABox& aabb) : extents(aabb.extents()) { transform.origin = aabb.center(); }
|
|
|
|
constexpr COBBox(const CTransform& xf, const CVector3f& extents) : transform(xf), extents(extents) {}
|
|
|
|
[[nodiscard]] CAABox calculateAABox(const CTransform& worldXf = CTransform()) const;
|
|
|
|
[[nodiscard]] static COBBox FromAABox(const CAABox& box, const CTransform& xf) {
|
|
const CVector3f center = box.center();
|
|
const CVector3f extents = box.max - center;
|
|
const CTransform newXf = xf * CTransform::Translate(center);
|
|
return COBBox(newXf, extents);
|
|
}
|
|
|
|
[[nodiscard]] bool OBBIntersectsBox(const COBBox& other) const;
|
|
|
|
[[nodiscard]] bool AABoxIntersectsBox(const CAABox& other) const {
|
|
return OBBIntersectsBox(FromAABox(other, CTransform()));
|
|
}
|
|
};
|
|
} // namespace zeus
|