summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-07-10 10:38:07 +0200
committerGitHub <noreply@github.com>2020-07-10 10:38:07 +0200
commit08c1657c99b5631475281b4f1370c69d359bb8df (patch)
tree14273369205d0816ab24e8906e85824860182fa9 /scene
parentda4851a9defe230e427d04c7e3c0aef714a40bff (diff)
parentbe3a1769fee6aab1a05176f41f2a03e095366fab (diff)
Merge pull request #40197 from mrushyendra/pathfollow_master
Fix repeated updates of PathFollow3D Transform
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/path_3d.cpp76
-rw-r--r--scene/3d/path_3d.h2
2 files changed, 40 insertions, 38 deletions
diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp
index 40d988ff9f..bf69a8598d 100644
--- a/scene/3d/path_3d.cpp
+++ b/scene/3d/path_3d.cpp
@@ -84,7 +84,7 @@ void Path3D::_bind_methods() {
//////////////
-void PathFollow3D::_update_transform() {
+void PathFollow3D::_update_transform(bool p_update_xyz_rot) {
if (!path) {
return;
}
@@ -156,45 +156,47 @@ void PathFollow3D::_update_transform() {
t.origin = pos;
- Vector3 t_prev = (pos - c->interpolate_baked(offset - delta_offset, cubic)).normalized();
- Vector3 t_cur = (c->interpolate_baked(offset + delta_offset, cubic) - pos).normalized();
-
- Vector3 axis = t_prev.cross(t_cur);
- float dot = t_prev.dot(t_cur);
- float angle = Math::acos(CLAMP(dot, -1, 1));
-
- if (likely(!Math::is_zero_approx(angle))) {
- if (rotation_mode == ROTATION_Y) {
- // assuming we're referring to global Y-axis. is this correct?
- axis.x = 0;
- axis.z = 0;
- } else if (rotation_mode == ROTATION_XY) {
- axis.z = 0;
- } else if (rotation_mode == ROTATION_XYZ) {
- // all components are allowed
- }
+ if (p_update_xyz_rot) { // Only update rotation if some parameter has changed - i.e. not on addition to scene tree
+ Vector3 t_prev = (pos - c->interpolate_baked(offset - delta_offset, cubic)).normalized();
+ Vector3 t_cur = (c->interpolate_baked(offset + delta_offset, cubic) - pos).normalized();
+
+ Vector3 axis = t_prev.cross(t_cur);
+ float dot = t_prev.dot(t_cur);
+ float angle = Math::acos(CLAMP(dot, -1, 1));
+
+ if (likely(!Math::is_zero_approx(angle))) {
+ if (rotation_mode == ROTATION_Y) {
+ // assuming we're referring to global Y-axis. is this correct?
+ axis.x = 0;
+ axis.z = 0;
+ } else if (rotation_mode == ROTATION_XY) {
+ axis.z = 0;
+ } else if (rotation_mode == ROTATION_XYZ) {
+ // all components are allowed
+ }
- if (likely(!Math::is_zero_approx(axis.length()))) {
- t.rotate_basis(axis.normalized(), angle);
+ if (likely(!Math::is_zero_approx(axis.length()))) {
+ t.rotate_basis(axis.normalized(), angle);
+ }
}
- }
- // do the additional tilting
- float tilt_angle = c->interpolate_baked_tilt(offset);
- Vector3 tilt_axis = t_cur; // not sure what tilt is supposed to do, is this correct??
-
- if (likely(!Math::is_zero_approx(Math::abs(tilt_angle)))) {
- if (rotation_mode == ROTATION_Y) {
- tilt_axis.x = 0;
- tilt_axis.z = 0;
- } else if (rotation_mode == ROTATION_XY) {
- tilt_axis.z = 0;
- } else if (rotation_mode == ROTATION_XYZ) {
- // all components are allowed
- }
+ // do the additional tilting
+ float tilt_angle = c->interpolate_baked_tilt(offset);
+ Vector3 tilt_axis = t_cur; // not sure what tilt is supposed to do, is this correct??
+
+ if (likely(!Math::is_zero_approx(Math::abs(tilt_angle)))) {
+ if (rotation_mode == ROTATION_Y) {
+ tilt_axis.x = 0;
+ tilt_axis.z = 0;
+ } else if (rotation_mode == ROTATION_XY) {
+ tilt_axis.z = 0;
+ } else if (rotation_mode == ROTATION_XYZ) {
+ // all components are allowed
+ }
- if (likely(!Math::is_zero_approx(tilt_axis.length()))) {
- t.rotate_basis(tilt_axis.normalized(), tilt_angle);
+ if (likely(!Math::is_zero_approx(tilt_axis.length()))) {
+ t.rotate_basis(tilt_axis.normalized(), tilt_angle);
+ }
}
}
@@ -213,7 +215,7 @@ void PathFollow3D::_notification(int p_what) {
if (parent) {
path = Object::cast_to<Path3D>(parent);
if (path) {
- _update_transform();
+ _update_transform(false);
}
}
diff --git a/scene/3d/path_3d.h b/scene/3d/path_3d.h
index 7f227a8a6f..9c50bd4906 100644
--- a/scene/3d/path_3d.h
+++ b/scene/3d/path_3d.h
@@ -75,7 +75,7 @@ private:
bool loop;
RotationMode rotation_mode;
- void _update_transform();
+ void _update_transform(bool p_update_xyz_rot = true);
protected:
virtual void _validate_property(PropertyInfo &property) const;