-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a61a227
commit b5af1b7
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Example>Example</Example> | ||
<StartupObject>$(Example)</StartupObject> | ||
</PropertyGroup> | ||
|
||
<Import Project="../Box2D.NET.Native/Box2D.NET.Native.targets"/> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../Box2D.NET/Box2D.NET.csproj"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Box2D.NET.Bindings; | ||
|
||
public static unsafe class HelloWorld | ||
{ | ||
public static void Main() | ||
{ | ||
// Create a world | ||
B2.WorldDef worldDef = B2.DefaultWorldDef; | ||
worldDef.gravity = new B2.Vec2 { x = 0, y = -9.81f }; | ||
|
||
B2.WorldId worldId = B2.CreateWorld(&worldDef); | ||
|
||
// Create a body | ||
B2.BodyDef bodyDef = B2.DefaultBodyDef; | ||
bodyDef.type = B2.dynamicBody; | ||
|
||
B2.BodyId bodyId = B2.CreateBody(worldId, &bodyDef); | ||
|
||
// Create a shape | ||
B2.Polygon box = B2.MakeBox(1, 1); | ||
B2.ShapeDef shapeDef = B2.DefaultShapeDef; | ||
shapeDef.friction = 0.6f; | ||
shapeDef.density = 1.0f; | ||
|
||
B2.ShapeId shapeId = B2.CreatePolygonShape(bodyId, &shapeDef, &box); | ||
|
||
// Run the simulation | ||
const float timeStep = 1.0f / 60.0f; | ||
const int velocityIterations = 6; | ||
const int positionIterations = 2; | ||
|
||
for (int i = 0; i < 60; i++) | ||
{ | ||
B2.WorldStep(worldId, timeStep, velocityIterations, positionIterations); | ||
B2.Vec2 position = B2.BodyGetPosition(bodyId); | ||
float angle = B2.BodyGetAngle(bodyId); | ||
|
||
Console.WriteLine($"Position: ({position.x}, {position.y})"); | ||
Console.WriteLine($"Angle: {angle}"); | ||
Console.WriteLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public static class Example | ||
{ | ||
public static void Main() | ||
{ | ||
Console.WriteLine("To run an example, use the following command and provide the full class name of your desired example"); | ||
Console.WriteLine("Example: \"dotnet run --project Box2D.NET.Examples --property:Example=HelloWorld\""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters