Update core data structures to match the engine
This commit is contained in:
@@ -31,29 +31,29 @@
|
||||
#ifndef GODOT_AABB_HPP
|
||||
#define GODOT_AABB_HPP
|
||||
|
||||
#include <godot_cpp/core/error_macros.hpp>
|
||||
#include <godot_cpp/core/math.hpp>
|
||||
#include <godot_cpp/variant/plane.hpp>
|
||||
#include <godot_cpp/variant/vector3.hpp>
|
||||
|
||||
/**
|
||||
* AABB / AABB (Axis Aligned Bounding Box)
|
||||
* This is implemented by a point (position) and the box size
|
||||
* AABB (Axis Aligned Bounding Box)
|
||||
* This is implemented by a point (position) and the box size.
|
||||
*/
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Variant;
|
||||
|
||||
struct _NO_DISCARD_ AABB {
|
||||
Vector3 position;
|
||||
Vector3 size;
|
||||
|
||||
real_t get_area() const; /// get area
|
||||
inline bool has_no_area() const {
|
||||
return (size.x <= 0 || size.y <= 0 || size.z <= 0);
|
||||
real_t get_volume() const;
|
||||
_FORCE_INLINE_ bool has_volume() const {
|
||||
return size.x > 0.0f && size.y > 0.0f && size.z > 0.0f;
|
||||
}
|
||||
|
||||
inline bool has_no_surface() const {
|
||||
return (size.x <= 0 && size.y <= 0 && size.z <= 0);
|
||||
_FORCE_INLINE_ bool has_surface() const {
|
||||
return size.x > 0.0f || size.y > 0.0f || size.z > 0.0f;
|
||||
}
|
||||
|
||||
const Vector3 &get_position() const { return position; }
|
||||
@@ -65,60 +65,67 @@ struct _NO_DISCARD_ AABB {
|
||||
bool operator!=(const AABB &p_rval) const;
|
||||
|
||||
bool is_equal_approx(const AABB &p_aabb) const;
|
||||
inline bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
|
||||
inline bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
|
||||
inline bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
|
||||
_FORCE_INLINE_ bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
|
||||
_FORCE_INLINE_ bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
|
||||
_FORCE_INLINE_ bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
|
||||
|
||||
AABB merge(const AABB &p_with) const;
|
||||
void merge_with(const AABB &p_aabb); /// merge with another AABB
|
||||
AABB intersection(const AABB &p_aabb) const; /// get box where two intersect, empty if no intersection occurs
|
||||
void merge_with(const AABB &p_aabb); ///merge with another AABB
|
||||
AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs
|
||||
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
|
||||
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
|
||||
inline bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const;
|
||||
_FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const;
|
||||
|
||||
inline bool intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const;
|
||||
inline bool inside_convex_shape(const Plane *p_planes, int p_plane_count) const;
|
||||
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const;
|
||||
_FORCE_INLINE_ bool inside_convex_shape(const Plane *p_planes, int p_plane_count) const;
|
||||
bool intersects_plane(const Plane &p_plane) const;
|
||||
|
||||
inline bool has_point(const Vector3 &p_point) const;
|
||||
inline Vector3 get_support(const Vector3 &p_normal) const;
|
||||
_FORCE_INLINE_ bool has_point(const Vector3 &p_point) const;
|
||||
_FORCE_INLINE_ Vector3 get_support(const Vector3 &p_normal) const;
|
||||
|
||||
Vector3 get_longest_axis() const;
|
||||
int get_longest_axis_index() const;
|
||||
inline real_t get_longest_axis_size() const;
|
||||
_FORCE_INLINE_ real_t get_longest_axis_size() const;
|
||||
|
||||
Vector3 get_shortest_axis() const;
|
||||
int get_shortest_axis_index() const;
|
||||
inline real_t get_shortest_axis_size() const;
|
||||
_FORCE_INLINE_ real_t get_shortest_axis_size() const;
|
||||
|
||||
AABB grow(real_t p_by) const;
|
||||
inline void grow_by(real_t p_amount);
|
||||
_FORCE_INLINE_ void grow_by(real_t p_amount);
|
||||
|
||||
void get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const;
|
||||
inline Vector3 get_endpoint(int p_point) const;
|
||||
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
|
||||
|
||||
AABB expand(const Vector3 &p_vector) const;
|
||||
inline void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
|
||||
inline void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */
|
||||
_FORCE_INLINE_ void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
|
||||
_FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */
|
||||
|
||||
inline AABB abs() const {
|
||||
return AABB(Vector3(position.x + Math::min(size.x, (real_t)0), position.y + Math::min(size.y, (real_t)0), position.z + Math::min(size.z, (real_t)0)), size.abs());
|
||||
_FORCE_INLINE_ AABB abs() const {
|
||||
return AABB(Vector3(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0), position.z + MIN(size.z, (real_t)0)), size.abs());
|
||||
}
|
||||
|
||||
inline void quantize(real_t p_unit);
|
||||
inline AABB quantized(real_t p_unit) const;
|
||||
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;
|
||||
|
||||
inline void set_end(const Vector3 &p_end) {
|
||||
_FORCE_INLINE_ void quantize(real_t p_unit);
|
||||
_FORCE_INLINE_ AABB quantized(real_t p_unit) const;
|
||||
|
||||
_FORCE_INLINE_ void set_end(const Vector3 &p_end) {
|
||||
size = p_end - position;
|
||||
}
|
||||
|
||||
inline Vector3 get_end() const {
|
||||
_FORCE_INLINE_ Vector3 get_end() const {
|
||||
return position + size;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Vector3 get_center() const {
|
||||
return position + (size * 0.5f);
|
||||
}
|
||||
|
||||
operator String() const;
|
||||
|
||||
inline AABB() {}
|
||||
_FORCE_INLINE_ AABB() {}
|
||||
inline AABB(const Vector3 &p_pos, const Vector3 &p_size) :
|
||||
position(p_pos),
|
||||
size(p_size) {
|
||||
@@ -126,6 +133,11 @@ struct _NO_DISCARD_ AABB {
|
||||
};
|
||||
|
||||
inline bool AABB::intersects(const AABB &p_aabb) const {
|
||||
#ifdef MATH_CHECKS
|
||||
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
|
||||
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
|
||||
}
|
||||
#endif
|
||||
if (position.x >= (p_aabb.position.x + p_aabb.size.x)) {
|
||||
return false;
|
||||
}
|
||||
@@ -149,6 +161,11 @@ inline bool AABB::intersects(const AABB &p_aabb) const {
|
||||
}
|
||||
|
||||
inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
|
||||
#ifdef MATH_CHECKS
|
||||
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
|
||||
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
|
||||
}
|
||||
#endif
|
||||
if (position.x > (p_aabb.position.x + p_aabb.size.x)) {
|
||||
return false;
|
||||
}
|
||||
@@ -172,6 +189,11 @@ inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
|
||||
}
|
||||
|
||||
inline bool AABB::encloses(const AABB &p_aabb) const {
|
||||
#ifdef MATH_CHECKS
|
||||
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
|
||||
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
|
||||
}
|
||||
#endif
|
||||
Vector3 src_min = position;
|
||||
Vector3 src_max = position + size;
|
||||
Vector3 dst_min = p_aabb.position;
|
||||
@@ -187,14 +209,14 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
|
||||
}
|
||||
|
||||
Vector3 AABB::get_support(const Vector3 &p_normal) const {
|
||||
Vector3 half_extents = size * 0.5;
|
||||
Vector3 half_extents = size * 0.5f;
|
||||
Vector3 ofs = position + half_extents;
|
||||
|
||||
return Vector3(
|
||||
(p_normal.x > 0) ? half_extents.x : -half_extents.x,
|
||||
(p_normal.y > 0) ? half_extents.y : -half_extents.y,
|
||||
(p_normal.z > 0) ? half_extents.z : -half_extents.z) +
|
||||
ofs;
|
||||
ofs;
|
||||
}
|
||||
|
||||
Vector3 AABB::get_endpoint(int p_point) const {
|
||||
@@ -221,7 +243,7 @@ Vector3 AABB::get_endpoint(int p_point) const {
|
||||
}
|
||||
|
||||
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const {
|
||||
Vector3 half_extents = size * 0.5;
|
||||
Vector3 half_extents = size * 0.5f;
|
||||
Vector3 ofs = position + half_extents;
|
||||
|
||||
for (int i = 0; i < p_plane_count; i++) {
|
||||
@@ -263,7 +285,7 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
|
||||
}
|
||||
|
||||
bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
|
||||
Vector3 half_extents = size * 0.5;
|
||||
Vector3 half_extents = size * 0.5f;
|
||||
Vector3 ofs = position + half_extents;
|
||||
|
||||
for (int i = 0; i < p_plane_count; i++) {
|
||||
@@ -282,6 +304,11 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
|
||||
}
|
||||
|
||||
bool AABB::has_point(const Vector3 &p_point) const {
|
||||
#ifdef MATH_CHECKS
|
||||
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
|
||||
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
|
||||
}
|
||||
#endif
|
||||
if (p_point.x < position.x) {
|
||||
return false;
|
||||
}
|
||||
@@ -305,6 +332,11 @@ bool AABB::has_point(const Vector3 &p_point) const {
|
||||
}
|
||||
|
||||
inline void AABB::expand_to(const Vector3 &p_vector) {
|
||||
#ifdef MATH_CHECKS
|
||||
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
|
||||
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
|
||||
}
|
||||
#endif
|
||||
Vector3 begin = position;
|
||||
Vector3 end = position + size;
|
||||
|
||||
@@ -333,7 +365,7 @@ inline void AABB::expand_to(const Vector3 &p_vector) {
|
||||
}
|
||||
|
||||
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
|
||||
Vector3 half_extents(size.x * (real_t)0.5, size.y * (real_t)0.5, size.z * (real_t)0.5);
|
||||
Vector3 half_extents(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
|
||||
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
|
||||
|
||||
real_t length = p_plane.normal.abs().dot(half_extents);
|
||||
@@ -371,9 +403,14 @@ inline real_t AABB::get_shortest_axis_size() const {
|
||||
}
|
||||
|
||||
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const {
|
||||
real_t divx = (real_t)1.0 / p_dir.x;
|
||||
real_t divy = (real_t)1.0 / p_dir.y;
|
||||
real_t divz = (real_t)1.0 / p_dir.z;
|
||||
#ifdef MATH_CHECKS
|
||||
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
|
||||
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
|
||||
}
|
||||
#endif
|
||||
real_t divx = 1.0f / p_dir.x;
|
||||
real_t divy = 1.0f / p_dir.y;
|
||||
real_t divz = 1.0f / p_dir.z;
|
||||
|
||||
Vector3 upbound = position + size;
|
||||
real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
|
||||
@@ -423,9 +460,9 @@ void AABB::grow_by(real_t p_amount) {
|
||||
position.x -= p_amount;
|
||||
position.y -= p_amount;
|
||||
position.z -= p_amount;
|
||||
size.x += (real_t)2.0 * p_amount;
|
||||
size.y += (real_t)2.0 * p_amount;
|
||||
size.z += (real_t)2.0 * p_amount;
|
||||
size.x += 2.0f * p_amount;
|
||||
size.y += 2.0f * p_amount;
|
||||
size.z += 2.0f * p_amount;
|
||||
}
|
||||
|
||||
void AABB::quantize(real_t p_unit) {
|
||||
|
||||
Reference in New Issue
Block a user