ECE 2036 Project
Dependencies: mbed wave_player 4DGL-uLCD-SE
physics.cpp@2:2042f29de6b7, 2019-11-21 (annotated)
- Committer:
- abraha2d
- Date:
- Thu Nov 21 16:10:57 2019 +0000
- Revision:
- 2:2042f29de6b7
- Parent:
- 0:cf4396614a79
Because other peeps is wanting dis...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:cf4396614a79 | 1 | #include "physics.h" |
rconnorlawson | 0:cf4396614a79 | 2 | #include "math_extra.h" |
rconnorlawson | 0:cf4396614a79 | 3 | |
rconnorlawson | 0:cf4396614a79 | 4 | void forward_euler(Physics* state, float delta) |
abraha2d | 2:2042f29de6b7 | 5 | { |
rconnorlawson | 0:cf4396614a79 | 6 | // TODO: Implement proper forward euler updates for position and velocity |
abraha2d | 2:2042f29de6b7 | 7 | |
rconnorlawson | 0:cf4396614a79 | 8 | // Compute random motion |
abraha2d | 2:2042f29de6b7 | 9 | // float damp = 0.5; |
abraha2d | 2:2042f29de6b7 | 10 | // float dx = damp*coin_flip(); |
abraha2d | 2:2042f29de6b7 | 11 | // float dy = damp*coin_flip(); |
abraha2d | 2:2042f29de6b7 | 12 | |
abraha2d | 2:2042f29de6b7 | 13 | // state->px = state->px + dx; |
abraha2d | 2:2042f29de6b7 | 14 | // state->py = state->py + dy; |
abraha2d | 2:2042f29de6b7 | 15 | // state->vx = dx; |
abraha2d | 2:2042f29de6b7 | 16 | // state->vy = dy; |
rconnorlawson | 0:cf4396614a79 | 17 | |
rconnorlawson | 0:cf4396614a79 | 18 | // Update position and velocity |
abraha2d | 2:2042f29de6b7 | 19 | state->vx += state->ax * delta; |
abraha2d | 2:2042f29de6b7 | 20 | state->vy += state->ay * delta; |
abraha2d | 2:2042f29de6b7 | 21 | state->px += state->vx * delta; |
abraha2d | 2:2042f29de6b7 | 22 | state->py += state->vy * delta; |
abraha2d | 2:2042f29de6b7 | 23 | |
rconnorlawson | 0:cf4396614a79 | 24 | } |