當前位置: 首頁>>代碼示例>>C#>>正文


C# Camera.DoFrustumCulling方法代碼示例

本文整理匯總了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);
            }
        }
開發者ID:iamjianxin,項目名稱:FFWD,代碼行數:26,代碼來源:MeshRenderer.cs

示例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);
            }
        }
開發者ID:gamekingdom,項目名稱:FFWD,代碼行數:50,代碼來源:SkinnedMeshRenderer.cs

示例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;
        }
開發者ID:CodeHelix,項目名稱:FFWD,代碼行數:48,代碼來源:MeshRenderer.cs

示例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);
            }
        }
開發者ID:gamekingdom,項目名稱:FFWD,代碼行數:24,代碼來源:MeshRenderer.cs

示例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;
        }
開發者ID:Joelone,項目名稱:FFWD,代碼行數:89,代碼來源:ParticleRenderer.cs


注:本文中的Camera.DoFrustumCulling方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。