本文整理汇总了C#中BoundingFrustum.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingFrustum.Intersects方法的具体用法?C# BoundingFrustum.Intersects怎么用?C# BoundingFrustum.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingFrustum
的用法示例。
在下文中一共展示了BoundingFrustum.Intersects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVisibleMeshes
public override void GetVisibleMeshes(BoundingFrustum frustum, List<Mesh.SubMesh>[] visibleSubMeshes)
{
for (int index = 0; index < _worldSubMeshes.Count; index++)
{
Mesh.SubMesh subMesh = _worldSubMeshes[index];
if (subMesh.Enabled &&
frustum.Intersects(subMesh.GlobalBoundingSphere) &&
frustum.Intersects(subMesh.GlobalBoundingBox))
{
visibleSubMeshes[(int)subMesh.RenderQueue].Add(subMesh);
}
}
}
示例2: VisitTree
public static void VisitTree(OctCell root, BoundingFrustum frustum, Action<OctCell> callback)
{
if (frustum.Intersects(root.Bounds))
{
if (root.Leaf) callback(root);
else foreach (var child in root.Children) VisitTree(child, frustum, callback);
}
}
示例3: GetVisibleLights
public void GetVisibleLights(BoundingFrustum frustum, List<Light> visibleLights)
{
for (int index = 0; index < lights.Count; index++)
{
Light l = lights[index];
if (l.Enabled && frustum.Intersects(l.BoundingSphere))
{
visibleLights.Add(l);
}
}
}
示例4: BoundingFrustumToBoundingBoxTests
public void BoundingFrustumToBoundingBoxTests()
{
var view = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
var projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1, 1, 100);
var testFrustum = new BoundingFrustum(view * projection);
var bbox1 = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
Assert.That(testFrustum.Contains(bbox1), Is.EqualTo(ContainmentType.Contains));
Assert.That(testFrustum.Intersects(bbox1), Is.True);
var bbox2 = new BoundingBox(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
Assert.That(testFrustum.Contains(bbox2), Is.EqualTo(ContainmentType.Intersects));
Assert.That(testFrustum.Intersects(bbox2), Is.True);
var bbox3 = new BoundingBox(new Vector3(-1000, -1000, -1000), new Vector3(0, 0, 0));
Assert.That(testFrustum.Contains(bbox3), Is.EqualTo(ContainmentType.Intersects));
Assert.That(testFrustum.Intersects(bbox3), Is.True);
var bbox4 = new BoundingBox(new Vector3(-1000, -1000, -1000), new Vector3(-500, -500, -500));
Assert.That(testFrustum.Contains(bbox4), Is.EqualTo(ContainmentType.Disjoint));
Assert.That(testFrustum.Intersects(bbox4), Is.False);
}
示例5: GetVisibleMeshes
public void GetVisibleMeshes(BoundingFrustum frustum, List<Mesh.SubMesh> visibleSubMeshes)
{
for (int index = 0; index < meshes.Count; index++)
{
Mesh m = meshes[index];
if (frustum.Intersects(m.GlobalBoundingBox))
{
for (int si = 0; si < m.SubMeshes.Count; si++)
{
Mesh.SubMesh sm = m.SubMeshes[si];
if (sm.Enabled) visibleSubMeshes.Add(sm);
}
}
}
}
示例6: Draw
public virtual void Draw(Matrix view, Matrix projection)
{
baseTransforms = new Matrix[this.Model.Bones.Count];
this.Model.CopyAbsoluteBoneTransformsTo(baseTransforms);
// Do nothing if the object is outside the view frustum
BoundingFrustum viewFrustum = new BoundingFrustum(view * projection);
if (viewFrustum.Intersects(BoundingSphere))
{
world = Matrix.CreateScale(Scale) * Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.CreateTranslation(Position);
foreach (ModelMesh mesh in Model.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
if (currentEffect is BasicEffect)
{
BasicEffect effect = currentEffect as BasicEffect;
effect.World = baseTransforms[mesh.ParentBone.Index] * world;
effect.View = view;
effect.Projection = projection;
}
else
{
EffectParameterCollection parameters = currentEffect.Parameters;
if (parameters["World"] != null)
parameters["World"].SetValue(baseTransforms[mesh.ParentBone.Index] * world);
if (parameters["View"] != null)
parameters["View"].SetValue(view);
if (parameters["Projection"] != null)
parameters["Projection"].SetValue(projection);
}
SetEffectParameters(currentEffect);
}
mesh.Draw();
}
}
}
示例7: InView
bool InView(BoundingBox boundingSphere)
{
bf = new BoundingFrustum(cubeEffect.View * cubeEffect.Projection);
return bf.Intersects(boundingSphere);
}
示例8: RefreshMeshCounts
/// <summary>
/// Get the total number of visible dwarves, and resize our instance arrays accordingly
/// </summary>
/// <param name="frustum"></param>
private void RefreshMeshCounts(BoundingFrustum frustum)
{
// Reset the counts of each part to 0
for (int i = 0; i < this.meshPartCount.Length; i++)
this.meshPartCount[i] = 0;
// Loop through, and see if they are visible
// If the dwarf is visible, make sure we add to the body part counters
for (int i = 0; i < this.numInstances; i++)
{
Dwarf dwarf = this.dwarves[i];
bool intersects = true;
frustum.Intersects(ref dwarf.boundingSphere, out intersects);
if (intersects)
{
this.meshPartCount[dwarf.HeadPart]++;
this.meshPartCount[dwarf.BodyPart]++;
this.meshPartCount[dwarf.LegPart]++;
}
dwarf.IsVisible = intersects;
}
// Resize all the arrays accordingly
for (int i = 0; i < this.meshInstances.Count; i++)
{
Array.Resize(ref this.meshInstances[i].transforms, meshPartCount[i]);
Array.Resize(ref this.meshInstances[i].animations, meshPartCount[i]);
}
}
示例9: RenderChildren
private void RenderChildren(BoundingFrustum frustum, CActor actor, Matrix world, bool parentAnimated)
{
if (RenderWheelsSeparately && actor.IsWheel) return;
bool intersects;
if (frustum == null)
{
intersects = true;
}
else
{
intersects = actor.BoundingBox.Max.X == 0;
if (!intersects)
{
frustum.Intersects(ref actor.BoundingBox, out intersects);
GameVars.NbrSectionsChecked++;
}
}
if (intersects)
{
Matrix m = actor.GetDynamicMatrix();
if (actor.IsAnimated || parentAnimated)
{
if (actor.IsAnimated && !parentAnimated)
{
world = m * actor.ParentMatrix * GameVars.ScaleMatrix * world;
}
else
{
world = m * world;
}
GameVars.CurrentEffect.World = world;
parentAnimated = true;
}
else
{
GameVars.CurrentEffect.World = m * world;
}
GameVars.CurrentEffect.CommitChanges();
if (actor.Model != null)
{
actor.Model.Render(actor.Material);
if (actor.Model is CDeformableModel)
{
Models.SetupRender();
}
}
GameVars.NbrSectionsRendered++;
foreach (CActor child in actor.Children)
RenderChildren(frustum, child, world, parentAnimated);
}
}
示例10: GetOverlaps
/// <summary>
/// Gets the triangles whose bounding boxes are overlapped by the query.
/// </summary>
/// <param name="boundingFrustum">Shape to query against the tree.</param>
/// <param name="outputOverlappedElements">Indices of triangles in the index buffer with bounding boxes which are overlapped by the query.</param>
/// <returns>Whether or not any elements were overlapped.</returns>
public bool GetOverlaps(BoundingFrustum boundingFrustum, IList<int> outputOverlappedElements)
{
if (root != null)
{
bool intersects;
boundingFrustum.Intersects(ref root.BoundingBox, out intersects);
if (intersects)
root.GetOverlaps(ref boundingFrustum, outputOverlappedElements);
}
return outputOverlappedElements.Count > 0;
}
示例11: RecursiveChildStatus
////////////////////////////////////////////////////////////////////
/// <summary>
/// Yet another recursive function. This function takes the position of the camera, and statuses all the children nodes of the
/// specified quadnode based on their distance. It then recurses down the tree, statusing as it goes.
/// In essence, this function is what applies our LOD
///
/// Addition: I've integrated the frustrum checks into this algorithm, to improve performance.
/// </summary>
/// <param name="qNode">The root node.</param>
/// <param name="cameraPoint">The camera's position</param>
/// <param name="LODLevel">The LOD Distance to apply. 3.5 is the recommended minimum, because of stitching issues. Less than 2 may cause an unhandled exception.</param>
private void RecursiveChildStatus(QuadNode qNode, Vector3 cameraPoint, float LODLevel, BoundingFrustum CameraFrustrum)
{
//Determine the squared distance of the camera from the specified node, taking into account the size of the node and the scale of
//the terrain.
//This value doesn't undergo a Sqrt to save processing power: instead, the opposite side is sqared
qNode.distanceFromCamera = (float)(Math.Pow(Math.Abs(cameraPoint.X - ((qNode.XPosition + (qNode.NodeScale / 2)) * Scale)), 2) + Math.Pow(Math.Abs(cameraPoint.Y - ((0 + (qNode.NodeScale / 2)) * Scale)), 2) * LODHeightImpact + Math.Pow(Math.Abs(cameraPoint.Z - ((qNode.YPosition + (qNode.NodeScale / 2)) * Scale)), 2));
/////////////////////////////////////////////////
//Staus this node as 1...
qNode.status = 1;
//...then, if node depth is not too deep...
if (qNode.NodeDepth < maxNodeDepth)
{
float leftUpLOD = qNode.leftUpNode.NodeScale * Scale * LODLevel;
float leftDownLOD = qNode.leftDownNode.NodeScale * Scale * LODLevel;
float rightUpLOD = qNode.rightUpNode.NodeScale * Scale * LODLevel;
float rightDownLOD = qNode.rightDownNode.NodeScale * Scale * LODLevel;
leftUpLOD *= leftUpLOD;
leftDownLOD *= leftDownLOD;
rightUpLOD *= rightUpLOD;
rightDownLOD *= rightDownLOD;
//...determine whether or not to recurse onto the nodes children.
if (qNode.distanceFromCamera < leftUpLOD)
{
if (CameraFrustrum.Intersects(qNode.leftUpNode.boundBox))
{
qNode.status = 2;
RecursiveChildStatus(qNode.leftUpNode, cameraPoint, LODLevel, CameraFrustrum);
}
else
{
qNode.leftUpNode.inView = false;
qNode.status = 2;
}
}
if (qNode.distanceFromCamera < leftDownLOD)
{
if (CameraFrustrum.Intersects(qNode.leftDownNode.boundBox))
{
qNode.status = 2;
RecursiveChildStatus(qNode.leftDownNode, cameraPoint, LODLevel, CameraFrustrum);
}
else
{
qNode.leftDownNode.inView = false;
qNode.status = 2;
}
}
if (qNode.distanceFromCamera < rightUpLOD)
{
if (CameraFrustrum.Intersects(qNode.rightUpNode.boundBox))
{
qNode.status = 2;
RecursiveChildStatus(qNode.rightUpNode, cameraPoint, LODLevel, CameraFrustrum);
}
else
{
qNode.rightUpNode.inView = false;
qNode.status = 2;
}
}
if (qNode.distanceFromCamera < rightDownLOD)
{
if (CameraFrustrum.Intersects(qNode.rightDownNode.boundBox))
{
qNode.status = 2;
RecursiveChildStatus(qNode.rightDownNode, cameraPoint, LODLevel, CameraFrustrum);
}
else
{
qNode.rightDownNode.inView = false;
qNode.status = 2;
}
}
}
}
示例12: Render
public void Render(Vector3 cameraPosition, TrackNode currentNode)
{
_skybox.Render();
_effect.View = Engine.Instance.Camera.View;
_effect.Projection = Engine.Instance.Camera.Projection;
_effect.World = Matrix.Identity;
int segmentIndex = currentNode.Number / 4;
var startSegment = TerrainSegments[segmentIndex];
var renderedSegments = new List<TerrainSegment>();
Engine.Instance.Device.SetVertexBuffer(TerrainVertexBuffer);
_effect.CurrentTechnique.Passes[0].Apply();
Engine.Instance.Device.RasterizerState = RasterizerState.CullNone;
Engine.Instance.Device.SamplerStates[0] = GameConfig.WrapSampler;
var frustum = new BoundingFrustum(Engine.Instance.Camera.View * Engine.Instance.Camera.Projection);
// draw segments from the player vehicle forwards. Stop when a segment is out of view
var segment = startSegment;
for (int i = 0; i < GameConfig.MaxSegmentRenderCount; i++)
{
if (segment == null) break;
if (frustum.Intersects(segment.BoundingBox))
{
RenderSegment(segment);
renderedSegments.Add(segment);
}
else
{
break;
}
segment = segment.Next;
}
// draw segments from the player vehicle backwards. Stop when a segment is out of view
segment = startSegment.Prev;
for (int i = 0; i < GameConfig.MaxSegmentRenderCount; i++)
{
if (segment == null) break;
if (frustum.Intersects(segment.BoundingBox))
{
RenderSegment(segment);
renderedSegments.Add(segment);
}
segment = segment.Prev;
}
DrawScenery(renderedSegments);
if (FenceVertexBuffer != null)
{
Engine.Instance.Device.SetVertexBuffer(FenceVertexBuffer);
_effect.World = Matrix.Identity;
_effect.CurrentTechnique.Passes[0].Apply();
Engine.Instance.Device.SamplerStates[0] = GameConfig.WrapSampler;
foreach (var renderedSegment in renderedSegments)
{
DrawFenceStrips(renderedSegment);
}
}
if (GameConfig.DrawDebugInfo)
{
var node = currentNode;
for (int i = 0; i < GameConfig.MaxSegmentRenderCount; i++)
{
Engine.Instance.GraphicsUtils.AddCube(Matrix.CreateTranslation(node.GetLeftBoundary()), Color.Red);
Engine.Instance.GraphicsUtils.AddCube(Matrix.CreateTranslation(node.GetRightBoundary()), Color.Red);
Engine.Instance.GraphicsUtils.AddCube(Matrix.CreateTranslation(node.GetLeftVerge()), Color.Blue);
Engine.Instance.GraphicsUtils.AddCube(Matrix.CreateTranslation(node.GetRightVerge()), Color.Blue);
Engine.Instance.GraphicsUtils.AddCube(Matrix.CreateTranslation(node.Position), Color.Yellow);
if (node.Number % TriFile.NbrRowsPerSegment == 0)
{
Engine.Instance.GraphicsUtils.AddLine(node.GetLeftBoundary(), node.GetRightBoundary(), Color.White);
}
node = node.Next;
if (node == null) break;
}
GameConsole.WriteLine(String.Format("Position node: {0}, segment: {1}", currentNode.Number, (int)(currentNode.Number / TriFile.NbrRowsPerSegment)));
GameConsole.WriteLine(String.Format("Node property: {0}, flags: {1}, {2}, {3}", currentNode.NodeProperty, currentNode.Flag1, currentNode.Flag2, currentNode.Flag3));
}
}
示例13: Draw
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
//Jumping
if (!fpsCam.InDeathThroes)
fpsCam.Setjump(currentjump + 10.0f);
graphics.GraphicsDevice.Clear(new Color(new Vector3(0.002f, 0.002f, 0.002f)));
// enable the depth buffer since geometry will be drawn
graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;
graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
graphics.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
// always set the shared effects parameters
viewParameter.SetValue(fpsCam.ViewMatrix);
cameraPositionParameter.SetValue(fpsCam.Position);
//Further optimisation needed - each quad should know which square it's in and the player's field of view should be taken into account
// MAIN DRAW
//Particles
smokePlumeParticles.SetCamera(fpsCam.ViewMatrix, fpsCam.ProjectionMatrix);
fireParticles.SetCamera(fpsCam.ViewMatrix, fpsCam.ProjectionMatrix);
antifireParticles.SetCamera(fpsCam.ViewMatrix, fpsCam.ProjectionMatrix);
BoundingSphere sphere = new BoundingSphere();
BoundingFrustum frustum = new BoundingFrustum(fpsCam.ViewMatrix * fpsCam.ProjectionMatrix);
Matrix ww;
//Only render the monster in play mode.
if (!Stage.GameState.DemoMode)
//Render The Stage
Stage.Render(true, false, false, fpsCam, 160.0f);
if (!Stage.GameState.DemoMode)
{
//Test render - a purple cube at the teleporter location.
Matrix mw = Matrix.Identity * Matrix.CreateTranslation(TeleporterRenderLocation);
BasicMaterial.DrawComplexModelWithMaterial(testmodel, ref mw, string.Empty);
}
else
{
Matrix mw = Matrix.Identity * Matrix.CreateTranslation(0,0,100);
BasicMaterial.DrawComplexModelWithMaterial(testmodel, ref mw, string.Empty);
}
//Render walls
foreach (Quad q in Stage.Map.Floors)
{
if (q.Origin.X * 2 < fpsCam.Position.X + (320 * OptionsViewDistance / 100) && q.Origin.X * 2 > fpsCam.Position.X - (320 * OptionsViewDistance / 100)
&& q.Origin.Z * 2 < fpsCam.Position.Z + (320 * OptionsViewDistance / 100) && q.Origin.Z * 2 > fpsCam.Position.Z - (320 * OptionsViewDistance / 100))
{
sphere = new BoundingSphere(new Vector3(q.Origin.X * 2, q.Origin.Y, q.Origin.Z * 2), 16.0f);
if (frustum.Intersects(sphere))
{
ww = Matrix.Identity * Matrix.CreateTranslation(q.Origin);
FloorMaterial.DrawQuadWithMaterial(q, ref ww);
}
}
}
foreach (Quad q in Stage.Map.Ceilings)
{
if (q.Origin.X * 2 < fpsCam.Position.X + (320 * OptionsViewDistance / 100) && q.Origin.X * 2 > fpsCam.Position.X - (320 * OptionsViewDistance / 100)
&& q.Origin.Z * 2 < fpsCam.Position.Z + (320 * OptionsViewDistance / 100) && q.Origin.Z * 2 > fpsCam.Position.Z - (320 * OptionsViewDistance / 100))
{
sphere = new BoundingSphere(new Vector3(q.Origin.X * 2, q.Origin.Y, q.Origin.Z * 2), 16.0f);
if (frustum.Intersects(sphere))
{
ww = Matrix.Identity * Matrix.CreateTranslation(q.Origin);
CeilingMaterial.DrawQuadWithMaterial(q, ref ww);
}
}
}
foreach (Quad q in Stage.Map.Walls)
{
if (q.Origin.X * 2 < fpsCam.Position.X + (320 * OptionsViewDistance / 100) && q.Origin.X * 2 > fpsCam.Position.X - (320 * OptionsViewDistance / 100)
&& q.Origin.Z * 2 < fpsCam.Position.Z + (320 * OptionsViewDistance / 100) && q.Origin.Z * 2 > fpsCam.Position.Z - (320 * OptionsViewDistance / 100))
{
sphere = new BoundingSphere(new Vector3(q.Origin.X * 2, q.Origin.Y, q.Origin.Z * 2), 16.0f);
if (frustum.Intersects(sphere))
{
ww = Matrix.Identity * Matrix.CreateTranslation(q.Origin);
WallMaterial.DrawQuadWithMaterial(q, ref ww);
}
}
}
//draw smoke only when teleporter is near.
if (Vector3.Distance(fpsCam.Position, TeleporterLocation) < (320 * OptionsViewDistance / 100))
smokePlumeParticles.Draw(gameTime);
//fireParticles.Draw(gameTime);
//draw fire only when monster is near.
//.........这里部分代码省略.........
示例14: DrawGameplayScreen
private void DrawGameplayScreen()
{
BoundingFrustum view_frustum = new BoundingFrustum(gameCamera.view_matrix * gameCamera.projection_matrix);
//device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.DarkSlateBlue, 1.0f, 0);
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
foreach (ModelMesh mesh in skyboxModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(20.0f);
effect.View = gameCamera.view_matrix;
effect.Projection = gameCamera.projection_matrix;
}
mesh.Draw();
}
DrawTerrain(ground.model, grassTexture);
DrawWalls(brick_wall.model, brickTexture);
foreach (Zombie zombie in zombies)
{
BoundingSphere object_sphere = new BoundingSphere(zombie.position, 5.0f);
if (!zombie.Killed && view_frustum.Intersects(object_sphere))
{
zombie.Draw(gameCamera.view_matrix,
gameCamera.projection_matrix);
}
}
foreach (Tree tree in trees)
{
BoundingSphere object_sphere = new BoundingSphere(tree.position, 8.0f);
if (view_frustum.Intersects(object_sphere))
tree.Draw(gameCamera.view_matrix, gameCamera.projection_matrix);
}
DepthStencilState dss = new DepthStencilState();
DepthStencilState dss2 = new DepthStencilState();
dss.DepthBufferEnable = false;
dss2.DepthBufferEnable = true;
GraphicsDevice.DepthStencilState = dss;
guns.Draw(player.position, player.forward_direction, gameCamera.view_matrix, gameCamera.projection_matrix);
GraphicsDevice.DepthStencilState = dss2;
/*foreach (Ray ray in rayList)
{
RayRenderer.Render(ray,100.0f, GraphicsDevice, gameCamera.view_matrix,gameCamera.projection_matrix, Color.Red);
}
*/
//player.Draw(gameCamera.view_matrix, gameCamera.projection_matrix);
DrawStats();
}
示例15: Intersects
/// <summary>
/// Проверка столкновения юнита с заданной пирамидой вида
/// </summary>
/// <param name="boundingFrustum">Пирамида вида</param>
/// <returns>Истина если пересекаются</returns>
public bool Intersects(BoundingFrustum boundingFrustum)
{
//if (BoundingBox != null)
// return boundingFrustum.Intersects(BoundingBox.Value);
if (Type.Model == null)
return true;
return Type.Model.Meshes.Any(mesh => boundingFrustum.Intersects(
mesh.BoundingSphere.Transform(GetResultingTransformation(Transforms[mesh.ParentBone.Index]))));
}