MCPcopy
hub / github.com/KilledByAPixel/LittleJS / screenToWorld

Function screenToWorld

src/engineDraw.js:983–997  ·  view source on GitHub ↗

Convert from screen to world space coordinates * @param {Vector2} screenPos * @return {Vector2} * @memberof Draw

(screenPos)

Source from the content-addressed store, hash-verified

981 * @return {Vector2}
982 * @memberof Draw */
983function screenToWorld(screenPos)
984{
985 ASSERT(isVector2(screenPos), 'screenPos must be a vec2');
986
987 let x = (screenPos.x - mainCanvasSize.x/2 + .5) / cameraScale;
988 let y = (screenPos.y - mainCanvasSize.y/2 + .5) / -cameraScale;
989 if (cameraAngle)
990 {
991 // apply camera rotation
992 const c = cos(-cameraAngle), s = sin(-cameraAngle);
993 const xr = x * c - y * s, yr = x * s + y * c;
994 x = xr; y = yr;
995 }
996 return new Vector2(x + cameraPos.x, y + cameraPos.y);
997}
998
999/** Convert from world to screen space coordinates
1000 * @param {Vector2} worldPos

Callers 4

inputUpdateFunction · 0.85
drawRectGradientFunction · 0.85
drawEllipseGradientFunction · 0.85
screenToWorldTransformFunction · 0.85

Calls 2

isVector2Function · 0.85
ASSERTFunction · 0.70

Tested by

no test coverage detected