ManagedChipmunk 0.1.0-dev.4

This is a prerelease version of ManagedChipmunk.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ManagedChipmunk --version 0.1.0-dev.4
                    
NuGet\Install-Package ManagedChipmunk -Version 0.1.0-dev.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ManagedChipmunk" Version="0.1.0-dev.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ManagedChipmunk" Version="0.1.0-dev.4" />
                    
Directory.Packages.props
<PackageReference Include="ManagedChipmunk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ManagedChipmunk --version 0.1.0-dev.4
                    
#r "nuget: ManagedChipmunk, 0.1.0-dev.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ManagedChipmunk@0.1.0-dev.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ManagedChipmunk&version=0.1.0-dev.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ManagedChipmunk&version=0.1.0-dev.4&prerelease
                    
Install as a Cake Tool

ManagedChipmunk

简体中文 · Contributing · Changelog

A pure C# port of Chipmunk 6.2.1 for .NET 10. ManagedChipmunk provides 2D rigid-body simulation with float precision and no native runtime dependencies. It preserves the recognizable Chipmunk object model and cp... function names.

Development preview: the built-in physics modules are implemented. The current inventory covers 408 public header functions and 11 managed adaptations of diagnostic/Apple Blocks interfaces. The recorded validation includes 94 checks and 3,606 original-C reference cases. This is not a claim of exhaustive correctness, cross-platform bitwise determinism, or production performance certification. See port status and validation.

Features

  • Dynamic, static, and rogue bodies; force/impulse application and custom integration callbacks.
  • Circles, capsule segments, convex polygons, beveled polygons, and all six shape-pair collision paths.
  • GJK/EPA narrow phase, contact caching, friction, restitution, surface velocity, and warm starting.
  • Dynamic AABB tree, spatial hash, and one-axis sweep indexes.
  • All ten constraints: pin, slide, pivot, groove, damped spring, damped rotary spring, rotary limit, ratchet, gear, and simple motor.
  • Point, nearest-point, ray/segment, AABB, and shape queries; collision groups, layers, and sensors.
  • Collision and post-step callbacks, contact graphs, sleeping components, and wake-up behavior.
  • Area, moment of inertia, centroid, convex hull, vector, matrix, and bounding-box utilities.

The runtime references only .NET's base libraries. Rendering, ECS, game rules, and networking belong to the host application; no game-engine integration is required to use this library.

Build and run

Install the .NET 10 SDK or a compatible newer SDK. Running the net10.0 executables also requires the .NET 10 runtime, which is included with the .NET 10 SDK. The repository does not pin an SDK through global.json.

git clone https://github.com/YingFengTingYu/ManagedChipmunk.git
cd ManagedChipmunk
dotnet build ManagedChipmunk.slnx -c Release
dotnet run --project tests/ManagedChipmunk.Tests -c Release --no-build
dotnet run --project samples/HelloPhysics -c Release --no-build

The tests use a console runner and committed reference fixtures. A failing check exits nonzero. Normal builds and tests need neither Python nor a C compiler. The optional maintainer tools are described in CONTRIBUTING.md.

Quick start

The HelloPhysics example drops a ball onto a floor using a fixed timestep:

using static ManagedChipmunk.cp;

var space = cpSpaceNew();
try
{
    cpSpaceSetGravity(space, cpv(0, -1000));
    var floor = cpSpaceAddShape(space,
        cpSegmentShapeNew(cpSpaceGetStaticBody(space), cpv(-500, 0), cpv(500, 0), 0));
    cpShapeSetFriction(floor, 0.8f);

    var body = cpSpaceAddBody(space,
        cpBodyNew(1, cpMomentForCircle(1, 0, 10, cpvzero)));
    cpBodySetPos(body, cpv(0, 100));
    var ball = cpSpaceAddShape(space, cpCircleShapeNew(body, 10, cpvzero));
    cpShapeSetFriction(ball, 0.8f);

    for (int i = 0; i < 300; i++) cpSpaceStep(space, 1f / 60);
    Console.WriteLine($"Ball position after 5 seconds: {cpvstr(cpBodyGetPos(body))}");
    // The center settles near y = 9.9: radius 10 minus the default collision slop 0.1.
}
finally
{
    cpSpaceFree(space);
}

Simulation conventions

  • cpFloat is System.Single; cpVect, cpBB, and cpMat2x2 have value semantics. Global functions are in ManagedChipmunk.cp.
  • The example uses Y-up coordinates. Keep units and timestep consistent across your application.
  • Prefer cp...Set... functions over direct field writes so activation and derived state stay consistent.
  • Polygons must be convex with clockwise winding. Use cpConvexHull for an unordered point set.
  • Reindex a shape after editing its geometry. Schedule add/remove operations from collision/query callbacks with cpSpaceAddPostStepCallback.
  • Forces and torque persist until explicitly reset, matching 6.2.1. Step and mutate each space on one thread.
  • C pointers and callbacks become managed references, spans, out parameters, and delegates. Memory/index storage is adapted for .NET; intentional behavior changes are documented.

Local NuGet package

Build a package with PowerShell 7 from the repository root:

pwsh -File scripts/pack.ps1

This verifies the upstream snapshot, runs the checks, and writes artifacts/packages/ManagedChipmunk.0.1.0-dev.4.nupkg. It refuses to overwrite an existing version. For a consumer project, replace the example project path below while running from this repository root:

dotnet add ../YourApp/YourApp.csproj package ManagedChipmunk --version 0.1.0-dev.4 --source ./artifacts/packages

These instructions use a locally built package; they do not assume publication on nuget.org. The library targets net10.0. AOT compatibility analysis is enabled, but NativeAOT/device validation remains a separate step.

Repository layout

Path Purpose
src/ManagedChipmunk Managed runtime library
samples/HelloPhysics Runnable headless example
tests/ManagedChipmunk.Tests Differential, numerical, lifecycle, and scene checks
tests/oracle Optional original-C fixture producer
reference/chipmunk-6.2.1 Unmodified upstream source snapshot
reference/upstream.json Upstream commit and per-file SHA-256 hashes
scripts Verification, packaging, and optional oracle build
tools API inventory and constraint/property conversion tools

License and upstream

ManagedChipmunk is released under the MIT license. The upstream copyright notice is retained, with a separate notice for the managed contributions. See THIRD-PARTY-NOTICES.md for attribution.

The baseline is slembcke/Chipmunk2D, tag Chipmunk-6.2.1, commit 451314744322ed3b256325b4f6f75cad29e2283c. ManagedChipmunk is an independent port, not an official upstream release.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-dev.5 39 11/19/2026
0.1.0-dev.4 53 11/17/2026
0.1.0-dev.3 49 11/17/2026