Skip to content

Commit 2b4802d

Browse files
authored
Merge pull request godotengine#1715 from dsnopek/godot-sync-pre44
Synchronize most shared variant code with Godot 4.4
2 parents 67ca2fb + 075b517 commit 2b4802d

35 files changed

+4813
-888
lines changed

include/godot_cpp/core/math.hpp

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

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

include/godot_cpp/variant/aabb.hpp

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

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

8388
_FORCE_INLINE_ bool has_point(const Vector3 &p_point) const;
84-
_FORCE_INLINE_ Vector3 get_support(const Vector3 &p_normal) const;
89+
_FORCE_INLINE_ Vector3 get_support(const Vector3 &p_direction) const;
8590

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

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

222230
Vector3 AABB::get_endpoint(int p_point) const {
@@ -402,7 +410,7 @@ inline real_t AABB::get_shortest_axis_size() const {
402410
return max_size;
403411
}
404412

405-
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const {
413+
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t p_t0, real_t p_t1) const {
406414
#ifdef MATH_CHECKS
407415
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
408416
ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
@@ -453,7 +461,7 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
453461
if (tzmax < tmax) {
454462
tmax = tzmax;
455463
}
456-
return ((tmin < t1) && (tmax > t0));
464+
return ((tmin < p_t1) && (tmax > p_t0));
457465
}
458466

459467
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
@@ -43,11 +43,11 @@ struct [[nodiscard]] Basis {
4343
Vector3(0, 0, 1)
4444
};
4545

46-
_FORCE_INLINE_ const Vector3 &operator[](int axis) const {
47-
return rows[axis];
46+
_FORCE_INLINE_ const Vector3 &operator[](int p_row) const {
47+
return rows[p_row];
4848
}
49-
_FORCE_INLINE_ Vector3 &operator[](int axis) {
50-
return rows[axis];
49+
_FORCE_INLINE_ Vector3 &operator[](int p_row) {
50+
return rows[p_row];
5151
}
5252

5353
void invert();
@@ -58,21 +58,19 @@ struct [[nodiscard]] Basis {
5858

5959
_FORCE_INLINE_ real_t determinant() const;
6060

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

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

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

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

75-
Vector3 get_euler_normalized(EulerOrder p_order = EULER_ORDER_YXZ) const;
73+
Vector3 get_euler_normalized(EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) const;
7674
void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const;
7775
void get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) const;
7876
Quaternion get_rotation_quaternion() const;
@@ -81,9 +79,9 @@ struct [[nodiscard]] Basis {
8179

8280
Vector3 rotref_posscale_decomposition(Basis &rotref) const;
8381

84-
Vector3 get_euler(EulerOrder p_order = EULER_ORDER_YXZ) const;
85-
void set_euler(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ);
86-
static Basis from_euler(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ) {
82+
Vector3 get_euler(EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) const;
83+
void set_euler(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ);
84+
static Basis from_euler(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ) {
8785
Basis b;
8886
b.set_euler(p_euler, p_order);
8987
return b;
@@ -103,27 +101,25 @@ struct [[nodiscard]] Basis {
103101

104102
void scale_orthogonal(const Vector3 &p_scale);
105103
Basis scaled_orthogonal(const Vector3 &p_scale) const;
106-
107-
void make_scale_uniform();
108-
float get_uniform_scale() const;
104+
real_t get_uniform_scale() const;
109105

110106
Vector3 get_scale() const;
111107
Vector3 get_scale_abs() const;
112-
Vector3 get_scale_local() const;
108+
Vector3 get_scale_global() const;
113109

114110
void set_axis_angle_scale(const Vector3 &p_axis, real_t p_angle, const Vector3 &p_scale);
115-
void set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale, EulerOrder p_order = EULER_ORDER_YXZ);
111+
void set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale, EulerOrder p_order = EulerOrder::EULER_ORDER_YXZ);
116112
void set_quaternion_scale(const Quaternion &p_quaternion, const Vector3 &p_scale);
117113

118114
// transposed dot products
119-
_FORCE_INLINE_ real_t tdotx(const Vector3 &v) const {
120-
return rows[0][0] * v[0] + rows[1][0] * v[1] + rows[2][0] * v[2];
115+
_FORCE_INLINE_ real_t tdotx(const Vector3 &p_v) const {
116+
return rows[0][0] * p_v[0] + rows[1][0] * p_v[1] + rows[2][0] * p_v[2];
121117
}
122-
_FORCE_INLINE_ real_t tdoty(const Vector3 &v) const {
123-
return rows[0][1] * v[0] + rows[1][1] * v[1] + rows[2][1] * v[2];
118+
_FORCE_INLINE_ real_t tdoty(const Vector3 &p_v) const {
119+
return rows[0][1] * p_v[0] + rows[1][1] * p_v[1] + rows[2][1] * p_v[2];
124120
}
125-
_FORCE_INLINE_ real_t tdotz(const Vector3 &v) const {
126-
return rows[0][2] * v[0] + rows[1][2] * v[1] + rows[2][2] * v[2];
121+
_FORCE_INLINE_ real_t tdotz(const Vector3 &p_v) const {
122+
return rows[0][2] * p_v[0] + rows[1][2] * p_v[1] + rows[2][2] * p_v[2];
127123
}
128124

129125
bool is_equal_approx(const Basis &p_basis) const;
@@ -140,31 +136,35 @@ struct [[nodiscard]] Basis {
140136
_FORCE_INLINE_ Basis operator+(const Basis &p_matrix) const;
141137
_FORCE_INLINE_ void operator-=(const Basis &p_matrix);
142138
_FORCE_INLINE_ Basis operator-(const Basis &p_matrix) const;
143-
_FORCE_INLINE_ void operator*=(const real_t p_val);
144-
_FORCE_INLINE_ Basis operator*(const real_t p_val) const;
139+
_FORCE_INLINE_ void operator*=(real_t p_val);
140+
_FORCE_INLINE_ Basis operator*(real_t p_val) const;
141+
_FORCE_INLINE_ void operator/=(real_t p_val);
142+
_FORCE_INLINE_ Basis operator/(real_t p_val) const;
145143

146144
bool is_orthogonal() const;
145+
bool is_orthonormal() const;
146+
bool is_conformal() const;
147147
bool is_diagonal() const;
148148
bool is_rotation() const;
149149

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

154154
operator String() const;
155155

156156
/* create / set */
157157

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

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

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

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

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

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

0 commit comments

Comments
 (0)