Convert from screen to world space coordinates * @param {Vector2} screenPos * @return {Vector2} * @memberof Draw
(screenPos)
| 981 | * @return {Vector2} |
| 982 | * @memberof Draw */ |
| 983 | function 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 |
no test coverage detected