本文整理汇总了C#中Camera.DoFrustumCulling方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.DoFrustumCulling方法的具体用法?C# Camera.DoFrustumCulling怎么用?C# Camera.DoFrustumCulling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera
的用法示例。
在下文中一共展示了Camera.DoFrustumCulling方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(GraphicsDevice device, Camera cam)
{
if (filter == null)
{
return;
}
Mesh mesh = filter.meshToRender;
BoundingSphere sphere = new BoundingSphere(transform.TransformPoint(filter.boundingSphere.Center), filter.boundingSphere.Radius * Math.Max(transform.lossyScale.x, Math.Max(transform.lossyScale.y, transform.lossyScale.z)));
bool cull = cam.DoFrustumCulling(ref sphere);
if (cull)
{
#if DEBUG
if (Camera.logRenderCalls)
{
Debug.LogFormat("VP cull mesh {0} with center {1} radius {2} cam {3} at {4}", gameObject, sphere.Center, sphere.Radius, cam.gameObject, cam.transform.position);
}
#endif
return;
}
if (filter.CanBatch())
{
cam.BatchRender(filter.meshToRender, sharedMaterials, transform);
}
}
示例2: Draw
public override void Draw(GraphicsDevice device, Camera cam)
{
if (sharedMesh == null)
{
return;
}
// Check the frustum of the camera
// When we kill this code we can kill the BoundingSphere in mesh and filter
BoundingSphere sphere = new BoundingSphere(transform.position, sharedMesh.bounds.boundingSphere.Radius * transform.lossyScale.sqrMagnitude);
if (cam.DoFrustumCulling(ref sphere))
{
#if DEBUG
if (Camera.logRenderCalls)
{
Debug.LogFormat("VP cull {0} with radius {1} pos {2} cam {3} at {4}", gameObject, sharedMesh.bounds.boundingSphere.Radius, transform.position, cam.gameObject, cam.transform.position);
}
#endif
return;
}
if (sharedMesh.boneWeights != null)
{
// This is the rendering of data gotten directly from Unity
//Matrix world = transform.world;
Matrix world = Matrix.Identity;
// Find the current bone data from the bone Transform.
for (int i = 0; i < bones.Length; i++)
{
bindPoses[i] = Matrix.Identity;
//bindPoses[i] = bones[i].world * Matrix.Invert(transform.world);
bindPoses[i] = sharedMesh.bindPoses[i] * bones[i].world;
//Debug.Log(bones[i].name + " : " + bones[i].localPosition);
}
// We have blended parts that does not come from a bone structure
for (int i = 0; i < sharedMesh._vertices.Length; i++)
{
CpuSkinningHelpers.SkinVertex(
bindPoses,
ref sharedMesh._vertices[i],
ref sharedMesh._normals[i],
ref world,
ref sharedMesh.boneWeights[i],
out mesh._vertices[i],
out mesh._normals[i]);
}
cam.BatchRender(mesh, sharedMaterials, null);
}
}
示例3: Draw
public override int Draw(GraphicsDevice device, Camera cam)
{
if (filter == null)
{
return 0;
}
BoundingSphere sphere = new BoundingSphere((Microsoft.Xna.Framework.Vector3)transform.position + filter.boundingSphere.Center, filter.boundingSphere.Radius * transform.lossyScale.sqrMagnitude);
if (cam.DoFrustumCulling(ref sphere))
{
#if DEBUG
if (Camera.logRenderCalls)
{
Debug.LogFormat("VP cull {0} with radius {1} pos {2} cam {3} at {4}", gameObject, filter.boundingSphere.Radius, transform.position, cam.gameObject, cam.transform.position);
}
#endif
return 0;
}
// NOTE: I don't want to look at this now... Use the old rendering method.
if (false /*vBuffer != null */)
{
device.SetVertexBuffer(vBuffer);
IndexBuffer iBuffer = filter.mesh.GetIndexBuffer();
device.Indices = iBuffer;
if (material != null)
{
Render(device, cam, material, vBuffer.VertexCount, iBuffer.IndexCount / 3);
//for (int i = 1; i < sharedMaterials.Length; i++)
//{
// sharedMaterials[i].Render(vBuffer, iBuffer);
//}
}
else
{
Debug.LogFormat("We have no material for {0}, so it is not rendered", this);
}
}
else
{
if (filter.CanBatch())
{
return cam.BatchRender(filter.meshToRender, sharedMaterials, transform);
}
}
return 0;
}
示例4: Draw
public override void Draw(GraphicsDevice device, Camera cam)
{
if (filter == null)
{
return;
}
BoundingSphere sphere = new BoundingSphere((Microsoft.Xna.Framework.Vector3)transform.position + filter.boundingSphere.Center, filter.boundingSphere.Radius * transform.lossyScale.sqrMagnitude);
if (cam.DoFrustumCulling(ref sphere))
{
#if DEBUG
if (Camera.logRenderCalls)
{
Debug.LogFormat("VP cull {0} with radius {1} pos {2} cam {3} at {4}", gameObject, filter.boundingSphere.Radius, transform.position, cam.gameObject, cam.transform.position);
}
#endif
return;
}
if (filter.CanBatch())
{
cam.BatchRender(filter.meshToRender, sharedMaterials, transform);
}
}
示例5: RenderParticle
private bool RenderParticle(Camera cam, int vertexIndex, int triangleIndex, ref Particle particle)
{
float size = particle.Size / 2;
if (size <= 0)
{
return false;
}
Microsoft.Xna.Framework.Vector3 pos = particle.Position;
if (!emitter.useWorldSpace)
{
pos += (Microsoft.Xna.Framework.Vector3)transform.position;
}
if (doViewportCulling)
{
BoundingSphere sphere = new BoundingSphere(pos, size);
if (cam.DoFrustumCulling(ref sphere))
{
return false;
}
}
vertices[vertexIndex].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(particle.TextureOffset.x, particle.TextureOffset.y + particle.TextureScale.y);
vertices[vertexIndex].Color = particle.Color;
vertices[vertexIndex + 1].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(particle.TextureOffset.x, particle.TextureOffset.y);
vertices[vertexIndex + 1].Color = particle.Color;
vertices[vertexIndex + 2].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(particle.TextureOffset.x + particle.TextureScale.x, particle.TextureOffset.y + particle.TextureScale.y);
vertices[vertexIndex + 2].Color = particle.Color;
vertices[vertexIndex + 3].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(particle.TextureOffset.x + particle.TextureScale.x, particle.TextureOffset.y);
vertices[vertexIndex + 3].Color = particle.Color;
//rotated particles
if (stretchParticles == StretchParticles.Billboard)
{
Microsoft.Xna.Framework.Vector3 particlePosition = particle.Position;
Matrix.CreateBillboard(
ref particlePosition,
ref camPosition,
ref camUpVector,
camForwardVector,
out m
);
Microsoft.Xna.Framework.Vector3 vertical = new Microsoft.Xna.Framework.Vector3(0, -size, 0);
Microsoft.Xna.Framework.Vector3 horizontal = new Microsoft.Xna.Framework.Vector3(size, 0, 0);
m.Translation = Microsoft.Xna.Framework.Vector3.Zero;
//Microsoft.Xna.Framework.Vector3.Transform(ref p, ref m, out p);
Microsoft.Xna.Framework.Vector3.Transform(ref vertical, ref m, out vertical);
Microsoft.Xna.Framework.Vector3.Transform(ref horizontal, ref m, out horizontal);
vertices[vertexIndex].Position = pos - vertical + horizontal;
vertices[vertexIndex+1].Position = pos - vertical - horizontal;
vertices[vertexIndex+2].Position = pos + vertical + horizontal;
vertices[vertexIndex+3].Position = pos + vertical - horizontal;
}
if (stretchParticles == StretchParticles.Stretched)
{
size *= 2;
Microsoft.Xna.Framework.Vector3 particlePosition = particle.Position;
//TODO make this work correctly, and add velocityScale functionality.
Microsoft.Xna.Framework.Vector3 vertical = -particle.Velocity;
vertical.Normalize();
vertical *= size * lengthScale;
Microsoft.Xna.Framework.Vector3 horizontal = -Microsoft.Xna.Framework.Vector3.Cross(vertical, camForwardVector);
horizontal.Normalize();
horizontal *= size;
vertices[vertexIndex].Position = pos - vertical + horizontal;
vertices[vertexIndex + 1].Position = pos - vertical - horizontal;
vertices[vertexIndex + 2].Position = pos + vertical + horizontal;
vertices[vertexIndex + 3].Position = pos + vertical - horizontal;
}
if (stretchParticles == StretchParticles.HorizontalBillboard)
{
vertices[vertexIndex].Position = pos + new Microsoft.Xna.Framework.Vector3(-size, vertexIndex * 0.0001f, size);
vertices[vertexIndex + 1].Position = pos + new Microsoft.Xna.Framework.Vector3(-size, vertexIndex * 0.0001f, -size);
vertices[vertexIndex + 2].Position = pos + new Microsoft.Xna.Framework.Vector3(size, vertexIndex * 0.0001f, size);
vertices[vertexIndex + 3].Position = pos + new Microsoft.Xna.Framework.Vector3(size, vertexIndex * 0.0001f, -size);
}
return true;
}