Skip to content

@ue-too/board / index / convertDeltaInWorldToViewPortSpace

函式: convertDeltaInWorldToViewPortSpace()

convertDeltaInWorldToViewPortSpace(delta, cameraZoomLevel, cameraRotation): Point

定義於: packages/board/src/camera/utils/coordinate-conversion.ts:413

Converts a displacement vector from world space to viewport space. Use this for converting movement deltas, not absolute positions. Inverse of convertDeltaInViewPortToWorldSpace.

參數

delta

Point

Displacement vector in world coordinates

cameraZoomLevel

number

Camera zoom level

cameraRotation

number

Camera rotation in radians

回傳

Point

Displacement vector in viewport space (CSS pixels)

備註

This transforms a relative displacement, not an absolute point. The conversion accounts for:

  • Rotation: Delta is rotated by -camera rotation
  • Zoom: Delta is scaled by zoom (world units → viewport pixels)

範例

typescript
// Object moved 50 units right in world space
const worldDelta = { x: 50, y: 0 };
const viewportDelta = convertDeltaInWorldToViewPortSpace(
  worldDelta,
  2.0,  // 2x zoom
  0     // no rotation
);
// Result: { x: 100, y: 0 } (50 world units = 100 viewport pixels at 2x zoom)