From 85f13a0d240114b9d858b7fe9ea53ecab3dcde68 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Thu, 8 Aug 2019 20:29:45 -0700 Subject: Add Basis constants and format Transform constants --- core/math/transform.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/math/transform.h') diff --git a/core/math/transform.h b/core/math/transform.h index 2f43f6b035..df0a036218 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -108,6 +108,7 @@ public: operator String() const; + Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t ox, real_t oy, real_t oz); Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3()); Transform() {} }; -- cgit v1.2.3 From 82b9557803f33521694587b6014645a05a814ecb Mon Sep 17 00:00:00 2001 From: IAmActuallyCthulhu Date: Sat, 10 Aug 2019 07:28:17 -0500 Subject: Remove redundant author doc comments --- core/math/transform.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'core/math/transform.h') diff --git a/core/math/transform.h b/core/math/transform.h index 2f43f6b035..8f8d20c067 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -35,10 +35,6 @@ #include "core/math/basis.h" #include "core/math/plane.h" -/** - @author Juan Linietsky -*/ - class Transform { public: Basis basis; -- cgit v1.2.3 From e7febd72d66ffe36c50d79684805142d8153f666 Mon Sep 17 00:00:00 2001 From: RaphaelHunter Date: Thu, 29 Aug 2019 14:17:08 +0800 Subject: a faster funtion to transform aabb --- core/math/transform.h | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'core/math/transform.h') diff --git a/core/math/transform.h b/core/math/transform.h index 4c8d915305..2448aecdc6 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -154,22 +154,29 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { } _FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const { - /* define vertices */ - Vector3 x = basis.get_axis(0) * p_aabb.size.x; - Vector3 y = basis.get_axis(1) * p_aabb.size.y; - Vector3 z = basis.get_axis(2) * p_aabb.size.z; - Vector3 pos = xform(p_aabb.position); - //could be even further optimized - AABB new_aabb; - new_aabb.position = pos; - new_aabb.expand_to(pos + x); - new_aabb.expand_to(pos + y); - new_aabb.expand_to(pos + z); - new_aabb.expand_to(pos + x + y); - new_aabb.expand_to(pos + x + z); - new_aabb.expand_to(pos + y + z); - new_aabb.expand_to(pos + x + y + z); - return new_aabb; + + /* http://dev.theomader.com/transform-bounding-boxes/ */ + Vector3 min = p_aabb.position; + Vector3 max = p_aabb.position + p_aabb.size; + Vector3 tmin, tmax; + for (int i = 0; i < 3; i++) { + tmin[i] = tmax[i] = origin[i]; + for (int j = 0; j < 3; j++) { + real_t e = basis[i][j] * min[j]; + real_t f = basis[i][j] * max[j]; + if (e < f) { + tmin[i] += e; + tmax[i] += f; + } else { + tmin[i] += f; + tmax[i] += e; + } + } + } + AABB r_aabb; + r_aabb.position = tmin; + r_aabb.size = tmax - tmin; + return r_aabb; } _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { -- cgit v1.2.3 From 07cff56f485298291132656f45b6679a314e04c1 Mon Sep 17 00:00:00 2001 From: "Andrii Doroshenko (Xrayez)" Date: Thu, 29 Aug 2019 13:20:10 +0300 Subject: Add transform methods for PoolVector*Array Similarly to `Vector2` and `Rect2` transforms in 2D and Vector3, Plane, and AABB in 3D. PoolVector2Array and PoolVector3Array were the only missing Variant types in both Transform2D and Transform respectively. --- core/math/transform.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'core/math/transform.h') diff --git a/core/math/transform.h b/core/math/transform.h index 4c8d915305..1fdc6398a1 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -34,6 +34,7 @@ #include "core/math/aabb.h" #include "core/math/basis.h" #include "core/math/plane.h" +#include "core/pool_vector.h" class Transform { public: @@ -82,6 +83,9 @@ public: _FORCE_INLINE_ AABB xform(const AABB &p_aabb) const; _FORCE_INLINE_ AABB xform_inv(const AABB &p_aabb) const; + _FORCE_INLINE_ PoolVector xform(const PoolVector &p_array) const; + _FORCE_INLINE_ PoolVector xform_inv(const PoolVector &p_array) const; + void operator*=(const Transform &p_transform); Transform operator*(const Transform &p_transform) const; @@ -198,4 +202,32 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { return ret; } +PoolVector Transform::xform(const PoolVector &p_array) const { + + PoolVector array; + array.resize(p_array.size()); + + PoolVector::Read r = p_array.read(); + PoolVector::Write w = array.write(); + + for (int i = 0; i < p_array.size(); ++i) { + w[i] = xform(r[i]); + } + return array; +} + +PoolVector Transform::xform_inv(const PoolVector &p_array) const { + + PoolVector array; + array.resize(p_array.size()); + + PoolVector::Read r = p_array.read(); + PoolVector::Write w = array.write(); + + for (int i = 0; i < p_array.size(); ++i) { + w[i] = xform_inv(r[i]); + } + return array; +} + #endif // TRANSFORM_H -- cgit v1.2.3