summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2020-10-13 15:59:37 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-10-14 15:24:30 +0200
commitb8c64184c628dba6b54b4beb5a38e292a182bd6f (patch)
tree7ffaba5d7fecfb9d16e0c47a18ffdd98117a2eea /core/math
parentbc91e088e4503bbf1c5800282f2974011a4cc8e8 (diff)
Refactored binding system for core types
Moved to a system using variadic templates, shared with CallableBind. New code is cleaner, faster and allows for much better optimization of core type functions from GDScript and GDNative. Added Variant::InternalMethod function for direct call access.
Diffstat (limited to 'core/math')
-rw-r--r--core/math/aabb.cpp16
-rw-r--r--core/math/aabb.h4
-rw-r--r--core/math/plane.cpp26
-rw-r--r--core/math/plane.h7
-rw-r--r--core/math/rect2.h8
5 files changed, 61 insertions, 0 deletions
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index f5c667dab0..e868ebc7c8 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -31,6 +31,7 @@
#include "aabb.h"
#include "core/print_string.h"
+#include "core/variant.h"
real_t AABB::get_area() const {
return size.x * size.y * size.z;
@@ -375,6 +376,21 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
}
}
+Variant AABB::intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const {
+ Vector3 inters;
+ if (intersects_segment(p_from, p_to, &inters)) {
+ return inters;
+ }
+ return Variant();
+}
+Variant AABB::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const {
+ Vector3 inters;
+ if (intersects_ray(p_from, p_dir, &inters)) {
+ return inters;
+ }
+ return Variant();
+}
+
AABB::operator String() const {
return String() + position + " - " + size;
}
diff --git a/core/math/aabb.h b/core/math/aabb.h
index bd1f3a1a36..8c08754e1c 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -39,6 +39,7 @@
* AABB / AABB (Axis Aligned Bounding Box)
* This is implemented by a point (position) and the box size
*/
+class Variant;
class AABB {
public:
@@ -103,6 +104,9 @@ public:
return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs());
}
+ 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;
+
operator String() const;
_FORCE_INLINE_ AABB() {}
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index 4200484c59..ae2021d2f6 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -31,6 +31,7 @@
#include "plane.h"
#include "core/math/math_funcs.h"
+#include "core/variant.h"
void Plane::set_normal(const Vector3 &p_normal) {
normal = p_normal;
@@ -138,6 +139,31 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec
return true;
}
+Variant Plane::intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const {
+ Vector3 inters;
+ if (intersect_3(p_plane1, p_plane2, &inters)) {
+ return inters;
+ } else {
+ return Variant();
+ }
+}
+Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const {
+ Vector3 inters;
+ if (intersects_ray(p_from, p_dir, &inters)) {
+ return inters;
+ } else {
+ return Variant();
+ }
+}
+Variant Plane::intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const {
+ Vector3 inters;
+ if (intersects_segment(p_begin, p_end, &inters)) {
+ return inters;
+ } else {
+ return Variant();
+ }
+}
+
/* misc */
bool Plane::is_equal_approx_any_side(const Plane &p_plane) const {
diff --git a/core/math/plane.h b/core/math/plane.h
index 70a6111edd..1386b0a2cb 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -33,6 +33,8 @@
#include "core/math/vector3.h"
+class Variant;
+
class Plane {
public:
Vector3 normal;
@@ -59,6 +61,11 @@ public:
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const;
bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const;
+ // For Variant bindings.
+ Variant intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const;
+ Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;
+ Variant intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const;
+
_FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const {
return p_point - normal * distance_to(p_point);
}
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 14393325ec..7660db71eb 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -197,6 +197,10 @@ struct Rect2 {
return g;
}
+ inline Rect2 grow_margin_bind(uint32_t p_margin, real_t p_amount) const {
+ return grow_margin(Margin(p_margin), p_amount);
+ }
+
inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const {
Rect2 g = *this;
g.position.x -= p_left;
@@ -363,6 +367,10 @@ struct Rect2i {
return g;
}
+ inline Rect2i grow_margin_bind(uint32_t p_margin, int p_amount) const {
+ return grow_margin(Margin(p_margin), p_amount);
+ }
+
inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const {
Rect2i g = *this;
g.position.x -= p_left;