feat(physics): phys_heightfield_smooth - the ground as a renderer draws a cubic B-spline height map, smoothed in C

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 00:27:15 +03:00
parent c7a18fd4f0
commit d2cd775309
6 changed files with 48 additions and 2 deletions

View file

@ -131,4 +131,20 @@ program PhysicsTest {
expect(not phys_resolve(physics_st, 5.0, 3.0, 0.35, 0.0, 1.8, PHYS_M_STATIC))
phys_close(physics_st)
}
test "a smoothed heightfield stands where a B-spline of its texels is" (physics_st: mut PhysicsState) {
expect(phys_open(physics_st, 64, 1))
let n = 32
let t = floats(n * n)
for z in 0 .. n { for x in 0 .. n { t[z * n + x] = float(x % 2) * 3.0 } }
let g = phys_heightfield_smooth(physics_st, t, n, 0.5, 0.5, 1.0)
expect(g >= 0)
phys_ground_add(physics_st, g)
phys_settle(physics_st)
let odd = phys_ray(physics_st, 5.5, 50.0, 10.5, 0.0, -100.0, 0.0, PHYS_M_GROUND)
let even = phys_ray(physics_st, 6.5, 50.0, 10.5, 0.0, -100.0, 0.0, PHYS_M_GROUND)
expect(Math.abs(odd.y - 2.0) < 0.01)
expect(Math.abs(even.y - 1.0) < 0.01)
phys_close(physics_st)
}
}