本文整理汇总了C#中Box类的典型用法代码示例。如果您正苦于以下问题:C# Box类的具体用法?C# Box怎么用?C# Box使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Box类属于命名空间,在下文中一共展示了Box类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Adding_item_with_negative_quanity_throws_error
public void Adding_item_with_negative_quanity_throws_error()
{
var box = new Box();
var item = new Item { Name = "Test Item" };
Assert.Throws<InvalidOperationException>(() => box.AddItem(-3, item));
}
示例2: WallDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public WallDemo(DemosGame game)
: base(game)
{
int width = 10;
int height = 10;
float blockWidth = 2f;
float blockHeight = 1f;
float blockLength = 1f;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
var toAdd =
new Box(
new Vector3(
i * blockWidth + .5f * blockWidth * (j % 2) - width * blockWidth * .5f,
blockHeight * .5f + j * (blockHeight),
0),
blockWidth, blockHeight, blockLength, 10);
Space.Add(toAdd);
}
}
Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50);
Space.Add(ground);
game.Camera.Position = new Vector3(0, 6, 15);
}
示例3: CollisionFilteringDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public CollisionFilteringDemo(DemosGame game)
: base(game)
{
Entity toAdd;
toAdd = new Box(new Vector3(0, -.5f, 0), 50, 1, 50);
Space.Add(toAdd);
//Set up two stacks which go through each other
var firstStackGroup = new CollisionGroup();
var secondStackGroup = new CollisionGroup();
//Adding this rule to the space's collision group rules will prevent entities belong to these two groups from generating collision pairs with each other.
groupPair = new CollisionGroupPair(firstStackGroup, secondStackGroup);
CollisionRules.CollisionGroupRules.Add(groupPair, CollisionRule.NoBroadPhase);
for (int k = 0; k < 10; k++)
{
toAdd = new Box(
new Vector3(-4 + .12f * k, .5f + k, 0), 1f, 1f, 1f,
10);
toAdd.CollisionInformation.CollisionRules.Group = firstStackGroup;
Space.Add(toAdd);
toAdd = new Box(new Vector3(4 - .12f * k, .5f + k, 0),
1f, 1f, 1f, 10);
toAdd.CollisionInformation.CollisionRules.Group = secondStackGroup;
Space.Add(toAdd);
}
//Add another two boxes which ignore each other using the specific entities method; they will still collide with the stacks since they will have the default dynamic collision group.
toAdd = new Box(new Vector3(1, 3, 0), 1f, 4f, 2f, 10);
var toAdd2 = new Box(new Vector3(-1, 3, 0), 1f, 4f, 2f, 15);
CollisionRules.AddRule(toAdd, toAdd2, CollisionRule.NoBroadPhase);
Space.Add(toAdd);
Space.Add(toAdd2);
game.Camera.Position = new Vector3(0, 6, 20);
}
示例4: ultraChart1_FillSceneGraph
void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e)
{
IAdvanceAxis xaxis = e.Grid["X"] as IAdvanceAxis;
IAdvanceAxis yaxis = e.Grid["Y"] as IAdvanceAxis;
if (xaxis == null)
{
return;
}
int xloc1 = (int)xaxis.MapMinimum;
int xloc2 = (int)xaxis.MapMaximum;
int yloc = (int)yaxis.Map(6);
Box b = new Box(new Point(xloc1, yloc - 2), xloc2 - xloc1, 5, new LineStyle(LineCapStyle.NoAnchor, LineCapStyle.NoAnchor, LineDrawStyle.Solid));
b.PE.Fill = Color.LightGreen;
b.Value = 6d; // has to be a double for the value
b.Caps = PCaps.HitTest | PCaps.Skin | PCaps.Tooltip;
b.Chart = e.ChartCore.ChartType;
b.Layer = e.ChartCore.GetChartLayer();
b.Row = b.Column = -1; // have to set these to -1
e.SceneGraph.Add(b);
}
示例5: DockItemContainer
public DockItemContainer (DockFrame frame, DockItem item)
{
this.item = item;
mainBox = new VBox ();
Add (mainBox);
mainBox.ResizeMode = Gtk.ResizeMode.Queue;
mainBox.Spacing = 0;
ShowAll ();
mainBox.PackStart (item.GetToolbar (PositionType.Top).Container, false, false, 0);
HBox hbox = new HBox ();
hbox.Show ();
hbox.PackStart (item.GetToolbar (PositionType.Left).Container, false, false, 0);
contentBox = new HBox ();
contentBox.Show ();
hbox.PackStart (contentBox, true, true, 0);
hbox.PackStart (item.GetToolbar (PositionType.Right).Container, false, false, 0);
mainBox.PackStart (hbox, true, true, 0);
mainBox.PackStart (item.GetToolbar (PositionType.Bottom).Container, false, false, 0);
}
示例6: BroadPhaseDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public BroadPhaseDemo(DemosGame game)
: base(game)
{
//Make a fatter kapow sphere.
Space.Remove(kapow);
kapow = new Sphere(new Vector3(11000, 0, 0), 1.5f, 1000);
Space.Add(kapow);
Space.Solver.IterationLimit = 1; //Essentially no sustained contacts, so don't need to worry about accuracy.
Space.ForceUpdater.Gravity = Vector3.Zero;
int numColumns = 15;
int numRows = 15;
int numHigh = 15;
float separation = 3;
Entity toAdd;
for (int i = 0; i < numRows; i++)
for (int j = 0; j < numColumns; j++)
for (int k = 0; k < numHigh; k++)
{
toAdd = new Box(new Vector3(separation * i, k * separation, separation * j), 1, 1, 1, 1);
toAdd.Material.Bounciness = 1; //Superbouncy boxes help propagate shock waves.
toAdd.LinearDamping = 0f;
toAdd.AngularDamping = 0f;
Space.Add(toAdd);
}
game.Camera.Position = new Vector3(0, 3, -10);
game.Camera.ViewDirection = new Vector3(0, 0, 1);
}
示例7: ColosseumDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public ColosseumDemo(DemosGame game)
: base(game)
{
double angle;
int numBoxesPerRing = 12;
float blockWidth = 2;
float blockHeight = 2;
float blockLength = 6f;
float radius = 15;
Entity toAdd;
Space.Add(new Box(new Vector3(0, -blockHeight / 2 - 1, 0), 100, 2f, 100));
double increment = MathHelper.TwoPi / numBoxesPerRing;
for (int i = 0; i < 8; i++)
{
for (int k = 0; k < numBoxesPerRing; k++)
{
if (i % 2 == 0)
{
angle = k * increment;
toAdd = new Box(new Vector3(-(float) Math.Cos(angle) * radius, i * blockHeight, (float) Math.Sin(angle) * radius), blockWidth, blockHeight, blockLength, 20);
toAdd.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float) angle);
Space.Add(toAdd);
}
else
{
angle = (k + .5f) * increment;
toAdd = new Box(new Vector3(-(float)Math.Cos(angle) * radius, i * blockHeight, (float)Math.Sin(angle) * radius), blockWidth, blockHeight, blockLength, 20);
toAdd.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float) angle);
Space.Add(toAdd);
}
}
}
game.Camera.Position = new Vector3(0, 2, 2);
}
示例8: 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);
}
示例9: CompoundBox
public CompoundBox(Box b1, Box b2, Box b3)
{
boxes = new List<Box>();
boxes.Add(b1);
boxes.Add(b2);
boxes.Add(b3);
}
示例10: Run
public static void Run()
{
// Initialize scene object
Scene scene = new Scene();
// Initialize Node class object
Node cubeNode = new Node("box");
// ExStart:ConvertBoxPrimitivetoMesh
// Initialize object by Box class
IMeshConvertible convertible = new Box();
// Convert a Box to Mesh
Mesh mesh = convertible.ToMesh();
// ExEnd:ConvertBoxPrimitivetoMesh
// Point node to the Mesh geometry
cubeNode.Entity = mesh;
// Add Node to a scene
scene.RootNode.ChildNodes.Add(cubeNode);
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("BoxToMeshScene.fbx");
// Save 3D scene in the supported file formats
scene.Save(MyDir, FileFormat.FBX7400ASCII);
Console.WriteLine("\n Converted the primitive Box to a mesh successfully.\nFile saved at " + MyDir);
}
示例11: TestConstruction
public void TestConstruction()
{
var box1 = new Box(new Point(1, 2), new Point(5, 4));
Assert.AreEqual(box1.Height, 2);
Assert.AreEqual(box1.Width, 4);
var box2 = new Box(new Point(1, 2), 5, 6);
Assert.AreEqual(box2.Height, 6);
Assert.AreEqual(box2.Width, 5);
var box3 = new Box(0, 2, 3, 1);
Assert.AreEqual(box3.BottomLeft, new Point(0, 1));
Assert.AreEqual(box3.BottomRight, new Point(3, 1));
Assert.AreEqual(box3.TopLeft, new Point(0, 2));
Assert.AreEqual(box3.TopRight, new Point(3, 2));
Assert.AreEqual(box3.Center, new Point(1.5, 1.5));
if (!box3.Points.SequenceEqual(new[]
{
box3.TopLeft,
box3.TopRight,
box3.BottomRight,
box3.BottomLeft
}))
Assert.Fail();
}
示例12: DockItemToolbar
internal DockItemToolbar (DockItem parentItem, PositionType position)
{
this.parentItem = parentItem;
frame = new CustomFrame ();
switch (position) {
case PositionType.Top:
frame.SetMargins (0, 0, 1, 1);
frame.SetPadding (0, 2, 2, 0);
break;
case PositionType.Bottom:
frame.SetMargins (0, 1, 1, 1);
frame.SetPadding (2, 2, 2, 0);
break;
case PositionType.Left:
frame.SetMargins (0, 1, 1, 0);
frame.SetPadding (0, 0, 2, 2);
break;
case PositionType.Right:
frame.SetMargins (0, 1, 0, 1);
frame.SetPadding (0, 0, 2, 2);
break;
}
this.position = position;
if (position == PositionType.Top || position == PositionType.Bottom)
box = new HBox (false, 3);
else
box = new VBox (false, 3);
box.Show ();
frame.Add (box);
frame.GradientBackround = true;
}
示例13: StackDemo
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public StackDemo(DemosGame game)
: base(game)
{
kapow.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;
int height = 50;
float blockWidth = 3f;
float blockHeight = 1f;
float blockLength = 3f;
for (int i = 0; i < height; i++)
{
var toAdd =
new Box(
new Vector3(
0,
blockHeight * .5f + i * (blockHeight),
0),
blockWidth, blockHeight, blockLength, 10);
Space.Add(toAdd);
}
Box ground = new Box(new Vector3(0, -.5f, 0), 50, 1, 50);
Space.Add(ground);
game.Camera.Position = new Vector3(0, 6, 15);
}
示例14: Adding_new_item_to_box_should_have_correct_quantity
public void Adding_new_item_to_box_should_have_correct_quantity()
{
var box = new Box();
box.AddItem(3, new Item { Name = "Test Item" });
Assert.Equal(3, box.Contents.First().Quantity);
}
示例15: CreateLevel2Box
/**
* Create a level two box, ie two boxes next to each other
*/
private void CreateLevel2Box(Box from, Box to, string direction)
{
// send rpc to master client to destroy the box
to.GetComponent<PhotonView>().RPC("Explode", PhotonTargets.MasterClient, null);
// set the build level to 2
from.GetComponent<PhotonView>().RPC("BuildLevel", PhotonTargets.All, 2);
if (direction == "sideways") {
// ie left to right
// increase the scale of the box
from.transform.localScale += new Vector3(1f, 0f, 0f);
// reposition the box
from.transform.position += new Vector3(0.5f, 0f, 0f);
} else {
// front to back
// increase the scale of the box
from.transform.localScale += new Vector3(0f, 0f, 1f);
// reposition the box
from.transform.position += new Vector3(0.0f, 0f, 0.5f);
}
}