Skip to content

Add inertia tensor and angular collision impulses#152

Merged
stainlu merged 1 commit intomainfrom
worktree-agent-a8e4aa45
Apr 8, 2026
Merged

Add inertia tensor and angular collision impulses#152
stainlu merged 1 commit intomainfrom
worktree-agent-a8e4aa45

Conversation

@stainlu
Copy link
Copy Markdown
Owner

@stainlu stainlu commented Apr 8, 2026

Summary

  • Extend Mass component with a diagonal inverse_inertia_tensor (Vec3) and add factory methods from_sphere, from_aabb, from_capsule for accurate per-shape inertia
  • All narrowphase collision functions now return world-space contact points alongside normal and depth
  • Rewrite apply_velocity_response with the standard rigid-body impulse formula: off-center contacts produce angular velocity changes via r x J torques, and the effective mass denominator includes rotational inertia terms
  • CollisionEvent gains a contact_point field

Backward compatibility

  • Mass::new(mass, inertia) produces a spherically symmetric tensor identical to the previous scalar behavior
  • Head-on sphere collisions: r x n == 0 so angular impulse is zero (regression-tested)
  • Kinematic/static bodies unaffected (zero inverse inertia tensor)

Test plan

  • Mass::new produces correct splat tensor
  • Mass::from_sphere, from_aabb, from_capsule produce correct values
  • Mass::infinite produces zero tensor
  • All existing collision tests pass with new (Vec3, f32, Vec3) return type
  • Sphere head-on collision: NO angular velocity change (regression test)
  • Sphere hits AABB edge: AABB gains angular velocity in correct direction
  • Off-center box-wall collision: box bounces AND spins
  • All 64 physics tests pass
  • Full workspace: cargo check, cargo clippy -- -D warnings, cargo fmt --check clean

🤖 Generated with Claude Code

Replace scalar inertia with a diagonal inertia tensor in the Mass
component. Extend narrowphase collision functions to return world-space
contact points. Rewrite collision response to apply angular impulses
from off-center contacts using the standard rigid-body impulse formula.

- Mass struct gains inverse_inertia_tensor field (Vec3, body-local diagonal)
- Factory methods: Mass::from_sphere, from_aabb, from_capsule with correct
  principal moments of inertia
- All intersect_* functions now return (normal, depth, contact_point)
- CollisionEvent gains contact_point field
- apply_velocity_response uses full rotational impulse formula: effective
  mass denominator includes I^-1 cross terms, angular velocity changes
  from both normal and friction impulses
- Backward compatible: Mass::new produces spherically symmetric tensor,
  head-on sphere collisions produce zero angular change

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying euca-engine with  Cloudflare Pages  Cloudflare Pages

Latest commit: 762d80f
Status: ✅  Deploy successful!
Preview URL: https://71eb512b.euca-engine.pages.dev
Branch Preview URL: https://worktree-agent-a8e4aa45.euca-engine.pages.dev

View logs

@stainlu stainlu merged commit 88bdf23 into main Apr 8, 2026
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant