瀏覽代碼

Merge pull request #96328 from object71/fix-animation-snap-96159

Add `modf` function and fix animation editor snap behavior
Rémi Verschelde 1 年之前
父節點
當前提交
52d1b0be4a
共有 2 個文件被更改,包括 7 次插入1 次删除
  1. 3 0
      core/math/math_funcs.h
  2. 4 1
      editor/animation_track_editor.cpp

+ 3 - 0
core/math/math_funcs.h

@@ -105,6 +105,9 @@ public:
 	static _ALWAYS_INLINE_ double fmod(double p_x, double p_y) { return ::fmod(p_x, p_y); }
 	static _ALWAYS_INLINE_ double fmod(double p_x, double p_y) { return ::fmod(p_x, p_y); }
 	static _ALWAYS_INLINE_ float fmod(float p_x, float p_y) { return ::fmodf(p_x, p_y); }
 	static _ALWAYS_INLINE_ float fmod(float p_x, float p_y) { return ::fmodf(p_x, p_y); }
 
 
+	static _ALWAYS_INLINE_ double modf(double p_x, double *r_y) { return ::modf(p_x, r_y); }
+	static _ALWAYS_INLINE_ float modf(float p_x, float *r_y) { return ::modff(p_x, r_y); }
+
 	static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); }
 	static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); }
 	static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); }
 	static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); }
 
 

+ 4 - 1
editor/animation_track_editor.cpp

@@ -7052,7 +7052,10 @@ void AnimationTrackEditor::_update_snap_unit() {
 	if (timeline->is_using_fps()) {
 	if (timeline->is_using_fps()) {
 		snap_unit = 1.0 / step->get_value();
 		snap_unit = 1.0 / step->get_value();
 	} else {
 	} else {
-		snap_unit = 1.0 / Math::round(1.0 / step->get_value()); // Follow the snap behavior of the timeline editor.
+		double integer;
+		double fraction = Math::modf(step->get_value(), &integer);
+		fraction = 1.0 / Math::round(1.0 / fraction);
+		snap_unit = integer + fraction;
 	}
 	}
 }
 }