pike/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 884b6d52e6dbc7666a34ac021063e9d1241a348a
| 1 | /** |
| 2 | * Keys to a direction on the map. |
| 3 | * |
| 4 | * The server has always been told a world-space direction, and that contract |
| 5 | * does not change: from inside the player's head W means "the way I am |
| 6 | * looking", so the keys are turned by the view angle before they are sent. |
| 7 | * In the top-down view the keys are the compass they always were. |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * `ax` is right on the keyboard (+1 for D), `ay` is down the screen (+1 for |
| 12 | * S, so forward is -1). `out` is filled and returned: no allocation. |
| 13 | */ |
| 14 | export function moveVector(ax, ay, yaw, out = { x: 0, y: 0 }) { |
| 15 | const cos = Math.cos(yaw); |
| 16 | const sin = Math.sin(yaw); |
| 17 | out.x = cos * -ay - sin * ax; |
| 18 | out.y = sin * -ay + cos * ax; |
| 19 | return out; |
| 20 | } |