Skip to content

Commit 0a68e80

Browse files
authored
Merge pull request #2 from nayutalienx/copilot/fix-2d243eb4-254b-4344-8b38-bd0de531936b
Fix cursor trail interpolation gaps when moving cursor quickly
2 parents 57e5c16 + 5060b47 commit 0a68e80

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

CursorTrail/Game.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ void Game::Update(GLFWwindow* window)
7171

7272
TrailPart currentTrail = TrailPart(xpos, ypos, g_config.fadeTime);
7373

74-
// Add the current cursor position to trail
75-
this->AddPart(currentTrail);
76-
77-
// interpolate trail
78-
74+
// Calculate previous index BEFORE adding current trail
7975
int prevIndex;
8076
if (this->currentIndex != 0) {
8177
prevIndex = this->currentIndex - 1;
@@ -84,6 +80,11 @@ void Game::Update(GLFWwindow* window)
8480
prevIndex = g_config.maxParticles - 1;
8581
}
8682

83+
// Add the current cursor position to trail
84+
this->AddPart(currentTrail);
85+
86+
// interpolate trail
87+
8788
TrailPart previousTrail = this->parts[prevIndex];
8889

8990
glm::vec2 pos1 = glm::vec2(previousTrail.x, previousTrail.y);

CursorTrail/WindowsOverlay.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ void WindowsOverlay::Update()
164164
if (GetCursorPos(&cursorPos)) {
165165
TrailPart currentTrail(static_cast<float>(cursorPos.x), static_cast<float>(cursorPos.y), g_config.fadeTime);
166166

167+
// Calculate previous index BEFORE adding current trail
168+
size_t prevIndex = (m_currentIndex == 0) ? m_trailParts.size() - 1 : m_currentIndex - 1;
169+
167170
// Add the current cursor position to trail (match OpenGL version exactly)
168171
AddTrailPart(currentTrail);
169172

170173
// Interpolate trail between current and previous position ONLY (like OpenGL Game.cpp)
171-
size_t prevIndex = (m_currentIndex == 0) ? m_trailParts.size() - 1 : m_currentIndex - 1;
172174
const TrailPart& previousTrail = m_trailParts[prevIndex];
173175

174176
float dx = currentTrail.x - previousTrail.x;

0 commit comments

Comments
 (0)