diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-12-24 14:01:19 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-24 14:01:19 -0300 |
commit | 545c89461464ee14b2b806dd2dd2c0eef110e181 (patch) | |
tree | 346e4cf91f69044485311a2037105690aa8c48aa /core/math/aabb.h | |
parent | ecda989c85e953ced7c19f161b38c6b054d3acec (diff) | |
parent | 1bebb2ba057a8baa2f560362142bae5123b962af (diff) |
Merge pull request #44656 from reduz/cull-fixes-and-optimizations
Cull fixes and optimizations
Diffstat (limited to 'core/math/aabb.h')
-rw-r--r-- | core/math/aabb.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/math/aabb.h b/core/math/aabb.h index 474304eae2..24908ae59d 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -107,6 +107,9 @@ public: Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const; + _FORCE_INLINE_ void quantize(float p_unit); + _FORCE_INLINE_ AABB quantized(float p_unit) const; + _FORCE_INLINE_ void set_end(const Vector3 &p_end) { size = p_end - position; } @@ -427,4 +430,28 @@ void AABB::grow_by(real_t p_amount) { size.z += 2.0 * p_amount; } +void AABB::quantize(float p_unit) { + size += position; + + position.x -= Math::fposmodp(position.x, p_unit); + position.y -= Math::fposmodp(position.y, p_unit); + position.z -= Math::fposmodp(position.z, p_unit); + + size.x -= Math::fposmodp(size.x, p_unit); + size.y -= Math::fposmodp(size.y, p_unit); + size.z -= Math::fposmodp(size.z, p_unit); + + size.x += p_unit; + size.y += p_unit; + size.z += p_unit; + + size -= position; +} + +AABB AABB::quantized(float p_unit) const { + AABB ret = *this; + ret.quantize(p_unit); + return ret; +} + #endif // AABB_H |