本文整理汇总了C#中Body.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Body.Add方法的具体用法?C# Body.Add怎么用?C# Body.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body.Add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWalls
void CreateWalls(Body root, WallSettings[,] array, int width, int height, int weight, string prefix, Func<int, int, Point> cooMaker)
{
for (int x = 0; x < array.GetLength(0); x++)
for (int y = 0; y < array.GetLength(1); y++)
{
var wall = array[x, y];
if (wall == WallSettings.NoWall) continue;
Color color = Color.LightGray;
string name = prefix;
switch (wall)
{
case WallSettings.RedSocket: name += "R"; color = Color.DarkRed; break;
case WallSettings.BlueSocket: name += "B"; color = Color.DarkBlue; break;
case WallSettings.GreenSocket: name += "G"; color = Color.DarkGreen; break;
}
var coo = cooMaker(x, y);
root.Add(new Box
{
XSize = width,
YSize = height,
ZSize = weight,
Location = new Frame3D(coo.X, coo.Y, 0),
DefaultColor = color,
Type = name,
IsMaterial = true,
IsStatic = true,
});
}
}
示例2: TestSaveVisibility
public void TestSaveVisibility()
{
var root = new Body
{
Location = new Frame3D(10, 0, 0)
};
Body box = new Box
{
Location = new Frame3D(10, 20, 30)
};
root.Add(box);
var lo = new LoggingObject(box, root);
lo.SaveVisibilityState(_totalTime);
Assert.AreEqual(1, lo.VisibilityStates.Count);
Assert.AreEqual(_totalTime, lo.VisibilityStates[0].StartTime);
_totalTime ++;
lo.SaveVisibilityState(_totalTime);
Assert.AreEqual(1, lo.VisibilityStates.Count);
Assert.AreEqual(true, lo.VisibilityStates[0].IsVisible);
root.Remove(box);
_totalTime++;
lo.SaveVisibilityState(_totalTime);
Assert.AreEqual(_totalTime, lo.VisibilityStates.Last().StartTime);
Assert.AreEqual(2, lo.VisibilityStates.Count);
Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
}
示例3: Apply
public void Apply(Body loadedBody, Body world)
{
if(IsVisible)
world.Add(loadedBody);
else
world.Remove(loadedBody);
}
示例4: TreeMovingConstantLocation
public void TreeMovingConstantLocation()
{
var world = new Body();
var boxLocation = new Frame3D(10, 0, 0);
var ballLocation = new Frame3D(20, 10, 0);
var box = new Box {Location = boxLocation};
var ball = new Ball {Location = ballLocation};
world.Add(box);
world.Add(ball);
box.DetachAttachMaintaingLoction(ball);
Assert.AreEqual(boxLocation, box.Location);
Assert.AreEqual(ballLocation, ball.GetAbsoluteLocation());
Assert.AreEqual(new Frame3D(10, 10, 0), ball.Location);
world.DetachAttachMaintaingLoction(ball);
Assert.AreEqual(ballLocation, ball.Location);
Assert.AreEqual(ballLocation, ball.GetAbsoluteLocation());
}
示例5: AbsoluteLocationLinear
public void AbsoluteLocationLinear()
{
var root = new Body {Location = new Frame3D(0, 0, 10)};
Assert.AreEqual(root.Location, root.GetAbsoluteLocation());
var box = new Box {Location = new Frame3D(10, 0, 0)};
Assert.AreEqual(box.Location, box.GetAbsoluteLocation());
root.Add(box);
Assert.AreEqual(box.Location.Apply(root.Location), box.GetAbsoluteLocation());
int sum = 0;
for(int i = 0; i < 10; i++)
{
sum += i;
Body child = new Box {Location = new Frame3D(i, 0, 0)};
root.Add(child);
Assert.AreEqual(sum, child.GetAbsoluteLocation().X);
root = child;
}
}
示例6: Location
public void Location()
{
var world = new Body();
var loc = new Frame3D(10, 0, 0);
world.Add(new Box {Location = loc});
Body box = world.Nested.First();
Assert.AreEqual(loc, box.Location);
Assert.AreEqual(loc, box.GetAbsoluteLocation());
box.Add(new Ball {Location = new Frame3D(0, 0, 30)});
Body ball = box.Nested.First();
Assert.AreEqual(new Frame3D(0, 0, 30), ball.Location);
Assert.AreEqual(new Frame3D(10, 0, 30), ball.GetAbsoluteLocation());
}
示例7: CreateSolid
public ICollection<DesignBody> CreateSolid(Part mainPart)
{
var bands = new List<ICollection<Body>>();
var cutters = new List<Body[]>();
double newScale = 0.094;
double cutterHeight = 0.01 / newScale;
double cutterWidth = 0.0005 / newScale;
bool swap = false;
for (int i = 0; i < iSteps; i++) {
var band = new List<Body>();
//if (i == 4) {
// DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i][0], points[i][1]));
// DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i + iSteps / 2][jSteps / 2], points[i + iSteps / 2][jSteps / 2 + 1]));
//}
for (int j = 0; j < jSteps; j++) {
// Main ring
Point p00 = points[i][j];
Point p01 = points[i][j + 1];
Point p10 = points[i + 1][j];
Point p11 = points[i + 1][j + 1];
Body b0, b1;
if ((p00 - p11).Magnitude < (p10 - p01).Magnitude) {
b0 = ShapeHelper.CreatePolygon(new Point[] { p00, p01, p11 }, 0);
b1 = ShapeHelper.CreatePolygon(new Point[] { p00, p11, p10 }, 0);
}
else {
b0 = ShapeHelper.CreatePolygon(new Point[] { p01, p10, p00 }, 0);
b1 = ShapeHelper.CreatePolygon(new Point[] { p01, p11, p10 }, 0);
}
// Tabs
/* Male Female Male
* ---p00last-------p00--------p01-------p10next--- v+
* | | | |
* | pn0 | | pn1 |
* | | | |
* ---p10last-------p10--------p11-------p11next---
*
*/
Point pn0 = (new Point[] { points[i - 1][j], points[i - 1][j + 1] }).Average();
Point pn1 = (new Point[] { points[i + 2][j], points[i + 2][j + 1] }).Average();
Direction normal0 = Vector.Cross(p01 - pn0, p00 - pn0).Direction;
Direction normal1 = Vector.Cross(p10 - pn1, p11 - pn1).Direction;
Body tab0 = Tabs.CreateCircularTab(p01, p00, -normal0, tabAngles[i][j], swap);
Body tab1 = Tabs.CreateCircularTab(p10, p11, -normal1, tabAngles[i + 1][j], !swap);
//DesignBody annotateMe = DesignBody.Create(mainPart, "annotatme", (swap ? tab0 : tab1).Copy());
//NoteHelper.AnnotateFace(mainPart, annotateMe.Faces.First(), string.Format("{0},{1}", i, j), 0.02, null);
//annotateMe.Delete();
//DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy());
//DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy());
//DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy());
//DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy());
try {
b0.Unite(new Body[] { b1, tab0, tab1 });
}
catch {
DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy());
DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy());
DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy());
DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy());
return null;
}
// Debug.Assert(b0.Shells.Count == 1);
band.Add(b0);
swap = !swap;
}
bands.Add(band.TryUnionBodies());
// Cutters
Point p0ThisSide0 = points[i][0];
Point p0ThisSide1 = points[i][1];
Point p0OtherSide0 = points[i + iSteps / 2][jSteps / 2];
Point p0OtherSide1 = points[i + iSteps / 2][1 + jSteps / 2];
Point p1ThisSide0 = points[i + 1][0];
Point p1ThisSide1 = points[i + 1][1];
Point p1OtherSide0 = points[i + 1 + iSteps / 2][jSteps / 2];
Point p1OtherSide1 = points[i + 1 + iSteps / 2][1 + jSteps / 2];
Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).GetInBetweenPoint(
CurveSegment.Create(p0OtherSide0, p0OtherSide1
));
Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).GetInBetweenPoint(
CurveSegment.Create(p1OtherSide0, p1OtherSide1
));
//Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).IntersectCurve(
//.........这里部分代码省略.........
示例8: TestSavingVisibility2
public void TestSavingVisibility2()
{
var root = new Body
{
Location = new Frame3D(10, 0, 0)
};
Body box = new Box
{
Location = new Frame3D(10, 20, 30)
};
var lo = new LoggingObject(box, root);
for (int i = 0; i < 100; i++)
{
lo.SaveVisibilityState(i);
Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
Assert.AreEqual(0, lo.VisibilityStates.Last().StartTime);
}
//body suddenly appears.
const int updateTime = 100;
root.Add(box);
lo.SaveVisibilityState(updateTime);
Assert.AreEqual(2, lo.VisibilityStates.Count);
Assert.AreEqual(true, lo.VisibilityStates.Last().IsVisible);
Assert.AreEqual(updateTime, lo.VisibilityStates.Last().StartTime);
}
示例9: GetTreeChildForTopDownLocations
private static Body GetTreeChildForTopDownLocations(IEnumerable<Frame3D> frames)
{
var currentChild = new Body();
foreach(var frame3D in frames)
{
var newChild = new Body {Location = frame3D};
currentChild.Add(newChild);
currentChild = newChild;
}
return currentChild;
}
示例10: CreateWorld
public Body CreateWorld(ICvarcEngine engine, ISceneSettings _settings)
{
Settings = (SceneSettings)_settings;
var root = new Body();
var first = new Cylinder
{
Height = 20,
RTop = 10,
RBottom = 10,
Location = new Frame3D(-150 + 25 - 10, 100 - 25 + 10, 3),
DefaultColor = Color.DarkViolet,
IsMaterial = true,
Density = Density.Iron,
FrictionCoefficient = 0,
Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("red.png")) },
Type = "Robot"
};
var second = new Cylinder
{
Height = 20,
RTop = 10,
RBottom = 10,
Location = new Frame3D(150 - 25 + 10, 100 - 25 + 10, 3, Angle.Zero, Angle.Pi, Angle.Zero),
DefaultColor = Color.DarkViolet,
IsMaterial = true,
Density = Density.Iron,
FrictionCoefficient = 0,
Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("blue.png")) },
Type = "Robot"
};
root.Add(first);
root.Add(second);
first.Collision += body => engine.RaiseOnCollision(first.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision);
second.Collision += body => engine.RaiseOnCollision(second.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision);
root.Add(new Box
{
XSize = 300,
YSize = 200,
ZSize = 3,
DefaultColor = Color.White,
Top = new SolidColorBrush { Color = Color.Yellow },
IsStatic = true,
Type = "floor",
});
foreach (var detail in Settings.Details)
{
Color color = Color.White;
string name = "D";
switch (detail.Color)
{
case DetailColor.Red: color = Color.Red; name += "R"; break;
case DetailColor.Blue: color = Color.Blue; name += "B"; break;
case DetailColor.Green: color = Color.Green; name += "G"; break;
}
var box = new Box
{
XSize = 15,
YSize = 15,
ZSize = 15,
Location = new Frame3D(-150 + 25 + detail.Location.X * 50, 100 - 25 - 50 * detail.Location.Y, 0),
DefaultColor = color,
Type = name,
IsMaterial = true,
IsStatic = false,
FrictionCoefficient = 8
};
root.Add(box);
box.Collision += body =>
{
if (box.Parent.Id == first.Id && body.Id == second.Id)
engine.RaiseOnCollision(second.Id.ToString(), first.Id.ToString(), CollisionType.RobotCollision);
if (box.Parent.Id == second.Id && body.Id == first.Id)
engine.RaiseOnCollision(first.Id.ToString(), second.Id.ToString(), CollisionType.RobotCollision);
};
}
CreateWalls(root, Settings.HorizontalWalls, 50, 10, 15, "HW", (x, y) => new Point(-150 + 25 + x * 50, 100 - (y + 1) * 50));
CreateWalls(root, Settings.VerticalWalls, 10, 50, 14, "VW", (x, y) => new Point(-150 + (x + 1) * 50, 100 - 25 - y * 50));
CreateBorders(root);
return root;
}
示例11: CaptureDevicet
private void CaptureDevicet(Body box, Body newChild)
{
var childAbsolute = newChild.GetAbsoluteLocation();
if (newChild.Parent != null)
newChild.Parent.Remove(newChild);
newChild.Location = box.GetAbsoluteLocation().Invert().Apply(childAbsolute);
newChild.Location = newChild.Location.NewYaw(Angle.Zero);
newChild.Location = newChild.Location.NewX(14);
newChild.Location = newChild.Location.NewY(0);
frictionCoefficientsById.SafeAdd(newChild.Id, newChild.FrictionCoefficient);
newChild.FrictionCoefficient = 0;
box.Add(newChild);
}
示例12: CreateTreasure
private static void CreateTreasure(Body root)
{
root.Add(new Box
{
XSize = 8,
YSize = 8,
ZSize = 8,
Location = new Frame3D(50, 80, 3),
DefaultColor = Color.YellowGreen,
IsMaterial = true,
Type = "part",
FrictionCoefficient = 8,
Density = Density.Aluminum,
});
root.Add(new Box
{
XSize = 8,
YSize = 8,
ZSize = 8,
Location = new Frame3D(-50, 80, 3),
DefaultColor = Color.YellowGreen,
IsMaterial = true,
Type = "part",
FrictionCoefficient = 8,
Density = Density.Aluminum,
});
root.Add(new Box
{
XSize = 8,
YSize = 8,
ZSize = 8,
Location = new Frame3D(50, -80, 3),
DefaultColor = Color.Red,
IsMaterial = true,
Type = "part",
FrictionCoefficient = 8,
Density = Density.Aluminum,
});
root.Add(new Box
{
XSize = 8,
YSize = 8,
ZSize = 8,
Location = new Frame3D(-50, -80, 3),
DefaultColor = Color.Red,
IsMaterial = true,
Type = "part",
FrictionCoefficient = 8,
Density = Density.Aluminum
});
var radius = 60.0;
var rand = new Random();
for (int k = -1; k < 2; k += 2)
{
var gems = new List<Tuple<string, Color>>
{
new Tuple<string, Color>("part", Color.Red),
new Tuple<string, Color>("part", Color.YellowGreen),
null,
null,
null,
null,
};
for (int i = 0; i < 6; i++)
{
var ind = rand.Next(gems.Count);
var gem = gems[ind];
gems.RemoveAt(ind);
if (gem == null) continue;
var angleCircle = Angle.FromGrad(15 + 30 * i);
root.Add(new Box
{
XSize = 8,
YSize = 8,
ZSize = 8,
Location = new Frame3D(radius * k * Math.Sin(angleCircle.Radian), radius * Math.Cos(angleCircle.Radian), 3),
DefaultColor = gem.Item2,
IsMaterial = true,
Type = gem.Item1,
FrictionCoefficient = 8
});
}
}
}
示例13: CreateBorders
private void CreateBorders(Body root)
{
Color wallsColor = Color.FromArgb(50, 0, 0, 0);
for (int i = 0; i < 4; ++i)
{
var sizeX = i / 2 == 0 ? 303 : 3;
var sizeY = i / 2 == 1 ? 203 : 3;
var lX = i / 2 == 0 ? 203 : 3;
var lY = i / 2 == 1 ? 303 : 3;
var pos = i % 2 == 0 ? 1 : -1;
root.Add(new Box
{
XSize = sizeX,
YSize = sizeY,
ZSize = 3,
DefaultColor = wallsColor,
IsStatic = true,
Type = "wall",
IsMaterial = true,
Location = new Frame3D(
pos * lY / 2,
pos * lX / 2,
3)
});
}
}