本文整理汇总了C#中BoundingBox.Include方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBox.Include方法的具体用法?C# BoundingBox.Include怎么用?C# BoundingBox.Include使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBox
的用法示例。
在下文中一共展示了BoundingBox.Include方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitLazy
public void InitLazy(MyObjectBuilder_DefinitionBase baseBuilder)
{
var builder = baseBuilder as MyObjectBuilder_PrefabDefinition;
Debug.Assert(builder.CubeGrid != null || builder.CubeGrids != null, "No cube grids defined in prefab " + PrefabPath);
if (builder.CubeGrid == null && builder.CubeGrids == null) return;
// Backwards compatiblity
if (builder.CubeGrid != null)
m_cubeGrids = new MyObjectBuilder_CubeGrid[1] { builder.CubeGrid };
else
m_cubeGrids = builder.CubeGrids;
m_boundingSphere = new BoundingSphere(Vector3.Zero, float.MinValue);
m_boundingBox = BoundingBox.CreateInvalid();
foreach (var grid in m_cubeGrids)
{
BoundingBox localBB = grid.CalculateBoundingBox();
Matrix gridTransform = grid.PositionAndOrientation.HasValue ? (Matrix)grid.PositionAndOrientation.Value.GetMatrix() : Matrix.Identity;
m_boundingBox.Include(localBB.Transform(gridTransform));
}
m_boundingSphere = BoundingSphere.CreateFromBoundingBox(m_boundingBox);
foreach (var gridBuilder in m_cubeGrids)
{
gridBuilder.CreatePhysics = true;
gridBuilder.XMirroxPlane = null;
gridBuilder.YMirroxPlane = null;
gridBuilder.ZMirroxPlane = null;
}
Initialized = true;
}
示例2: Init
protected override void Init(MyObjectBuilder_DefinitionBase baseBuilder)
{
base.Init(baseBuilder);
Id = baseBuilder.Id;
var builder = baseBuilder as MyObjectBuilder_PrefabDefinition;
BoundingSphere = new BoundingSphere(Vector3.Zero, float.MinValue);
PrefabPath = builder.PrefabPath;
if (builder.CubeGrid == null && builder.CubeGrids == null)
{
return;
}
// Backwards compatiblity
if (builder.CubeGrid != null)
CubeGrids = new MyObjectBuilder_CubeGrid[1] { builder.CubeGrid };
else
CubeGrids = builder.CubeGrids;
BoundingBox = BoundingBox.CreateInvalid();
foreach (var grid in CubeGrids)
{
BoundingBox localBB = grid.CalculateBoundingBox();
Matrix gridTransform = grid.PositionAndOrientation.HasValue ? (Matrix)grid.PositionAndOrientation.Value.GetMatrix() : Matrix.Identity;
BoundingBox.Include(localBB.Transform(gridTransform));
}
BoundingSphere = BoundingSphere.CreateFromBoundingBox(BoundingBox);
foreach (var gridBuilder in CubeGrids)
{
gridBuilder.CreatePhysics = true;
gridBuilder.XMirroxPlane = null;
gridBuilder.YMirroxPlane = null;
gridBuilder.ZMirroxPlane = null;
}
}
示例3: CalculateAABB
//private bool TestAABB(ref BoundingBox bbox)
//{
// return (bbox.Max - bbox.Min).Length() < MyLightsConstants.MAX_SPOTLIGHT_AABB_DIAGONAL;
//}
private static void CalculateAABB(ref BoundingBox bbox, out float scaleZ, out float scaleXY, ref Vector3 position, ref Vector3 direction, ref Vector3 up, float reflectorConeMaxAngleCos, float reflectorRange)
{
float cosAngle = 1 - reflectorConeMaxAngleCos;
scaleZ = reflectorRange;
// Calculate cone side (hypotenuse of triangle)
float side = reflectorRange / cosAngle;
// Calculate cone bottom scale (Pythagoras theorem)
scaleXY = (float)System.Math.Sqrt(side * side - reflectorRange * reflectorRange) * 2;
up = MyMwcUtils.Normalize(up);
Vector3 coneSideDirection = Vector3.Cross(up, direction);
coneSideDirection = MyMwcUtils.Normalize(coneSideDirection);
Vector3 coneCenter = position + direction * scaleZ;
Vector3 pt1 = coneCenter + coneSideDirection * scaleXY / 2 + up * scaleXY / 2;
Vector3 pt2 = coneCenter - coneSideDirection * scaleXY / 2 + up * scaleXY / 2;
Vector3 pt3 = coneCenter + coneSideDirection * scaleXY / 2 - up * scaleXY / 2;
Vector3 pt4 = coneCenter - coneSideDirection * scaleXY / 2 - up * scaleXY / 2;
bbox = bbox.CreateInvalid();
bbox = bbox.Include(ref position);
//bbox = bbox.Include(ref coneCenter);
bbox = bbox.Include(ref pt1);
bbox = bbox.Include(ref pt2);
bbox = bbox.Include(ref pt3);
bbox = bbox.Include(ref pt4);
}
示例4: GetTriangleBoundingBox
public void GetTriangleBoundingBox(int triangleIndex, ref BoundingBox boundingBox)
{
boundingBox = BoundingBox.CreateInvalid();
Vector3 v1, v2, v3;
GetVertex(Triangles[triangleIndex].I0, Triangles[triangleIndex].I1, Triangles[triangleIndex].I2, out v1, out v2, out v3);
boundingBox.Include(
v1,
v2,
v3);
}
示例5: AddTriangle
// Add triangleVertexes into this node or its child or child's child...
public void AddTriangle(MyModel model, int triangleIndex, int recursiveLevel)
{
BoundingBox triangleBoundingBox = new BoundingBox();
model.GetTriangleBoundingBox(triangleIndex, ref triangleBoundingBox);
if (recursiveLevel != MAX_RECURSIVE_LEVEL)
{
// If we didn't reach max recursive level, we look for child where triangleVertexes can be completely contained
for (int i = 0; i < OCTREE_CHILDS_COUNT; i++)
{
BoundingBox childBoundingBox = GetChildBoundingBox(m_boundingBox, i);
// If child completely contains the triangleVertexes, we add it to this child (or its child...child).
if (childBoundingBox.Contains(triangleBoundingBox) == ContainmentType.Contains)
{
if (m_childs[i] == null) m_childs[i] = new MyModelOctreeNode(childBoundingBox);
m_childs[i].AddTriangle(model, triangleIndex, recursiveLevel + 1);
// Child completely contains triangle, so also current bounding box must contain that triangle
m_realBoundingBox = m_realBoundingBox.Include(ref triangleBoundingBox.Min);
m_realBoundingBox = m_realBoundingBox.Include(ref triangleBoundingBox.Max);
return;
}
}
}
// If we get here, it was because we reached max recursive level or no child completely contained the triangleVertexes, so we add triangleVertexes to this node
m_triangleIndices.Add(triangleIndex);
m_realBoundingBox = m_realBoundingBox.Include(ref triangleBoundingBox.Min);
m_realBoundingBox = m_realBoundingBox.Include(ref triangleBoundingBox.Max);
}
示例6: GetEncounterBoundingBox
private static BoundingBox GetEncounterBoundingBox(MySpawnGroupDefinition selectedEncounter)
{
BoundingBox encouterBoundingBox = new BoundingBox(Vector3.Zero, Vector3.Zero);
selectedEncounter.ReloadPrefabs();
foreach (var selectedPrefab in selectedEncounter.Prefabs)
{
var prefabDefinition = MyDefinitionManager.Static.GetPrefabDefinition(selectedPrefab.SubtypeId);
encouterBoundingBox.Include(prefabDefinition.BoundingSphere);
}
return encouterBoundingBox;
}
示例7: IntersectLine
public unsafe bool IntersectLine(ref LineD ll, out double startOffset, out double endOffset)
{
var box = new BoundingBox(ll.From, ll.From);
box.Include(ll.To);
int firstFace = -1;
uint faces = 0;
bool complicated = false;
Vector3* corners = stackalloc Vector3[8];
box.GetCornersUnsafe(corners);
for (int i = 0; i < 8; ++i)
{
int face;
MyCubemapHelpers.GetCubeFace(ref corners[i], out face);
if (firstFace == -1)
firstFace = face;
else if (firstFace != face) complicated = true;
faces |= (uint)(1 << face);
}
if (complicated)
return IntersectLineCornerCase(ref ll, faces, out startOffset, out endOffset);
// Later on we will have split the line per sextant already.
// From here on I calculate how many times to split the line to account for the surface curvature.
//
return IntersectLineFace(ref ll, firstFace, out startOffset, out endOffset);
}
示例8: DebugDraw
public void DebugDraw()
{
return;
MyStateObjects.WireframeRasterizerState.Apply();
for (int i = 0; i < NumSplits; i++)
{
cameraFrustum.Matrix = m_lightCameras[i].CameraSubfrustum;
cameraFrustum.GetCorners(frustum);
var tmp = frustum[3];
frustum[3] = frustum[2];
frustum[2] = tmp;
//MyDebugDraw.DrawBoundingFrustum(cameraFrustum, frustumColors[i]);
MySimpleObjectDraw.OcclusionPlaneDraw(frustum);
//MyDebugDraw.DrawTriangle(frustum[0], frustum[1], frustum[2], frustumColors[i], frustumColors[i], frustumColors[i]);
//MyDebugDraw.DrawTriangle(frustum[1], frustum[2], frustum[3], frustumColors[i], frustumColors[i], frustumColors[i]);
}
return;
bool update = false;
if (MyRender.CurrentRenderSetup.CallerID.Value == MyRenderCallerEnum.Main)
{
if (update)
{
mainCamera = MyCamera.GetBoundingFrustum().Matrix;
}
for (int i = 0; i < NumSplits; i++)
{
if (update)
{
Vector4 c = frustumColors[i].ToVector4();
//MyDebugDraw.DrawAABBLowRes(ref box, ref c, 1);
//BoundingFrustum bf = new BoundingFrustum();
//frustumMatrices[i] = m_lightCameras[i].CameraSubfrustum;
frustumMatrices[i] = m_lightCameras[i].BoundingFrustum.Matrix;
}
DebugDrawFrustum(frustumMatrices[i], frustumColors[i]);
Vector4 cc = frustumColors[i].ToVector4();
BoundingFrustum frma = new BoundingFrustum(frustumMatrices[i]);
MyRender.PrepareEntitiesForDraw(ref frma, Vector3.Zero, 0, (MyOcclusionQueryID)(i + 1), m_castingRenderObjects, m_castingCullObjects, m_occlusionQueriesLists[i], ref MyPerformanceCounter.PerCameraDraw.ShadowEntitiesOccluded[i]);
BoundingBox aabbFr = new BoundingBox();
aabbFr = aabbFr.CreateInvalid();
foreach (MyRenderObject ro in m_castingRenderObjects)
{
BoundingBox vv = ro.GetWorldSpaceAABB();
//MyDebugDraw.DrawAABBLowRes(ref vv, ref cc, 1);
aabbFr = aabbFr.Include(ref vv);
}
//MyDebugDraw.DrawAABBLowRes(ref aabbFr, ref cc, 1);
}
// DebugDrawFrustum(mainCamera, new Color(1.0f, 1.0f, 1.0f));
}
}
示例9: ProcessVertex
private void ProcessVertex(MyIsoMesh mesh, int vertexIndex, ref BoundingBox localAabb, ref Vector3 positionScale, ref Vector3D positionOffset, out MyVoxelVertex vertex)
{
vertex.Position = mesh.Positions[vertexIndex];
vertex.Normal = mesh.Normals[vertexIndex];
vertex.Material = mesh.Materials[vertexIndex];
vertex.Ambient = 0f;
Vertex morph;
if (m_morphMap.TryGetValue(mesh.Cells[vertexIndex] >> 1, out morph))
{
vertex.PositionMorph = morph.Target.Position;
vertex.NormalMorph = morph.Target.Normal;
vertex.MaterialMorph = morph.Target.Material;
}
else
{
vertex.PositionMorph = vertex.Position;
vertex.NormalMorph = vertex.Normal;
vertex.MaterialMorph = vertex.Material;
}
localAabb.Include(vertex.Position * positionScale + positionOffset);
localAabb.Include(vertex.PositionMorph * positionScale + positionOffset);
Debug.Assert(vertex.Position.IsInsideInclusive(ref Vector3.MinusOne, ref Vector3.One));
Debug.Assert(vertex.PositionMorph.IsInsideInclusive(ref Vector3.MinusOne, ref Vector3.One));
}
示例10: Update
public bool Update()
{
if (!Enabled)
return AutoDelete; //efect is not enabled at all and must be deleted
System.Diagnostics.Debug.Assert(WorldMatrix != MyUtils.ZeroMatrix, "Effect world matrix was not set!");
if (!m_isPreloading && !m_wasPreloaded && m_preload > 0)
{
m_isPreloading = true;
// TODO: Optimize (preload causes lags, depending on preload size, it's from 0 ms to 85 ms)
//while (m_elapsedTime < m_preload)
//{
// Update();
//}
m_isPreloading = false;
m_wasPreloaded = true;
}
MyRender.GetRenderProfiler().StartProfilingBlock("ParticleEffect-Update");
if (!m_isPreloading && IsInFrustum)
MyPerformanceCounter.PerCameraDraw.ParticleEffectsDrawn++;
MyRender.GetRenderProfiler().EndProfilingBlock();
MyRender.GetRenderProfiler().StartProfilingBlock("ParticleEffect-UpdateGen");
m_elapsedTime += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
m_distance = MyCamera.GetDistanceWithFOV(WorldMatrix.Translation) / (UserScale * 1000.0f);
m_particlesCount = 0;
m_birthRate = 0;
m_AABB = m_AABB.CreateInvalid();
if (CalculateDeltaMatrix)
{
DeltaMatrix = Matrix.Invert(m_lastWorldMatrix) * m_worldMatrix;
}
if (RenderCounter == 0 || ((MyRender.RenderCounter - RenderCounter) < FRAMES_TO_SKIP)) //more than FRAMES_TO_SKIP frames consider effect as invisible
{
foreach (MyParticleGeneration generation in m_generations)
{
generation.EffectMatrix = WorldMatrix;
generation.Update();
m_particlesCount += generation.GetParticlesCount();
m_birthRate += generation.GetBirthRate();
BoundingBox bbox = generation.GetAABB();
m_AABB = m_AABB.Include(ref bbox);
}
m_lastWorldMatrix = m_worldMatrix;
if (m_particlesCount > 0)
m_hasShownSomething = true;
IsInFrustum = MyCamera.IsInFrustum(ref m_AABB);
}
MyRender.GetRenderProfiler().EndProfilingBlock();
if (((m_particlesCount == 0 && HasShownSomething())
|| (m_particlesCount == 0 && m_birthRate == 0.0f))
&& AutoDelete && !m_isPreloading)
{ //Effect was played and has to be deleted
return true;
}
if (!m_isPreloading && OnUpdate != null)
OnUpdate(this, null);
return false;
}
示例11: DoClipping
/// <summary>
/// Recursive clipping function requests cells in provided range and
/// cells needed from parent to wrap the lod safely
/// </summary>
/// <param name="collector"></param>
/// <param name="it0">requested range</param>
/// <param name="ignore">inner range filled by children</param>
private void DoClipping(RequestCollector collector, Vector3I min, Vector3I max, ref BoundingBox ignore)
{
LodLevel parentLod, clevel;
GetNearbyLodLevels(out parentLod, out clevel);
MyCellCoord cell = new MyCellCoord(m_lodIndex, Vector3I.Zero);
//if (collector.SentRequestsEmpty)
{
MyUtils.Swap(ref m_storedCellData, ref m_clippedCells);
m_storedCellData.Clear();
}
var it0 = new Vector3I.RangeIterator(ref min, ref max);
cell.CoordInLod = it0.Current;
var shiftToParent = MyVoxelCoordSystems.RenderCellSizeShiftToLessDetailed(cell.Lod);
var parentCell = parentLod != null ? new MyCellCoord(parentLod.m_lodIndex, cell.CoordInLod >> shiftToParent) : cell;
var parentIgnore = new BoundingBox(parentCell.CoordInLod, parentCell.CoordInLod);
BoundingBox bb = new BoundingBox(cell.CoordInLod, cell.CoordInLod);
for (; it0.IsValid(); it0.GetNext(out cell.CoordInLod)) //cells to be loaded
{
if (ignore.Contains((Vector3)cell.CoordInLod) == ContainmentType.Contains)
{
continue; //lower lod requested
}
if (parentLod != null) //get also their lodcell mates
{
parentCell = new MyCellCoord(parentLod.m_lodIndex, cell.CoordInLod >> shiftToParent);
var it = GetChildrenCoords(this, ref parentCell);
bb.Include(it);
parentIgnore.Max = parentCell.CoordInLod;
}
}
if (parentLod != null)
{
Vector3I parentMinI = Vector3I.Round(parentIgnore.Min - Vector3.One);
Vector3I parentMaxI = Vector3I.Round(parentIgnore.Max + Vector3.One);
//Vector3I.Clamp(ref parentMinI, ref Vector3I.Zero, ref m_lodSizeMinusOne, out parentMinI);
//Vector3I.Clamp(ref parentMaxI, ref Vector3I.Zero, ref m_lodSizeMinusOne, out parentMaxI);
var parentIterator = new Vector3I.RangeIterator(ref parentMinI, ref parentMaxI);
parentLod.DoClipping(collector, parentMinI, parentMaxI, ref parentIgnore);
}
Vector3I start, end;
start = Vector3I.Round(bb.Min); end = Vector3I.Round(bb.Max);
Vector3I.Clamp(ref start, ref Vector3I.Zero, ref m_lodSizeMinusOne, out start);
Vector3I.Clamp(ref end, ref Vector3I.Zero, ref m_lodSizeMinusOne, out end);
it0 = new Vector3I.RangeIterator(ref start, ref end);
cell.CoordInLod = it0.Current;
for (; it0.IsValid(); it0.GetNext(out cell.CoordInLod)) //cells to be loaded
{
if (ignore.Contains((Vector3)cell.CoordInLod) == ContainmentType.Contains)
{
continue; //lower lod requested
}
var cellId = cell.PackId64();
CellData data;
if (m_clippedCells.TryGetValue(cellId, out data))
{
m_clippedCells.Remove(cellId);
}
else
{
var clipmapCellId = MyCellCoord.GetClipmapCellHash(m_clipmap.Id, cellId);
data = CellsCache.Read(clipmapCellId);
if (data == null) //cache miss
{
data = new CellData();
ClippingCacheMisses++;
}
else
{
//cache hit
ClippingCacheHits++;
data.InScene = false;
if (data.Cell != null)
{
m_nonEmptyCells[cellId] = data;
}
}
}
if (data.State == CellState.Invalid)
{
if (!TryAddCellRequest(collector, parentLod, cell, cellId, data))
//.........这里部分代码省略.........
示例12: CreateWaypointsAroundLargeStaticObjects
//.........这里部分代码省略.........
}
envelopes.Add(envelope);
envelopeEntity.Add(entity);
envelopeBvh.AddProxy(ref extrudedBox, envelopes.Count - 1, 0);
largeObjects++;
if (entity.Name == "Madelyn")
{
madelynsBox = envelopes.Count - 1;
}
}
MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
var componentsDone = new HashSet<int>();
MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("connect free wps");
// free waypoint: check whether it's connected to an envelope
foreach (var v in GetVertexListForModification()) if (!nonFree.Contains(v))
{
int id = GetConnectedComponentId(v);
if (componentsDone.Contains(id)) continue;
componentsDone.Add(id);
var connectedWaypoints = GetWaypointsWithConnectedComponentId(id);
// is this component already connected to an envelope?
var box = new BoundingBox(v.Position, v.Position);
foreach (var w in connectedWaypoints) if (w.Save)
{
var pos = w.Position;
box = box.Include(ref pos);
if (nonFree.Contains(w))
goto alreadyConnected;
}
BoundingBox extrudedBox = new BoundingBox(box.Min - (box.Max - box.Min) * 0.01f - new Vector3(5, 5, 5), box.Max + (box.Max - box.Min) * 0.01f + new Vector3(5, 5, 5));
// no - create a new one
int s = 1;
MyWayPoint[, ,] envelope = new MyWayPoint[s + 1, s + 1, s + 1];
for (int i = 0; i <= s; i++) for (int j = 0; j <= s; j++) for (int k = 0; k <= s; k++)
{
envelope[i, j, k] = CreateWaypoint(new Vector3(
extrudedBox.Min.X + i * (extrudedBox.Max.X - extrudedBox.Min.X) / s,
extrudedBox.Min.Y + j * (extrudedBox.Max.Y - extrudedBox.Min.Y) / s,
extrudedBox.Min.Z + k * (extrudedBox.Max.Z - extrudedBox.Min.Z) / s
), null);
envelope[i, j, k].Save = false; // don't save generated waypoints
nonFree.Add(envelope[i, j, k]);
// connect with neighbors
// should use ConnectIfVisible, but it's slow and we can resolve it while computing the GPS
if (i != 0) { if (MyWayPoint.ConnectIfNoAABBBlockers(envelope[i, j, k], envelope[i - 1, j, k])) edgesWithRaycastsAdded++; else edgesWithRaycastsNotAdded++; }
if (j != 0) { if (MyWayPoint.ConnectIfNoAABBBlockers(envelope[i, j, k], envelope[i, j - 1, k])) edgesWithRaycastsAdded++; else edgesWithRaycastsNotAdded++; }
if (k != 0) { if (MyWayPoint.ConnectIfNoAABBBlockers(envelope[i, j, k], envelope[i, j, k - 1])) edgesWithRaycastsAdded++; else edgesWithRaycastsNotAdded++; }
}
// connect all waypoints to the closest corner of the new envelope
foreach (var w in connectedWaypoints)
{
var pos = w.Position;
if (MyWayPoint.ConnectIfNoAABBBlockers(w, envelope[pos.X < extrudedBox.GetCenter().X ? 0 : 1, pos.Y < extrudedBox.GetCenter().Y ? 0 : 1, pos.Z < extrudedBox.GetCenter().Z ? 0 : 1]))
edgesWithRaycastsAdded++;