public Body Construct()
{
if (World == null)
throw new BodyConstructorException("Cannot construct body with no World object supplied.");
var body = new Body(World, Position, Rotation.HasValue ? Rotation.Value : 0);
if (BodyType.HasValue)
body.BodyType = BodyType.Value;
if (IslandIndex.HasValue)
body.IslandIndex = IslandIndex.Value;
if (GravityScale.HasValue)
body.GravityScale = GravityScale.Value;
if (InitialLinearVelocity.HasValue)
body.LinearVelocity = InitialLinearVelocity.Value;
if (InitialAngularVelocity.HasValue)
body.AngularVelocity = InitialAngularVelocity.Value;
if (LinearDamping.HasValue)
body.LinearDamping = LinearDamping.Value;
if (AngularDamping.HasValue)
body.AngularDamping = AngularDamping.Value;
if (IsBullet.HasValue)
body.IsBullet = IsBullet.Value;
if (SleepingAllowed.HasValue)
body.SleepingAllowed = SleepingAllowed.Value;
if (InitiallyAwake.HasValue)
body.Awake = InitiallyAwake.Value;
if (InitiallyEnabled.HasValue)
body.Enabled = InitiallyEnabled.Value;
if (FixedRotation.HasValue)
body.FixedRotation = FixedRotation.Value;
if (IgnoreCCD.HasValue)
body.IgnoreCCD = IgnoreCCD.Value;
if (IgnoreGravity.HasValue)
body.IgnoreGravity = IgnoreGravity.Value;
if (LocalCenter.HasValue)
body.LocalCenter = LocalCenter.Value;
if (Mass.HasValue)
body.Mass = Mass.Value;
if (Inertia.HasValue)
body.Inertia = Inertia.Value;
if (fixtureBuilderData.Count > 0)
{
Shape defaultShape = null;
if (Shapes.Count > 0)
{
defaultShape = Shapes[0];
}
foreach (var kvp in fixtureBuilderData)
{
var fixtureData = kvp.Value;
Fixture fixture;
if (fixtureData.Shape == null)
{
if (defaultShape == null)
throw new BodyConstructorException(
String.Format(
"FixtureData with name '{0}' has no associated Shape. Either set " +
"a default shape using WithShape(Shape), or add a shape specifically " +
"to this Fixture using WithShape(\"{0}\", Shape).", kvp.Key));
}
fixture = body.CreateFixture(fixtureData.Shape);
SetFixtureData(fixture, fixtureData);
}
}
else
{
foreach (var shape in Shapes)
{
var fixture = body.CreateFixture(shape);
SetFixtureData(fixture, anonymousFixtureData);
}
}
return body;
}