Commit ca1490ad authored by Navid Zolghadr's avatar Navid Zolghadr Committed by Commit Bot

Make SyntheticSmoothMoveGesture smoother to make it more realistic

Bug: 1000682
Change-Id: Id5a6b7e87e983b475dda60821b1edff2ed23b0fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2027891
Commit-Queue: Navid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737867}
parent bbd20716
...@@ -17,6 +17,26 @@ gfx::Vector2dF ProjectScalarOntoVector(float scalar, ...@@ -17,6 +17,26 @@ gfx::Vector2dF ProjectScalarOntoVector(float scalar,
return gfx::ScaleVector2d(vector, scalar / vector.Length()); return gfx::ScaleVector2d(vector, scalar / vector.Length());
} }
// returns the animation progress along an arctan curve to provide simple
// ease-in ease-out behavior.
float GetCurvedRatio(const base::TimeTicks& current,
const base::TimeTicks& start,
const base::TimeTicks& end,
int speed_in_pixels_s) {
// Increasing this would make the start and the end of the curv smoother.
// Hence the higher value for the higher speed.
const float kArctanRange = sqrt(static_cast<double>(speed_in_pixels_s)) / 100;
const float kMaxArctan = std::atan(kArctanRange / 2);
const float kMinArctan = std::atan(-kArctanRange / 2);
float linear_ratio =
(current - start).InSecondsF() / (end - start).InSecondsF();
return (std::atan(kArctanRange * linear_ratio - kArctanRange / 2) -
kMinArctan) /
(kMaxArctan - kMinArctan);
}
const int kDefaultSpeedInPixelsPerSec = 800; const int kDefaultSpeedInPixelsPerSec = 800;
} // namespace } // namespace
...@@ -340,11 +360,11 @@ gfx::Vector2dF SyntheticSmoothMoveGesture::GetPositionDeltaAtTime( ...@@ -340,11 +360,11 @@ gfx::Vector2dF SyntheticSmoothMoveGesture::GetPositionDeltaAtTime(
if (FinishedCurrentMoveSegment(timestamp)) if (FinishedCurrentMoveSegment(timestamp))
return params_.distances[current_move_segment_]; return params_.distances[current_move_segment_];
float delta_length = return gfx::ScaleVector2d(
params_.speed_in_pixels_s * params_.distances[current_move_segment_],
(timestamp - current_move_segment_start_time_).InSecondsF(); GetCurvedRatio(timestamp, current_move_segment_start_time_,
return ProjectScalarOntoVector(delta_length, current_move_segment_stop_time_,
params_.distances[current_move_segment_]); params_.speed_in_pixels_s));
} }
void SyntheticSmoothMoveGesture::ComputeNextMoveSegment() { void SyntheticSmoothMoveGesture::ComputeNextMoveSegment() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment