Skip to content

Commit

Permalink
Reworked camera smoothing (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Jan 6, 2024
1 parent c72270c commit 70c08fd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
8 changes: 2 additions & 6 deletions Sources/Jazz2/LevelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,10 +1572,6 @@ namespace Jazz2
Vector2f focusPos = targetObj->_pos;
Vector2f focusSpeed = targetObj->_speed;

Vector2f focusDiff = focusPos - _cameraLastPos;
_cameraDiff.X = lerpByTime(_cameraDiff.X, focusDiff.X, 0.8f, timeMult);
_cameraDiff.Y = lerpByTime(_cameraDiff.Y, focusDiff.Y, 0.8f, timeMult);

_cameraLastPos = focusPos;

_cameraDistanceFactor.X = lerpByTime(_cameraDistanceFactor.X, focusSpeed.X * 8.0f, (std::abs(focusSpeed.X) < 2.0f ? SlowRatioX : FastRatioX), timeMult);
Expand All @@ -1595,15 +1591,15 @@ namespace Jazz2

// Clamp camera position to level bounds
if (_viewBounds.W > halfView.X * 2) {
_cameraPos.X = std::clamp(_cameraLastPos.X + _cameraDistanceFactor.X - _cameraDiff.X, _viewBounds.X + halfView.X, _viewBounds.X + _viewBounds.W - halfView.X) + _shakeOffset.X;
_cameraPos.X = std::clamp(_cameraLastPos.X + _cameraDistanceFactor.X, _viewBounds.X + halfView.X, _viewBounds.X + _viewBounds.W - halfView.X) + _shakeOffset.X;
if (!PreferencesCache::UnalignedViewport || std::abs(_cameraDistanceFactor.X) < 1.0f) {
_cameraPos.X = std::floor(_cameraPos.X);
}
} else {
_cameraPos.X = std::floor(_viewBounds.X + _viewBounds.W * 0.5f + _shakeOffset.X);
}
if (_viewBounds.H > halfView.Y * 2) {
_cameraPos.Y = std::clamp(_cameraLastPos.Y + _cameraDistanceFactor.Y - _cameraDiff.Y, _viewBounds.Y + halfView.Y - 1.0f, _viewBounds.Y + _viewBounds.H - halfView.Y - 2.0f) + _shakeOffset.Y;
_cameraPos.Y = std::clamp(_cameraLastPos.Y + _cameraDistanceFactor.Y, _viewBounds.Y + halfView.Y - 1.0f, _viewBounds.Y + _viewBounds.H - halfView.Y - 2.0f) + _shakeOffset.Y;
if (!PreferencesCache::UnalignedViewport || std::abs(_cameraDistanceFactor.Y) < 1.0f) {
_cameraPos.Y = std::floor(_cameraPos.Y);
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Jazz2/LevelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ namespace Jazz2
Vector2f _cameraPos;
Vector2f _cameraLastPos;
Vector2f _cameraDistanceFactor;
Vector2f _cameraDiff;
float _shakeDuration;
Vector2f _shakeOffset;
float _waterLevel;
Expand Down

0 comments on commit 70c08fd

Please sign in to comment.