Example #1
0
        private void UpdateGeometry()
        {
            m_GridResolution = GeomUtil3D.GetGridResolution(m_CellArc, m_MaxDistance);
            m_LonLatRect     = GeomUtil3D.GetLonLatRect(m_CellArc,
                                                        m_LonAngle, m_LatAngleSouth, m_LatAngleNorth,
                                                        out int nLon, out int nLat);

            UpdateGridSize(nLon, nLat);
            UpdateResolutionInfo();
        }
Example #2
0
        /// <inheritdoc/>
        public override bool ContainsPoint(Vector3 localPoint, out Vector3 normPoint)
        {
            float radiusSqr = localPoint.sqrMagnitude;

            if (radiusSqr >= m_MinRadiusSqr && radiusSqr <= m_MaxRadiusSqr)
            {
                Vector2 lonLat = GeomUtil3D.GetLonLat(localPoint);
                if (LonLatRect.Contains(lonLat))
                {
                    normPoint = Rect.PointToNormalized(LonLatRect, lonLat);
                    // 0 (near) to 1 (far)
                    normPoint.z = Mathf.Clamp01((Mathf.Sqrt(radiusSqr) - m_MinRadius) / m_Range);
                    return(true);
                }
            }

            normPoint = default;
            return(false);
        }
        private void ValidateCullingEnabled()
        {
            m_CullingEnabled = GeomUtil3D.HasValidFrustum(m_Constraint.LonLatRect,
                                                          Mathf.Max(m_Constraint.MinRadius, 0.01f), m_Constraint.MaxRadius,
                                                          out Frustum frustum);

            if (m_CullingEnabled)
            {
                // Create a helper camera for valid frustum,
                // so we can cull the found colliders before the
                // detector has to parse all their shape points.

                var nested = m_Transform.Find("HelperCam");
                if (nested == null)
                {
                    nested = new GameObject("HelperCam").transform;
                    // Cam frustum does update even with disabled
                    // camera component and inactive gameobject.
                    nested.gameObject.SetActive(false);
                    nested.parent        = m_Transform;
                    nested.localPosition = Vector3.zero;

                    m_Camera = nested.gameObject.AddComponent <Camera>();
                    m_Camera.transform.localRotation = Quaternion.identity;
                    m_Camera.cullingMask             = m_LayerMask;
                    m_Camera.enabled = false;
                }
                else
                {
                    m_Camera = nested.GetComponent <Camera>();
                }

                m_Camera.nearClipPlane    = frustum.Near;
                m_Camera.farClipPlane     = frustum.Far;
                m_Camera.projectionMatrix = GeomUtil3D.GetProjectionMatrix(frustum);

                m_ColliderBufferSet = new HashSet <Collider>();
                m_Planes            = new Plane[6];
            }
        }
Example #4
0
        private void DrawWireFrame()
        {
            GeomUtil3D.CalcGridRotations(m_Comp.CellArc,
                                         m_Comp.LonLatRect, m_Comp.GridShape,
                                         ref m_Wireframe);

            EditorUtil.GLMaterial.SetPass(0);

            GL.PushMatrix();
            GL.MultMatrix(m_Comp.transform.localToWorldMatrix);

            Vector3 min = Vector3.forward * m_Comp.MinDistance;
            Vector3 max = Vector3.forward * m_Comp.MaxDistance;

            // Grid Cells

            int nLon = m_Comp.GridShape.Width;
            int nLat = m_Comp.GridShape.Height;

            for (int iLat = 0; iLat <= nLat; iLat++)
            {
                GL.Begin(GL.LINE_STRIP);
                GL.Color(s_WireColorA);
                for (int iLon = 0; iLon <= nLon; iLon++)
                {
                    var v = m_Wireframe[iLon, iLat] * max;
                    GL.Vertex3(v.x, v.y, v.z);
                }
                GL.End();
            }

            for (int iLon = 0; iLon <= nLon; iLon++)
            {
                GL.Begin(GL.LINE_STRIP);
                GL.Color(s_WireColorA);
                for (int iLat = 0; iLat <= nLat; iLat++)
                {
                    var v = m_Wireframe[iLon, iLat] * max;
                    GL.Vertex3(v.x, v.y, v.z);
                }
                GL.End();
            }

            // Angles

            if (m_Comp.LatAngleSouth < 90)
            {
                GL.Begin(GL.LINES);
                GL.Color(s_WireColorB);
                for (int iLon = 0; iLon <= nLon; iLon++)
                {
                    var a = m_Wireframe[iLon, 0] * min;
                    GL.Vertex3(a.x, a.y, a.z);
                    var b = m_Wireframe[iLon, 0] * max;
                    GL.Vertex3(b.x, b.y, b.z);
                }
                GL.End();
            }

            if (m_Comp.LatAngleNorth < 90)
            {
                GL.Begin(GL.LINES);
                GL.Color(s_WireColorB);
                for (int iLon = 0; iLon <= nLon; iLon++)
                {
                    var a = m_Wireframe[iLon, nLat] * min;
                    GL.Vertex3(a.x, a.y, a.z);
                    var b = m_Wireframe[iLon, nLat] * max;
                    GL.Vertex3(b.x, b.y, b.z);
                }
                GL.End();
            }

            if (m_Comp.LonAngle < 180)
            {
                GL.Begin(GL.LINES);
                GL.Color(s_WireColorB);
                for (int iLat = 0; iLat <= nLat; iLat++)
                {
                    var a = m_Wireframe[0, iLat] * min;
                    GL.Vertex3(a.x, a.y, a.z);
                    var b = m_Wireframe[0, iLat] * max;
                    GL.Vertex3(b.x, b.y, b.z);
                }
                GL.End();

                GL.Begin(GL.LINES);
                GL.Color(s_WireColorB);
                for (int iLat = 0; iLat <= nLat; iLat++)
                {
                    var a = m_Wireframe[nLon, iLat] * min;
                    GL.Vertex3(a.x, a.y, a.z);
                    var b = m_Wireframe[nLon, iLat] * max;
                    GL.Vertex3(b.x, b.y, b.z);
                }
                GL.End();
            }

            GL.PopMatrix();
        }