Boing 2.0.0

dotnet add package Boing --version 2.0.0
                    
NuGet\Install-Package Boing -Version 2.0.0
                    
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="Boing" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Boing" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Boing" />
                    
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 Boing --version 2.0.0
                    
#r "nuget: Boing, 2.0.0"
                    
#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 Boing@2.0.0
                    
#: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=Boing&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Boing&version=2.0.0
                    
Install as a Cake Tool

boing logo

Build status Boing NuGet version License

A simple library for 2D and 3D physics simulations in .NET.

Installation

The easiest way to use this library is via its NuGet package:

PM> Install-Package Boing

Boing supports net47 (.NET Framework 4.7 and above) and netstandard2.0 (.NET Standard 2.0 and above) for .NET Core and other platforms.

Usage

Create either a 2D Simulation<Vector2> or a 3D Simulation<Vector3> comprising:

  • PointMass2 or PointMass3 objects
  • Dimension-specific forces such as Spring2, Spring3, KeepWithinBounds2Force, and KeepWithinBounds3Force
  • Shared forces such as ColoumbForce, FlowDownwardForce, OriginAttractionForce, and ViscousForce

Periodically update the simulation with a time step.

Example

This example creates a 2D simulation. To build a 3D simulation, use Vector3, PointMass3, and Spring3 instead.

// create some point masses
var pointMass1 = new PointMass2(mass: 1.0f);
var pointMass2 = new PointMass2(mass: 2.0f);

// create a new simulation
var simulation = new Simulation<Vector2>
{
    // add the point masses
    pointMass1,
    pointMass2,

    // create a spring between these point masses
    new Spring2(pointMass1, pointMass2, length: 20),

    // point masses are attracted to one another
    new ColoumbForce(),

    // point masses move towards the origin
    new OriginAttractionForce(stiffness: 10),

    // gravity
    new FlowDownwardForce(magnitude: 100)
};

With the simulation configured, we must run it step by step in a loop. You could do this in several ways, but here are two common approaches.

Max speed

If you call Update as fast as possible, the simulation will most likely run faster than real time.

void RunAtMaxSpeed()
{
    while (true)
    {
        // update the simulation
        simulation.Update(dt: 0.01f);

        // use the resulting positions somehow
        Console.WriteLine($"PointMass1 at {pointMass1.Position}, PointMass2 at {pointMass2.Position}");
    }
}
At a fixed rate

A more controlled approach is to use FixedTimeStepUpdater. This allows you to update the simulation at one rate, and integrate the simulation's output at another rate. For example, you might run the simulation at 200Hz, and render the output at 60Hz, as shown here:

async Task RunAtFixedRateAsync(CancellationToken token)
{
    var updater = new FixedTimeStepUpdater<Vector2>(simulation, timeStepSeconds: 1f/200);

    while (!token.IsCancellationRequested)
    {
        updater.Update();

        // TODO render frame

        await Task.Delay(millisecondsDelay: 1/60, cancellationToken: token);
    }
}

For each Render call, the simulation will have multiple updates with smaller time deltas.

This example code is async, but only to support a non-blocking delay. You could make it synchronous and use Thread.Sleep if you prefer.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0 84 10/9/2026
1.1.0 1,071 10/25/2020
1.0.0-rc2 1,385 4/7/2017
1.0.0-rc1 1,312 2/3/2017
0.6.0 2,012 8/6/2016
0.5.0 1,793 7/29/2016
0.4.1 1,559 6/19/2016
0.4.0 1,540 6/19/2016
0.3.2 1,598 5/23/2016
0.3.1 1,564 5/23/2016
0.3.0 1,567 5/23/2016
0.2.0 1,546 5/21/2016
0.1.0 2,651 5/19/2015