This commit is contained in:
Schluffe
2026-09-04 13:57:52 +02:00
parent 71cfa64793
commit e961887953
24 changed files with 340 additions and 360 deletions
+10 -8
View File
@@ -1,6 +1,6 @@
# Step 05 — Sweeping in 1D (entry & exit time)
This is the seed of the whole engine. Get this one *in your bones* and the scary
This is the seed of the whole engine. Get this one _in your bones_ and the scary
2D `sweptAABB` becomes "do this twice and combine."
## Concept
@@ -9,26 +9,28 @@ Forget 2D. Forget boxes. We have:
- a **point** sitting at position `p` on a number line,
- moving with velocity `v` — meaning over this one frame it travels a total of
`v` units (so at fraction `t` of the frame, it's at `p + v*t`, for `t` from 0 to 1),
`v` units (so at fraction `t` of the frame, it's at `p + v*t`, for `t` from 0
to 1),
- and a static **interval** `[min, max]` on that same line.
Question: **during this frame, for which `t` is the point inside `[min, max]`?**
### The slab math
The point reaches `min` when `p + v*t = min`, i.e. `t = (min - p) / v`.
Likewise it reaches `max` at `t = (max - p) / v`.
The point reaches `min` when `p + v*t = min`, i.e. `t = (min - p) / v`. Likewise
it reaches `max` at `t = (max - p) / v`.
```
t1 = (min - p) / v
t2 = (max - p) / v
```
If `v` is **negative** (moving left), the point hits `max` *before* `min`, so
If `v` is **negative** (moving left), the point hits `max` _before_ `min`, so
`t1 > t2`. We always want `entry` to be the smaller and `exit` the larger, so
**swap them if they're out of order**. Then:
- `entry` = the time the point *enters* the interval,
- `exit` = the time it *leaves*.
- `entry` = the time the point _enters_ the interval,
- `exit` = the time it _leaves_.
> These can be negative or greater than 1 — that just means the crossing happens
> before this frame started or after it ends. Don't clamp here; the caller (step
@@ -37,7 +39,7 @@ If `v` is **negative** (moving left), the point hits `max` *before* `min`, so
### The `v == 0` edge case
If the point isn't moving (`v == 0`), it never *crosses* an edge — dividing by
If the point isn't moving (`v == 0`), it never _crosses_ an edge — dividing by
zero is meaningless. Instead: it's either already inside the interval for the
whole frame, or never. So: