Added Box2D

This commit is contained in:
Julian Nießner
2018-05-06 12:43:20 +02:00
parent cb5469bb89
commit d175d433a8
351 changed files with 123545 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using Box2D.Net;
namespace TestBed.Net.Tests
{
public class Bridge : TestBed.Net.Test
{
public Bridge()
{
Body ground;
{
PolygonDef sd = new PolygonDef();
sd.ShapeType = ShapeType.e_polygonShape;
sd.SetAsBox(50.0f, 10.0f);
BodyDef bd = new BodyDef();
bd.Position = new Vector(0, -10);
ground = world.CreateBody(bd);
ground.CreateShape(sd);
}
{
PolygonDef sd = new PolygonDef();
sd.SetAsBox(0.5f, 0.125f);
sd.Density = 20.0f;
sd.Friction = 0.2f;
BodyDef bd = new BodyDef();
bd.BodyType = BodyType.e_dynamicBody;
RevoluteJointDef jd = new RevoluteJointDef();
const float numPlanks = 30;
Body prevBody = ground;
for (float i = 0; i < numPlanks; ++i)
{
bd.Position = new Vector(-14.5f + i, 5);
Body body = world.CreateBody(bd);
body.CreateShape(sd);
body.SetMassFromShapes();
Vector anchor = new Vector(-15 + i, 5);
jd.Initialize(prevBody, body, anchor);
world.CreateJoint(jd);
prevBody = body;
}
Vector anchor2 = new Vector(-15 + numPlanks, 5);
jd.Initialize(prevBody, ground, anchor2);
world.CreateJoint(jd);
}
}
}
}