Beispiel #1
0
        }   // end of Frustum CullTest()

        /// <summary>
        /// Test an axis aligned bounding box against the frustum.
        /// </summary>
        public CullResult CullTest(Vector3 min, Vector3 max)
        {
            CullResult result = CullResult.TotallyInside;

            for (int i = 0; i < 6; i++)
            {
                // Calc the two vertices we need to test against.
                Vector3 pVertex;
                Vector3 nVertex;
                if (planes[i].X < 0)
                {
                    pVertex.X = min.X;
                    nVertex.X = max.X;
                }
                else
                {
                    pVertex.X = max.X;
                    nVertex.X = min.X;
                }
                if (planes[i].Y < 0)
                {
                    pVertex.Y = min.Y;
                    nVertex.Y = max.Y;
                }
                else
                {
                    pVertex.Y = max.Y;
                    nVertex.Y = min.Y;
                }
                if (planes[i].Z < 0)
                {
                    pVertex.Z = min.Z;
                    nVertex.Z = max.Z;
                }
                else
                {
                    pVertex.Z = max.Z;
                    nVertex.Z = min.Z;
                }

                // Check for totally outside case.
                float dist = pVertex.X * planes[i].X + pVertex.Y * planes[i].Y + pVertex.Z * planes[i].Z + planes[i].W;
                if (dist < 0)
                {
                    result = CullResult.TotallyOutside;
                    break;
                }

                // Check for box intersecting plane case.
                dist = nVertex.X * planes[i].X + nVertex.Y * planes[i].Y + nVertex.Z * planes[i].Z + planes[i].W;
                if (dist < 0 )
                {
                    result = CullResult.PartiallyInside;
                }

            }   // end of loop over frustum planes.

            return result;
        }   // end of Frustum CullTest()
 public void EndCull(CullRequest cullRequest, CullResult cullResults)
 {
     m_DecalsVisibleThisFrame = QueryCullResults(cullRequest, cullResults);
     foreach (var pair in m_DecalSets)
     {
         pair.Value.EndCull(cullRequest[pair.Key]);
     }
 }
        private int QueryCullResults(CullRequest decalCullRequest, CullResult cullResults)
        {
            var totalVisibleDecals = 0;

            foreach (var pair in m_DecalSets)
            {
                totalVisibleDecals += pair.Value.QueryCullResults(decalCullRequest[pair.Key], cullResults[pair.Key]);
            }
            return(totalVisibleDecals);
        }
        public void LoadCullResults(CullResult cullResult)
        {
            foreach (var pair in cullResult)
            {
                if (!m_DecalSets.TryGetValue(pair.Key, out var decalSet))
                {
                    continue;
                }

                decalSet.SetCullResult(pair.Value);
            }
        }
Beispiel #5
0
    private static string GetCullText(CullResult result)
    {
        switch (result)
        {
        case CullResult.NotCulled:
            return(string.Empty);

        case CullResult.ClipRectIsZero:
            return("[Culled - Fully Clipped]");

        case CullResult.ActualSizeZero:
            return("[Culled - Size is zero]");

        case CullResult.OpacityZero:
            return("[Culled - Opacity is zero]");

        case CullResult.VisibilityHidden:
            return("[Culled - Visibility Hidden]");

        default:
            throw new ArgumentOutOfRangeException(nameof(result), result, null);
        }
    }
Beispiel #6
0
        }   // end of Frustum CullTest()

        /// <summary>
        /// Test a sphere against the frustum.
        /// </summary>
        public CullResult CullTest(Vector3 center, float radius)
        {
            CullResult result = CullResult.TotallyInside;

            float dist;
            for (int i = 0; i < 6; ++i)
            {
                // Calc the distance to the plane.
                dist = planes[i].X * center.X + planes[i].Y * center.Y + planes[i].Z * center.Z + planes[i].W;

                if (dist < -radius)         // If sphere is outside and we can exit.
                {
                    result = CullResult.TotallyOutside;
                    break;
                }
                else if (dist < radius)     // If sphere intersects plane, change result to
                {                           // partial but keep looking for full exclusion.
                    result = CullResult.PartiallyInside;
                }
            }

            return result;
        }   // end of Frustum CullTest()
Beispiel #7
0
        public CullResult CullTriangles(Vertex[] vertexs, List<int[]> trianglesIndex, CullPlane cullPlanes)
        {
            foreach (int[] indexs in trianglesIndex)
            {
                Vertex[] t = new Vertex[3];
                int index1 = indexs[0];
                t[0] = vertexs[index1];
                int index2 = indexs[1];
                t[1] = vertexs[index2];
                int index3 = indexs[2];
                t[2] = vertexs[index3];
                cullTriangles.Add(t);
            }

            foreach (Plane p in cullPlanes.getCullPlanes())
            {
                Vertex[][] triAry = cullTriangles.ToArray();
                int length = triAry.Length;

                cullTriangles.Clear();
                cullTrianglesCache.Clear();

                for (int i = 0; i < triAry.Length; i++)
                {
                    cullTriangle(triAry[i], p);
                }
                List<Vertex> newVertex1 = new List<Vertex>();

                foreach (Vertex[] t in cullTriangles)
                {
                    if (!newVertex1.Contains(t[0]))
                        newVertex1.Add(t[0]);
                    if (!newVertex1.Contains(t[1]))
                        newVertex1.Add(t[1]);
                    if (!newVertex1.Contains(t[2]))
                        newVertex1.Add(t[2]);
                }

                int vertexCount = newVertex1.Count;
            }

            List<Vertex> newVertex = new List<Vertex>();

            foreach (Vertex[] t in cullTriangles)
            {
                if (!newVertex.Contains(t[0]))
                    newVertex.Add(t[0]);
                if (!newVertex.Contains(t[1]))
                    newVertex.Add(t[1]);
                if (!newVertex.Contains(t[2]))
                    newVertex.Add(t[2]);
            }

            vertexs = newVertex.ToArray();
            trianglesIndex = new List<int[]>();

            foreach(Vertex[] t in cullTriangles)
            {
                int[] indexs = new int[3];
                indexs[0] = newVertex.IndexOf(t[0]);
                indexs[1] = newVertex.IndexOf(t[1]);
                indexs[2] = newVertex.IndexOf(t[2]);
                trianglesIndex.Add(indexs);
            }

            CullResult result = new CullResult();
            result.vertexs = vertexs;
            result.trianglesIndex = trianglesIndex;

            return result;
        }