@@ -45,7 +45,8 @@ bool is_equal_approx(const Vector3 &p_a, const Vector3 &p_b) {
4545}
4646
4747TEST_CASE (" [SceneTree][PathFollow3D] Sampling with progress ratio" ) {
48- Ref<Curve3D> curve = memnew (Curve3D);
48+ Ref<Curve3D> curve;
49+ curve.instantiate ();
4950 curve->add_point (Vector3 (0 , 0 , 0 ));
5051 curve->add_point (Vector3 (100 , 0 , 0 ));
5152 curve->add_point (Vector3 (100 , 100 , 0 ));
@@ -89,7 +90,8 @@ TEST_CASE("[SceneTree][PathFollow3D] Sampling with progress ratio") {
8990}
9091
9192TEST_CASE (" [SceneTree][PathFollow3D] Sampling with progress" ) {
92- Ref<Curve3D> curve = memnew (Curve3D);
93+ Ref<Curve3D> curve;
94+ curve.instantiate ();
9395 curve->add_point (Vector3 (0 , 0 , 0 ));
9496 curve->add_point (Vector3 (100 , 0 , 0 ));
9597 curve->add_point (Vector3 (100 , 100 , 0 ));
@@ -133,7 +135,8 @@ TEST_CASE("[SceneTree][PathFollow3D] Sampling with progress") {
133135}
134136
135137TEST_CASE (" [SceneTree][PathFollow3D] Removal of a point in curve" ) {
136- Ref<Curve3D> curve = memnew (Curve3D);
138+ Ref<Curve3D> curve;
139+ curve.instantiate ();
137140 curve->add_point (Vector3 (0 , 0 , 0 ));
138141 curve->add_point (Vector3 (100 , 0 , 0 ));
139142 curve->add_point (Vector3 (100 , 100 , 0 ));
@@ -157,7 +160,8 @@ TEST_CASE("[SceneTree][PathFollow3D] Removal of a point in curve") {
157160}
158161
159162TEST_CASE (" [SceneTree][PathFollow3D] Progress ratio out of range" ) {
160- Ref<Curve3D> curve = memnew (Curve3D);
163+ Ref<Curve3D> curve;
164+ curve.instantiate ();
161165 curve->add_point (Vector3 (0 , 0 , 0 ));
162166 curve->add_point (Vector3 (100 , 0 , 0 ));
163167 Path3D *path = memnew (Path3D);
@@ -194,7 +198,8 @@ TEST_CASE("[SceneTree][PathFollow3D] Progress ratio out of range") {
194198}
195199
196200TEST_CASE (" [SceneTree][PathFollow3D] Progress out of range" ) {
197- Ref<Curve3D> curve = memnew (Curve3D);
201+ Ref<Curve3D> curve;
202+ curve.instantiate ();
198203 curve->add_point (Vector3 (0 , 0 , 0 ));
199204 curve->add_point (Vector3 (100 , 0 , 0 ));
200205 Path3D *path = memnew (Path3D);
@@ -232,7 +237,8 @@ TEST_CASE("[SceneTree][PathFollow3D] Progress out of range") {
232237
233238TEST_CASE (" [SceneTree][PathFollow3D] Calculate forward vector" ) {
234239 const real_t dist_cube_100 = 100 * Math::sqrt (3.0 );
235- Ref<Curve3D> curve = memnew (Curve3D);
240+ Ref<Curve3D> curve;
241+ curve.instantiate ();
236242 curve->add_point (Vector3 (0 , 0 , 0 ));
237243 curve->add_point (Vector3 (100 , 0 , 0 ));
238244 curve->add_point (Vector3 (200 , 100 , -100 ));
@@ -283,4 +289,52 @@ TEST_CASE("[SceneTree][PathFollow3D] Calculate forward vector") {
283289
284290 memdelete (path);
285291}
292+
293+ TEST_CASE (" [SceneTree][PathFollow3D] Calculate forward vector with degenerate curves" ) {
294+ Ref<Curve3D> curve;
295+ curve.instantiate ();
296+ curve->add_point (Vector3 (0 , 0 , 1 ), Vector3 (), Vector3 (1 , 0 , 0 ));
297+ curve->add_point (Vector3 (1 , 0 , 0 ), Vector3 (0 , 0 , 0 ), Vector3 (0 , 0 , 0 ));
298+ curve->add_point (Vector3 (0 , 0 , -1 ), Vector3 (1 , 0 , 0 ), Vector3 (-1 , 0 , 0 ));
299+ curve->add_point (Vector3 (-1 , 0 , 0 ), Vector3 (0 , 0 , 0 ), Vector3 (0 , 0 , 0 ));
300+ curve->add_point (Vector3 (0 , 0 , 1 ), Vector3 (-1 , 0 , 0 ), Vector3 ());
301+ Path3D *path = memnew (Path3D);
302+ path->set_curve (curve);
303+ PathFollow3D *path_follow_3d = memnew (PathFollow3D);
304+ path->add_child (path_follow_3d);
305+ SceneTree::get_singleton ()->get_root ()->add_child (path);
306+
307+ path_follow_3d->set_loop (false );
308+ path_follow_3d->set_rotation_mode (PathFollow3D::RotationMode::ROTATION_ORIENTED);
309+
310+ path_follow_3d->set_progress_ratio (0.00 );
311+ CHECK (is_equal_approx (Vector3 (-1 , 0 , 0 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
312+
313+ path_follow_3d->set_progress_ratio (0.25 );
314+ CHECK (is_equal_approx (Vector3 (0 , 0 , 1 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
315+
316+ path_follow_3d->set_progress_ratio (0.50 );
317+ CHECK (is_equal_approx (Vector3 (1 , 0 , 0 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
318+
319+ path_follow_3d->set_progress_ratio (0.75 );
320+ CHECK (is_equal_approx (Vector3 (0 , 0 , -1 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
321+
322+ path_follow_3d->set_progress_ratio (1.00 );
323+ CHECK (is_equal_approx (Vector3 (-1 , 0 , 0 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
324+
325+ path_follow_3d->set_progress_ratio (0.125 );
326+ CHECK (is_equal_approx (Vector3 (-0.688375 , 0 , 0.725355 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
327+
328+ path_follow_3d->set_progress_ratio (0.375 );
329+ CHECK (is_equal_approx (Vector3 (0.688375 , 0 , 0.725355 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
330+
331+ path_follow_3d->set_progress_ratio (0.625 );
332+ CHECK (is_equal_approx (Vector3 (0.688375 , 0 , -0.725355 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
333+
334+ path_follow_3d->set_progress_ratio (0.875 );
335+ CHECK (is_equal_approx (Vector3 (-0.688375 , 0 , -0.725355 ), path_follow_3d->get_transform ().get_basis ().get_column (2 )));
336+
337+ memdelete (path);
338+ }
339+
286340} // namespace TestPathFollow3D
0 commit comments