Skip to content

@ue-too/board / index / convert2WorldSpaceAnchorAtCenter

関数: convert2WorldSpaceAnchorAtCenter()

convert2WorldSpaceAnchorAtCenter(point, cameraPosition, cameraZoomLevel, cameraRotation): Point

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

Converts a viewport point (center-anchored) to world space. This is the most commonly used viewport-to-world conversion function.

パラメータ

point

Point

Point in viewport coordinates (origin at viewport center)

cameraPosition

Point

Camera position in world coordinates

cameraZoomLevel

number

Camera zoom level

cameraRotation

number

Camera rotation in radians

戻り値

Point

World space coordinates of the point

Remarks

Viewport coordinates have the origin at the center of the viewport, with:

  • Positive x to the right
  • Positive y upward
  • Point (0, 0) is the center of the viewport

This is the standard coordinate system for camera operations.

typescript
// Convert viewport center (0,0) to world space
const worldCenter = convert2WorldSpaceAnchorAtCenter(
  { x: 0, y: 0 },
  { x: 500, y: 300 },  // camera at world (500, 300)
  1.0,
  0
);
// worldCenter will be { x: 500, y: 300 }

// Convert point 100 pixels right of center
const rightPoint = convert2WorldSpaceAnchorAtCenter(
  { x: 100, y: 0 },
  { x: 500, y: 300 },
  2.0,  // 2x zoom
  0
);
// At 2x zoom, 100 viewport pixels = 50 world units
// Result: { x: 550, y: 300 }