本文整理汇总了C#中BoundingBox.GetCorners方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBox.GetCorners方法的具体用法?C# BoundingBox.GetCorners怎么用?C# BoundingBox.GetCorners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBox
的用法示例。
在下文中一共展示了BoundingBox.GetCorners方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Contains
public ContainmentType Contains(ref BoundingBox box)
{
var result = ContainmentType.Contains;
box.GetCorners(BoxCorners);
// ReSharper disable TooWideLocalVariableScope
int k, nIn, nOut;
float distance;
for(var i = 0; i < 6; ++i)
{
nIn = 0;
nOut = 0;
for(k = 0; k < 8 && (nIn == 0 || nOut == 0); ++k)
{
Plane.DotCoordinate(ref mPlanes[i], ref BoxCorners[k], out distance);
if (distance < 0)
++nOut;
else
++nIn;
}
if (nIn == 0)
return ContainmentType.Disjoint;
if (nOut != 0)
result = ContainmentType.Intersects;
}
return result;
}
示例2: DrawBoundingBox
public void DrawBoundingBox(BoundingBox box, DMatrix transform)
{
var corners = box.GetCorners();
var worldCorners = corners.Select(x => DVector3.TransformCoordinate(new DVector3(x.X, x.Y, x.Z), transform)).ToArray();
//foreach (var corner in worldCorners)
//{
// DrawPoint(corner, 0.1f);
//}
DrawLine(worldCorners[0], worldCorners[1], Color.Green);
DrawLine(worldCorners[0], worldCorners[4], Color.Green);
DrawLine(worldCorners[0], worldCorners[3], Color.Green);
DrawLine(worldCorners[7], worldCorners[6], Color.Red);
DrawLine(worldCorners[7], worldCorners[3], Color.Red);
DrawLine(worldCorners[7], worldCorners[4], Color.Red);
DrawLine(worldCorners[5], worldCorners[1], Color.Yellow);
DrawLine(worldCorners[5], worldCorners[4], Color.Yellow);
DrawLine(worldCorners[5], worldCorners[6], Color.Yellow);
DrawLine(worldCorners[2], worldCorners[1], Color.WhiteSmoke);
DrawLine(worldCorners[2], worldCorners[3], Color.WhiteSmoke);
DrawLine(worldCorners[2], worldCorners[6], Color.WhiteSmoke);
}
示例3: TransformBoundingBox
public static BoundingBox TransformBoundingBox(BoundingBox boundary, Matrix transformation)
{
var corners = boundary.GetCorners();
for (int i = 0; i < 8; ++i)
{
var transformed = Vector3.Transform(corners[i], transformation);
corners[i] = new Vector3(transformed.X, transformed.Y, transformed.Z);
}
return BoundingBox.FromPoints(corners);
}
示例4: UpdateAABB
public override void UpdateAABB()
{
Matrix matrix = GetGlobalTransformation();
m_AABB = m_AABB.CreateInvalid();
BoundingBox box = new BoundingBox(-m_extent, m_extent);
box.GetCorners(m_points);
Vector3 point2;
Vector3 point1;
foreach (Vector3 point in m_points)
{
point1 = point;
Vector3.Transform(ref point1, ref matrix, out point2);
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB, point2);
}
base.UpdateAABB();
}
示例5: Intersects
public bool Intersects(BoundingBox box)
{
bool result = true;
int outP = 0;
int inS = 0;
Vector3[] Corners = box.GetCorners();
Plane[] Planes = new Plane[]
{
near,
far,
top,
bottom,
left,
right
};
// for each plane do ...
for(int i = 0; i < 6; i++)
{
// reset counters for corners in and out
outP = 0;
inS = 0;
// for each corner of the box do ...
// get out of the cycle as soon as a box as corners
// both inside and out of the frustum
for (int k = 0; k < 8 && (inS == 0 || outP == 0); k++)
{
// is the corner outside or inside
if (Plane.DotCoordinate(Planes[i], Corners[k]) < 0)
outP++;
else
inS++;
}
//if all corners are out
if (inS == 0)
return (false);
// if some corners are out and others are in
else if (outP > 0)
result = true;
}
return(result);
}
示例6: DrawBox
public void DrawBox(BoundingBox bbox, Color color)
{
var crnrs = bbox.GetCorners();
var p = bbox.Maximum;
var n = bbox.Minimum;
DrawLine(new Vector3(p.X, p.Y, p.Z), new Vector3(n.X, p.Y, p.Z), color);
DrawLine(new Vector3(n.X, p.Y, p.Z), new Vector3(n.X, p.Y, n.Z), color);
DrawLine(new Vector3(n.X, p.Y, n.Z), new Vector3(p.X, p.Y, n.Z), color);
DrawLine(new Vector3(p.X, p.Y, n.Z), new Vector3(p.X, p.Y, p.Z), color);
DrawLine(new Vector3(p.X, n.Y, p.Z), new Vector3(n.X, n.Y, p.Z), color);
DrawLine(new Vector3(n.X, n.Y, p.Z), new Vector3(n.X, n.Y, n.Z), color);
DrawLine(new Vector3(n.X, n.Y, n.Z), new Vector3(p.X, n.Y, n.Z), color);
DrawLine(new Vector3(p.X, n.Y, n.Z), new Vector3(p.X, n.Y, p.Z), color);
DrawLine(new Vector3(p.X, p.Y, p.Z), new Vector3(p.X, n.Y, p.Z), color);
DrawLine(new Vector3(n.X, p.Y, p.Z), new Vector3(n.X, n.Y, p.Z), color);
DrawLine(new Vector3(n.X, p.Y, n.Z), new Vector3(n.X, n.Y, n.Z), color);
DrawLine(new Vector3(p.X, p.Y, n.Z), new Vector3(p.X, n.Y, n.Z), color);
}
示例7: Render
/// <summary>
/// Renders the bounding box for debugging purposes.
/// </summary>
/// <param name="box">The box to render.</param>
/// <param name="graphicsDevice">The graphics device to use when rendering.</param>
/// <param name="view">The current view matrix.</param>
/// <param name="projection">The current projection matrix.</param>
/// <param name="color">The color to use for drawing the lines of the box.</param>
public static void Render(
BoundingBox box,
Device graphicsDevice,
Matrix world,
Matrix view,
Matrix projection,
Color4 color)
{
if (effect == null)
{
effect = Ressources.EffectCache.Get("Shaders\\basic_effect.fx");
vertexBuffer = new Buffer(Scene.GetGraphicsDevice(), 8 * sizeof(float) * 4, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
/*
*
vBuffer = new SlimDX.Direct3D11.Buffer(Scene.GetGraphicsDevice(), vBuffStream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = (int)vBuffStream.Length,
Usage = ResourceUsage.Default
});*/
DataStream stream = new DataStream(sizeof(int) * indices.Length, false, true);
stream.WriteRange<int>(indices);
stream.Position = 0;
indexBuffer = new SlimDX.Direct3D11.Buffer(Scene.GetGraphicsDevice(), stream, new BufferDescription()
{
BindFlags = BindFlags.IndexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = (int)stream.Length,
Usage = ResourceUsage.Default
});
stream.Dispose();
var sign = effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature;
inLayout = new InputLayout(
Scene.GetGraphicsDevice(),
effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature,
new InputElement[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0)
});
}
effect.GetVariableByName("xColor").AsVector().Set(color);
Vector3[] corners = box.GetCorners();
for (int i = 0; i < 8; i++)
{
verts[i] = new Vector4(corners[i], 1.0f);
}
var data = Scene.GetGraphicsDevice().ImmediateContext.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);
data.Data.WriteRange(verts);
Scene.GetGraphicsDevice().ImmediateContext.UnmapSubresource(vertexBuffer, 0);
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.InputLayout = inLayout;
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0);
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.PrimitiveTopology = (PrimitiveTopology.LineList);
effect.GetVariableByName("World").AsMatrix().SetMatrix(world);
effect.GetVariableByName("View").AsMatrix().SetMatrix(view);
effect.GetVariableByName("Projection").AsMatrix().SetMatrix(projection);
for (int i = 0; i < effect.GetTechniqueByIndex(0).Description.PassCount; i++)
{
effect.GetTechniqueByIndex(0).GetPassByIndex(i).Apply(Scene.GetGraphicsDevice().ImmediateContext);
Scene.GetGraphicsDevice().ImmediateContext.DrawIndexed(indexBuffer.Description.SizeInBytes / sizeof(int), 0, 0);
}
}
示例8: ExtendThroughBox
/// <summary>
/// Utility function for creating a PlaneSurface through a Box.
/// </summary>
/// <param name="plane">Plane to extend.</param>
/// <param name="box">Box to extend through.</param>
/// <param name="fuzzyness">Box will be inflated by this amount.</param>
/// <returns>A Plane surface through the box or null.</returns>
internal static PlaneSurface ExtendThroughBox(Plane plane, BoundingBox box, double fuzzyness)
{
if (fuzzyness != 0.0) { box.Inflate(fuzzyness); }
Point3d[] corners = box.GetCorners();
int side = 0;
bool valid = false;
for (int i = 0; i < corners.Length; i++)
{
double d = plane.DistanceTo(corners[i]);
if (d == 0.0) { continue; }
if (d < 0.0)
{
if (side > 0) { valid = true; break; }
side = -1;
}
else
{
if (side < 0) { valid = true; break; }
side = +1;
}
}
if (!valid) { return null; }
Interval s, t;
if (!plane.ExtendThroughBox(box, out s, out t)) { return null; }
if (s.IsSingleton || t.IsSingleton)
return null;
return new PlaneSurface(plane, s, t);
}
示例9: Contains
public ContainmentType Contains(BoundingBox boundingBox, Matrix worldMatrix)
{
if (PassAllTests)
return ContainmentType.Contains;
var bboxcl = boundingBox.GetCorners().ToList();
for (int i = 0; i < bboxcl.Count; ++i)
bboxcl[i] = Vector3.TransformCoordinate(bboxcl[i], worldMatrix);
Vector3 newMin = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
Vector3 newMax = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);
for (int i = 0; i < bboxcl.Count; ++i)
{
if (bboxcl[i].X < newMin.X)
newMin.X = bboxcl[i].X;
if (bboxcl[i].X > newMax.X)
newMax.X = bboxcl[i].X;
if (bboxcl[i].Y < newMin.Y)
newMin.Y = bboxcl[i].Y;
if (bboxcl[i].Y > newMax.Y)
newMax.Y = bboxcl[i].Y;
if (bboxcl[i].Z < newMin.Z)
newMin.Z = bboxcl[i].Z;
if (bboxcl[i].Z > newMax.Z)
newMax.Z = bboxcl[i].Z;
}
boundingBox = new BoundingBox(newMin, newMax);
bool flag = false;
foreach (Plane plane in planes)
{
switch (Plane.Intersects(plane, boundingBox))
{
case PlaneIntersectionType.Front:
return ContainmentType.Disjoint;
case PlaneIntersectionType.Intersecting:
flag = true;
break;
}
}
if (!flag) return ContainmentType.Contains;
return ContainmentType.Intersects;
}
示例10: BoundingBoxMultiplyMatrix
public static BoundingBox BoundingBoxMultiplyMatrix(BoundingBox bb, Matrix m)
{
Vector3 []corners = bb.GetCorners();
for (int i = 0; i < corners.Length; i++)
{
corners[i] = Vector3.TransformCoordinate(corners[i], m);
}
return BoundingBox.FromPoints(corners);
}
示例11: UpdateSelectionBox
public void UpdateSelectionBox(BoundingBox box, Matrix transform)
{
mTransform = transform;
mBox = box;
var corners = mBox.GetCorners();
for (int i = 0; i < 8; ++i)
mPlaneVertices[i].Position = corners[i];
Video.ShaderCollection.BoxShader.SetValue("matrixWorld", transform);
mDrawBox = true;
}
示例12: DoesBoxOverlap
public bool DoesBoxOverlap(BoundingBox box)
{
/// We are using separating axis theorem
/// We have to test 4 planes from tetrahedron, 3 planes from BB (trivial) and 6 * 3 planes from cross product of edges
///
/// First early out on box planes - trivial world space bounding box
///
if (!BoundingBox.Intersects(m_BoundingBox, box))
return false;
Vector3[] corners = box.GetCorners();
Vector4 baryCentricBoundsMin = new Vector4(float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue);
Vector4 baryCentricBoundsMax = new Vector4(float.MinValue, float.MinValue, float.MinValue, float.MinValue);
/// Second check tetrahedron planes, easy due to barycentric matrices
foreach (var vert in corners)
{
float b0, b1, b2, b3;
CalculateBarycentricCoordinates(vert, out b0, out b1, out b2, out b3);
baryCentricBoundsMin = Vector4.Minimize(baryCentricBoundsMin, new Vector4(b0, b1, b2, b3));
baryCentricBoundsMax = Vector4.Maximize(baryCentricBoundsMax, new Vector4(b0, b1, b2, b3));
}
if (baryCentricBoundsMin.X > 1.0f || baryCentricBoundsMin.Y > 1.0f || baryCentricBoundsMin.Z > 1.0f || baryCentricBoundsMin.W > 1.0f)
return false;
if (baryCentricBoundsMax.X < 0.0f || baryCentricBoundsMax.Y < 0.0f || baryCentricBoundsMax.Z < 0.0f || baryCentricBoundsMax.W < 0.0f)
return false;
// Finally, more difficult part - planes between the edges of both
Vector3[] boxVectors = { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) };
Vector3[] tetEdgeVectors = new Vector3[6];
// Note: not necessary to normalize, we are interested in axis limits overlap
// And those vectors cannot be 0 (degenerated tetrahedron)
tetEdgeVectors[0] = m_Vertices[1] - m_Vertices[0];
tetEdgeVectors[1] = m_Vertices[2] - m_Vertices[0];
tetEdgeVectors[2] = m_Vertices[3] - m_Vertices[0];
tetEdgeVectors[3] = m_Vertices[2] - m_Vertices[1];
tetEdgeVectors[4] = m_Vertices[3] - m_Vertices[2];
tetEdgeVectors[5] = m_Vertices[1] - m_Vertices[3];
foreach (var tetEdge in tetEdgeVectors)
{
foreach (var boxEdge in boxVectors)
{
// Normal of plane constructed by those 2 edges
var planeNormal = Vector3.Cross(tetEdge, boxEdge);
if (planeNormal.LengthSquared() > 0.0001f)
{
Vector2 tetLimits = GeometricsAlgorithms.GetAxisProjectionLimits(m_Vertices, planeNormal);
Vector2 boxLimits = GeometricsAlgorithms.GetAxisProjectionLimits(corners, planeNormal);
if (tetLimits.X > boxLimits.Y || tetLimits.Y < boxLimits.X)
{
return false;
}
}
}
}
return true;
}
示例13: printCorners
private string printCorners(BoundingBox bb)
{
Vector3[] corners = bb.GetCorners();
return printCorners(corners);
}
示例14: UpdateAABB
public override void UpdateAABB()
{
Matrix matrix = GetGlobalTransformation();
m_AABB = m_AABB.CreateInvalid();
BoundingBox box = new BoundingBox(-m_Size, m_Size);
box.GetCorners(m_points);
Vector3 point2;
Vector3 point1;
foreach (Vector3 point in m_points)
{
point1 = point;
Vector3.Transform(ref point1, ref matrix, out point2);
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB, point2);
}
/*
Vector3 origin = matrix.Translation;
m_AABB.Min = origin;
m_AABB.Max = origin;
Vector3 rotSize = Vector3.TransformNormal(m_Size, GetGlobalTransformation());
m_Extent.X = rotSize.X;
m_Extent.Y = rotSize.Y;
m_Extent.Z = rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB, origin + m_Extent);
m_Extent.X = -rotSize.X;
m_Extent.Y = rotSize.Y;
m_Extent.Z = rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB, origin+m_Extent);
m_Extent.X = -rotSize.X;
m_Extent.Y = -rotSize.Y;
m_Extent.Z = rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB, origin+m_Extent);
m_Extent.X = -rotSize.X;
m_Extent.Y = -rotSize.Y;
m_Extent.Z = -rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB, origin+m_Extent);
m_Extent.X = rotSize.X;
m_Extent.Y = -rotSize.Y;
m_Extent.Z = rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB,origin+ m_Extent);
m_Extent.X = rotSize.X;
m_Extent.Y = -rotSize.Y;
m_Extent.Z = -rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB,origin+ m_Extent);
m_Extent.X = rotSize.X;
m_Extent.Y = rotSize.Y;
m_Extent.Z = -rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB,origin+ m_Extent);
m_Extent.X = -rotSize.X;
m_Extent.Y = rotSize.Y;
m_Extent.Z = -rotSize.Z;
MyPhysicsUtils.BoundingBoxAddPoint(ref m_AABB,origin+ m_Extent);
*/
base.UpdateAABB();
}
示例15: CreateConstructionSmokes
private void CreateConstructionSmokes()
{
Vector3 halfSize = new Vector3(CubeGrid.GridSize) / 2;
BoundingBox blockBox = new BoundingBox(Min * CubeGrid.GridSize - halfSize, Max * CubeGrid.GridSize + halfSize);
if (FatBlock != null)
{
BoundingBox fatBlockBoxLocal = new BoundingBox(FatBlock.Model.BoundingBox.Min, FatBlock.Model.BoundingBox.Max);
Matrix m;
FatBlock.Orientation.GetMatrix(out m);
BoundingBox fatBlockBoxOriented = BoundingBox.CreateInvalid();
foreach (var corner in fatBlockBoxLocal.GetCorners())
{
fatBlockBoxOriented = fatBlockBoxOriented.Include(Vector3.Transform(corner, m));
}
blockBox = new BoundingBox(fatBlockBoxOriented.Min + blockBox.Center, fatBlockBoxOriented.Max + blockBox.Center);
}
blockBox.Inflate(-0.3f);
Vector3[] corners = blockBox.GetCorners();
float particleStep = 0.25f;
for (int e = 0; e < MyOrientedBoundingBox.StartVertices.Length; e++)
{
Vector3 offset = corners[MyOrientedBoundingBox.StartVertices[e]];
float offsetLength = 0;
float length = Vector3.Distance(offset, corners[MyOrientedBoundingBox.EndVertices[e]]);
Vector3 offsetStep = particleStep * Vector3.Normalize(corners[MyOrientedBoundingBox.EndVertices[e]] - corners[MyOrientedBoundingBox.StartVertices[e]]);
while (offsetLength < length)
{
Vector3D tr = Vector3D.Transform(offset, CubeGrid.WorldMatrix);
MyParticleEffect smokeEffect;
if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out smokeEffect))
{
smokeEffect.AutoDelete = true;
smokeEffect.WorldMatrix = MatrixD.CreateTranslation(tr);
smokeEffect.UserScale = 0.7f;
}
offsetLength += particleStep;
offset += offsetStep;
}
}
}