fix: Correct mouse-centered wheel zoom functionality
- Fix ScreenToWorld coordinate transformation bug in wheel event - Implement proper mouse cursor-centered zoom calculation - Calculate world coordinates before zoom and maintain them after zoom - Adjust pan offset to keep mouse cursor pointing at same world position - Remove matrix-based transformation that was causing coordinate issues Fixes: Wheel zoom now correctly centers on mouse cursor position and no longer causes erratic panning 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -170,23 +170,25 @@ namespace AGVNavigationCore.Controls
|
|||||||
|
|
||||||
private void UnifiedAGVCanvas_MouseWheel(object sender, MouseEventArgs e)
|
private void UnifiedAGVCanvas_MouseWheel(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
// 현재 마우스 위치를 월드 좌표로 변환 (줌 전)
|
// 마우스 커서 위치 (스크린 좌표)
|
||||||
var mouseWorldBefore = ScreenToWorld(e.Location);
|
Point mouseScreenPos = e.Location;
|
||||||
|
|
||||||
|
// 줌 전 마우스가 가리키는 월드 좌표
|
||||||
|
float worldX_before = (mouseScreenPos.X - _panOffset.X) / _zoomFactor;
|
||||||
|
float worldY_before = (mouseScreenPos.Y - _panOffset.Y) / _zoomFactor;
|
||||||
|
|
||||||
|
// 이전 줌 팩터 저장
|
||||||
float oldZoom = _zoomFactor;
|
float oldZoom = _zoomFactor;
|
||||||
|
|
||||||
// 줌 팩터 계산 (휠 델타 기반) - 더 부드러운 줌
|
// 줌 팩터 계산 (휠 델타 기반)
|
||||||
if (e.Delta > 0)
|
if (e.Delta > 0)
|
||||||
_zoomFactor = Math.Min(_zoomFactor * 1.15f, 5.0f); // 확대 (더 부드러움)
|
_zoomFactor = Math.Min(_zoomFactor * 1.15f, 5.0f); // 확대
|
||||||
else
|
else
|
||||||
_zoomFactor = Math.Max(_zoomFactor / 1.15f, 0.1f); // 축소 (더 부드러움)
|
_zoomFactor = Math.Max(_zoomFactor / 1.15f, 0.1f); // 축소
|
||||||
|
|
||||||
// 줌 후 마우스 위치의 월드 좌표
|
// 줌 후에도 마우스가 같은 월드 좌표를 가리키도록 팬 오프셋 조정
|
||||||
var mouseWorldAfter = ScreenToWorld(e.Location);
|
_panOffset.X = (int)(mouseScreenPos.X - worldX_before * _zoomFactor);
|
||||||
|
_panOffset.Y = (int)(mouseScreenPos.Y - worldY_before * _zoomFactor);
|
||||||
// 마우스 위치가 같은 월드 좌표를 가리키도록 팬 오프셋 조정
|
|
||||||
_panOffset.X += (int)((mouseWorldBefore.X - mouseWorldAfter.X) * _zoomFactor);
|
|
||||||
_panOffset.Y += (int)((mouseWorldBefore.Y - mouseWorldAfter.Y) * _zoomFactor);
|
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user