Exemple #1
0
        public static bool BoundSpereInCamera_UseMVP(SoftSpere spere, SoftCamera camera)
        {
            Vector3 localPt = camera.WorldToViewportPoint(spere.position, false);

            float left  = localPt.x - spere.radius;
            float right = localPt.x + spere.radius;

            if (right <= -1 || left >= 1)
            {
                return(false);
            }

            float top    = localPt.y + spere.radius;
            float bottom = localPt.y - spere.radius;

            if (bottom >= 1 || top <= -1)
            {
                return(false);
            }

            float front = localPt.z + spere.radius;
            float back  = localPt.z - spere.radius;

            if (back >= 1 || front <= -1)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        // 摄影机剔除
        // visiableList: 可见列表
        public void CameraCull(SoftCamera camera, Dictionary <int, SoftRenderObject> objs, out NativeList <int> visiableList)
        {
            visiableList = null;
            if (camera == null)
            {
                return;
            }
            if (objs == null || objs.Count <= 0)
            {
                m_Objs.Clear(false);
                return;
            }

            m_Objs.Clear(false);
            // 简单处理,直接干
            var iter = objs.GetEnumerator();

            while (iter.MoveNext())
            {
                SoftRenderObject obj = iter.Current.Value;
                if (obj != null && obj.CanRenderer)
                {
                    switch (obj.ObjType)
                    {
                    case SoftRenderObjType.MeshRender:
                        SoftSpere spere = (obj as SoftMeshRenderer).WorldBoundSpere;
                        // if (!camera.IsOpenCameraSpereCull || SoftMath.BoundSpereInCamera(spere, camera)) {
                        if (!camera.IsOpenCameraSpereCull || SoftMath.BoundSpereInCamera_UseMVP(spere, camera))
                        {
                            m_Objs.Add(obj.InstanceId);
                        }
                        break;
                    }
                }
            }
            iter.Dispose();
            if (m_Objs.Count > 0)
            {
                visiableList = m_Objs;
            }
        }