Skip to content

Commit 6637edb

Browse files
committed
Synchronize most shared variant code with Godot 4.4
1 parent 48baa0c commit 6637edb

35 files changed

+4816
-888
lines changed

include/godot_cpp/core/math.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,26 @@ inline float bezier_interpolate(float p_start, float p_control_1, float p_contro
538538
return p_start * omt3 + p_control_1 * omt2 * p_t * 3.0f + p_control_2 * omt * t2 * 3.0f + p_end * t3;
539539
}
540540

541+
inline double bezier_derivative(double p_start, double p_control_1, double p_control_2, double p_end, double p_t) {
542+
/* Formula from Wikipedia article on Bezier curves. */
543+
double omt = (1.0 - p_t);
544+
double omt2 = omt * omt;
545+
double t2 = p_t * p_t;
546+
547+
double d = (p_control_1 - p_start) * 3.0 * omt2 + (p_control_2 - p_control_1) * 6.0 * omt * p_t + (p_end - p_control_2) * 3.0 * t2;
548+
return d;
549+
}
550+
551+
inline float bezier_derivative(float p_start, float p_control_1, float p_control_2, float p_end, float p_t) {
552+
/* Formula from Wikipedia article on Bezier curves. */
553+
float omt = (1.0f - p_t);
554+
float omt2 = omt * omt;
555+
float t2 = p_t * p_t;
556+
557+
float d = (p_control_1 - p_start) * 3.0f * omt2 + (p_control_2 - p_control_1) * 6.0f * omt * p_t + (p_end - p_control_2) * 3.0f * t2;
558+
return d;
559+
}
560+
541561
template <typename T>
542562
inline T clamp(T x, T minv, T maxv) {
543563
if (x < minv) {

include/godot_cpp/variant/aabb.hpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,21 @@ struct [[nodiscard]] AABB {
7373
AABB merge(const AABB &p_with) const;
7474
void merge_with(const AABB &p_aabb); ///merge with another AABB
7575
AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs
76-
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
77-
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
78-
_FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const;
76+
_FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t p_t0, real_t p_t1) const;
77+
78+
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_intersection_point = nullptr, Vector3 *r_normal = nullptr) const;
79+
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir) const {
80+
bool inside;
81+
return find_intersects_ray(p_from, p_dir, inside);
82+
}
83+
bool find_intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, bool &r_inside, Vector3 *r_intersection_point = nullptr, Vector3 *r_normal = nullptr) const;
7984

8085
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const;
8186
_FORCE_INLINE_ bool inside_convex_shape(const Plane *p_planes, int p_plane_count) const;
8287
bool intersects_plane(const Plane &p_plane) const;
8388

8489
_FORCE_INLINE_ bool has_point(const Vector3 &p_point) const;
85-
_FORCE_INLINE_ Vector3 get_support(const Vector3 &p_normal) const;
90+
_FORCE_INLINE_ Vector3 get_support(const Vector3 &p_direction) const;
8691

8792
Vector3 get_longest_axis() const;
8893
int get_longest_axis_index() const;
@@ -209,15 +214,18 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
209214
(src_max.z >= dst_max.z));
210215
}
211216

212-
Vector3 AABB::get_support(const Vector3 &p_normal) const {
213-
Vector3 half_extents = size * 0.5f;
214-
Vector3 ofs = position + half_extents;
215-
216-
return Vector3(
217-
(p_normal.x > 0) ? half_extents.x : -half_extents.x,
218-
(p_normal.y > 0) ? half_extents.y : -half_extents.y,
219-
(p_normal.z > 0) ? half_extents.z : -half_extents.z) +
220-
ofs;
217+
Vector3 AABB::get_support(const Vector3 &p_direction) const {
218+
Vector3 support = position;
219+
if (p_direction.x > 0.0f) {
220+
support.x += size.x;
221+
}
222+
if (p_direction.y > 0.0f) {
223+
support.y += size.y;
224+
}
225+
if (p_direction.z > 0.0f) {
226+
support.z += size.z;
227+
}
228+
return support;
221229
}
222230

223231
Vector3 AABB::get_endpoint(int p_point) const {
@@ -403,7 +411,7 @@ inline real_t AABB::get_shortest_axis_size() const {
403411
return max_size;
404412
}
405413

406-
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const {
414+
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t p_t0, real_t p_t1) const {
407415
#ifdef MATH_CHECKS
408416
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
409417
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
@@ -454,7 +462,7 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
454462
if (tzmax < tmax) {
455463
tmax = tzmax;
456464
}
457-
return ((tmin < t1) && (tmax > t0));
465+
return ((tmin < p_t1) && (tmax > p_t0));
458466
}
459467

460468
void AABB::grow_by(real_t p_amount) {

include/godot_cpp/variant/basis.hpp

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ struct [[nodiscard]] Basis {
4444
Vector3(0, 0, 1)
4545
};
4646

47-
_FORCE_INLINE_ const Vector3 &operator[](int axis) const {
48-
return rows[axis];
47+
_FORCE_INLINE_ const Vector3 &operator[](int p_row) const {
48+
return rows[p_row];
4949
}
50-
_FORCE_INLINE_ Vector3 &operator[](int axis) {
51-
return rows[axis];
50+
_FORCE_INLINE_ Vector3 &operator[](int p_row) {
51+
return rows[p_row];
5252
}
5353

5454
void invert();
@@ -59,21 +59,19 @@ struct [[nodiscard]] Basis {
5959

6060
_FORCE_INLINE_ real_t determinant() const;
6161

62-
void from_z(const Vector3 &p_z);
63-
6462
void rotate(const Vector3 &p_axis, real_t p_angle);
6563
Basis rotated(const Vector3 &p_axis, real_t p_angle) const;
6664

6765
void rotate_local(const Vector3 &p_axis, real_t p_angle);
6866
Basis rotated_local(const Vector3 &p_axis, real_t p_angle) const;
6967

70-
void rotate(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ);
71-
Basis rotated(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ) const;
68+
void rotate(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ);
69+
Basis rotated(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) const;
7270

7371
void rotate(const Quaternion &p_quaternion);
7472
Basis rotated(const Quaternion &p_quaternion) const;
7573

76-
Vector3 get_euler_normalized(EulerOrder p_order = EULER_ORDER_YXZ) const;
74+
Vector3 get_euler_normalized(EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) const;
7775
void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const;
7876
void get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) const;
7977
Quaternion get_rotation_quaternion() const;
@@ -82,9 +80,9 @@ struct [[nodiscard]] Basis {
8280

8381
Vector3 rotref_posscale_decomposition(Basis &rotref) const;
8482

85-
Vector3 get_euler(EulerOrder p_order = EULER_ORDER_YXZ) const;
86-
void set_euler(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ);
87-
static Basis from_euler(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ) {
83+
Vector3 get_euler(EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) const;
84+
void set_euler(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ);
85+
static Basis from_euler(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) {
8886
Basis b;
8987
b.set_euler(p_euler, p_order);
9088
return b;
@@ -104,27 +102,25 @@ struct [[nodiscard]] Basis {
104102

105103
void scale_orthogonal(const Vector3 &p_scale);
106104
Basis scaled_orthogonal(const Vector3 &p_scale) const;
107-
108-
void make_scale_uniform();
109-
float get_uniform_scale() const;
105+
real_t get_uniform_scale() const;
110106

111107
Vector3 get_scale() const;
112108
Vector3 get_scale_abs() const;
113-
Vector3 get_scale_local() const;
109+
Vector3 get_scale_global() const;
114110

115111
void set_axis_angle_scale(const Vector3 &p_axis, real_t p_angle, const Vector3 &p_scale);
116-
void set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale, EulerOrder p_order = EULER_ORDER_YXZ);
112+
void set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ);
117113
void set_quaternion_scale(const Quaternion &p_quaternion, const Vector3 &p_scale);
118114

119115
// transposed dot products
120-
_FORCE_INLINE_ real_t tdotx(const Vector3 &v) const {
121-
return rows[0][0] * v[0] + rows[1][0] * v[1] + rows[2][0] * v[2];
116+
_FORCE_INLINE_ real_t tdotx(const Vector3 &p_v) const {
117+
return rows[0][0] * p_v[0] + rows[1][0] * p_v[1] + rows[2][0] * p_v[2];
122118
}
123-
_FORCE_INLINE_ real_t tdoty(const Vector3 &v) const {
124-
return rows[0][1] * v[0] + rows[1][1] * v[1] + rows[2][1] * v[2];
119+
_FORCE_INLINE_ real_t tdoty(const Vector3 &p_v) const {
120+
return rows[0][1] * p_v[0] + rows[1][1] * p_v[1] + rows[2][1] * p_v[2];
125121
}
126-
_FORCE_INLINE_ real_t tdotz(const Vector3 &v) const {
127-
return rows[0][2] * v[0] + rows[1][2] * v[1] + rows[2][2] * v[2];
122+
_FORCE_INLINE_ real_t tdotz(const Vector3 &p_v) const {
123+
return rows[0][2] * p_v[0] + rows[1][2] * p_v[1] + rows[2][2] * p_v[2];
128124
}
129125

130126
bool is_equal_approx(const Basis &p_basis) const;
@@ -141,31 +137,35 @@ struct [[nodiscard]] Basis {
141137
_FORCE_INLINE_ Basis operator+(const Basis &p_matrix) const;
142138
_FORCE_INLINE_ void operator-=(const Basis &p_matrix);
143139
_FORCE_INLINE_ Basis operator-(const Basis &p_matrix) const;
144-
_FORCE_INLINE_ void operator*=(const real_t p_val);
145-
_FORCE_INLINE_ Basis operator*(const real_t p_val) const;
140+
_FORCE_INLINE_ void operator*=(real_t p_val);
141+
_FORCE_INLINE_ Basis operator*(real_t p_val) const;
142+
_FORCE_INLINE_ void operator/=(real_t p_val);
143+
_FORCE_INLINE_ Basis operator/(real_t p_val) const;
146144

147145
bool is_orthogonal() const;
146+
bool is_orthonormal() const;
147+
bool is_conformal() const;
148148
bool is_diagonal() const;
149149
bool is_rotation() const;
150150

151-
Basis lerp(const Basis &p_to, const real_t &p_weight) const;
152-
Basis slerp(const Basis &p_to, const real_t &p_weight) const;
151+
Basis lerp(const Basis &p_to, real_t p_weight) const;
152+
Basis slerp(const Basis &p_to, real_t p_weight) const;
153153
void rotate_sh(real_t *p_values);
154154

155155
operator String() const;
156156

157157
/* create / set */
158158

159-
_FORCE_INLINE_ void set(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) {
160-
rows[0][0] = xx;
161-
rows[0][1] = xy;
162-
rows[0][2] = xz;
163-
rows[1][0] = yx;
164-
rows[1][1] = yy;
165-
rows[1][2] = yz;
166-
rows[2][0] = zx;
167-
rows[2][1] = zy;
168-
rows[2][2] = zz;
159+
_FORCE_INLINE_ void set(real_t p_xx, real_t p_xy, real_t p_xz, real_t p_yx, real_t p_yy, real_t p_yz, real_t p_zx, real_t p_zy, real_t p_zz) {
160+
rows[0][0] = p_xx;
161+
rows[0][1] = p_xy;
162+
rows[0][2] = p_xz;
163+
rows[1][0] = p_yx;
164+
rows[1][1] = p_yy;
165+
rows[1][2] = p_yz;
166+
rows[2][0] = p_zx;
167+
rows[2][1] = p_zy;
168+
rows[2][2] = p_zz;
169169
}
170170
_FORCE_INLINE_ void set_columns(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) {
171171
set_column(0, p_x);
@@ -195,20 +195,20 @@ struct [[nodiscard]] Basis {
195195
rows[2].zero();
196196
}
197197

198-
_FORCE_INLINE_ Basis transpose_xform(const Basis &m) const {
198+
_FORCE_INLINE_ Basis transpose_xform(const Basis &p_m) const {
199199
return Basis(
200-
rows[0].x * m[0].x + rows[1].x * m[1].x + rows[2].x * m[2].x,
201-
rows[0].x * m[0].y + rows[1].x * m[1].y + rows[2].x * m[2].y,
202-
rows[0].x * m[0].z + rows[1].x * m[1].z + rows[2].x * m[2].z,
203-
rows[0].y * m[0].x + rows[1].y * m[1].x + rows[2].y * m[2].x,
204-
rows[0].y * m[0].y + rows[1].y * m[1].y + rows[2].y * m[2].y,
205-
rows[0].y * m[0].z + rows[1].y * m[1].z + rows[2].y * m[2].z,
206-
rows[0].z * m[0].x + rows[1].z * m[1].x + rows[2].z * m[2].x,
207-
rows[0].z * m[0].y + rows[1].z * m[1].y + rows[2].z * m[2].y,
208-
rows[0].z * m[0].z + rows[1].z * m[1].z + rows[2].z * m[2].z);
200+
rows[0].x * p_m[0].x + rows[1].x * p_m[1].x + rows[2].x * p_m[2].x,
201+
rows[0].x * p_m[0].y + rows[1].x * p_m[1].y + rows[2].x * p_m[2].y,
202+
rows[0].x * p_m[0].z + rows[1].x * p_m[1].z + rows[2].x * p_m[2].z,
203+
rows[0].y * p_m[0].x + rows[1].y * p_m[1].x + rows[2].y * p_m[2].x,
204+
rows[0].y * p_m[0].y + rows[1].y * p_m[1].y + rows[2].y * p_m[2].y,
205+
rows[0].y * p_m[0].z + rows[1].y * p_m[1].z + rows[2].y * p_m[2].z,
206+
rows[0].z * p_m[0].x + rows[1].z * p_m[1].x + rows[2].z * p_m[2].x,
207+
rows[0].z * p_m[0].y + rows[1].z * p_m[1].y + rows[2].z * p_m[2].y,
208+
rows[0].z * p_m[0].z + rows[1].z * p_m[1].z + rows[2].z * p_m[2].z);
209209
}
210-
Basis(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) {
211-
set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
210+
Basis(real_t p_xx, real_t p_xy, real_t p_xz, real_t p_yx, real_t p_yy, real_t p_yz, real_t p_zx, real_t p_zy, real_t p_zz) {
211+
set(p_xx, p_xy, p_xz, p_yx, p_yy, p_yz, p_zx, p_zy, p_zz);
212212
}
213213

214214
void orthonormalize();
@@ -282,18 +282,30 @@ _FORCE_INLINE_ Basis Basis::operator-(const Basis &p_matrix) const {
282282
return ret;
283283
}
284284

285-
_FORCE_INLINE_ void Basis::operator*=(const real_t p_val) {
285+
_FORCE_INLINE_ void Basis::operator*=(real_t p_val) {
286286
rows[0] *= p_val;
287287
rows[1] *= p_val;
288288
rows[2] *= p_val;
289289
}
290290

291-
_FORCE_INLINE_ Basis Basis::operator*(const real_t p_val) const {
291+
_FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const {
292292
Basis ret(*this);
293293
ret *= p_val;
294294
return ret;
295295
}
296296

297+
_FORCE_INLINE_ void Basis::operator/=(real_t p_val) {
298+
rows[0] /= p_val;
299+
rows[1] /= p_val;
300+
rows[2] /= p_val;
301+
}
302+
303+
_FORCE_INLINE_ Basis Basis::operator/(real_t p_val) const {
304+
Basis ret(*this);
305+
ret /= p_val;
306+
return ret;
307+
}
308+
297309
Vector3 Basis::xform(const Vector3 &p_vector) const {
298310
return Vector3(
299311
rows[0].dot(p_vector),

0 commit comments

Comments
 (0)