zeus/include/zeus/COBBox.hpp

48 lines
1.2 KiB
C++
Raw Normal View History

2018-10-06 20:39:40 -07:00
#pragma once
2016-03-04 15:03:26 -08:00
#include "zeus/CTransform.hpp"
#include "zeus/CVector3f.hpp"
#include "zeus/CAABox.hpp"
#include "zeus/CMRay.hpp"
2018-12-07 17:16:50 -08:00
namespace zeus {
class COBBox {
public:
2016-04-26 03:36:44 -07:00
#if ZE_ATHENA_TYPES
2018-12-07 17:16:50 -08:00
void readBig(athena::io::IStreamReader& in) {
transform.read34RowMajor(in);
extents.readBig(in);
}
static COBBox ReadBig(athena::io::IStreamReader& in) {
COBBox out;
out.readBig(in);
return out;
}
2016-04-26 03:36:44 -07:00
#endif
2018-12-07 17:16:50 -08:00
CTransform transform;
CVector3f extents;
2018-12-07 17:16:50 -08:00
COBBox() = default;
2018-12-07 17:16:50 -08:00
COBBox(const CAABox& aabb) : extents(aabb.extents()) { transform.origin = aabb.center(); }
2018-12-07 17:16:50 -08:00
COBBox(const CTransform& xf, const CVector3f& extents) : transform(xf), extents(extents) {}
2016-04-26 03:36:44 -07:00
2018-12-07 17:16:50 -08:00
CAABox calculateAABox(const CTransform& worldXf = CTransform()) const;
2016-04-26 03:36:44 -07:00
2018-12-07 17:16:50 -08:00
static COBBox FromAABox(const CAABox& box, const CTransform& xf) {
const CVector3f extents = box.max - box.center();
const CTransform newXf = CTransform::Translate(box.center()) * xf;
return COBBox(newXf, extents);
}
2016-12-22 12:35:29 -08:00
2018-12-07 17:16:50 -08:00
bool OBBIntersectsBox(const COBBox& other) const;
2017-01-23 02:10:35 -08:00
2018-12-07 21:23:50 -08:00
bool AABoxIntersectsBox(const CAABox& other) { return OBBIntersectsBox(FromAABox(other, CTransform::Identity())); }
};
2018-12-07 21:23:50 -08:00
} // namespace zeus