Exemple #1
0
        private void FrustumCullList(FFrustum frustum, List <IRenderable> sourceList, List <IRenderable> outputList)
        {
            for (int i = 0; i < sourceList.Count; i++)
            {
                Halfspace contains = frustum.ContainsSphere(sourceList[i].GetPosition(), sourceList[i].GetBoundingRadius());

                if (contains != Halfspace.Negative)
                {
                    outputList.Add(sourceList[i]);
                }
            }
        }
Exemple #2
0
        public void DrawFrame()
        {
            ResetGraphicsState();

            int x      = (int)(m_viewportRect.X * m_viewWidth);
            int y      = (int)(m_viewportRect.Y * m_viewHeight);
            int width  = (int)(m_viewportRect.Width * m_viewWidth);
            int height = (int)(m_viewportRect.Height * m_viewHeight);

            GL.Viewport(x, y, width, height);
            GL.Scissor(x, y, width, height);

            GL.ClearColor(m_viewportRect.X, m_viewportRect.Y, m_viewportRect.Width, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 viewMatrix, projMatrix;

            GetViewAndProjMatrixForView(out viewMatrix, out projMatrix);
            FFrustum frustum = new FFrustum(ref viewMatrix, ref projMatrix);

            // Resize our list if needed.
            m_renderablesInFrustum.Clear();
            m_renderablesInFrustum.Capacity = Math.Max(m_opaqueRenderList.Count, m_transparentRenderList.Count);

            FrustumCullList(frustum, m_opaqueRenderList, m_renderablesInFrustum);

            // Render all Opaque Geometry first.
            foreach (var mesh in m_renderablesInFrustum)
            {
                mesh.Draw(this);
            }

            // Now cull us against translucent geometry.
            m_renderablesInFrustum.Clear();
            FrustumCullList(frustum, m_transparentRenderList, m_renderablesInFrustum);

            // Render all Transparent Geometry afterwards. ToDo: depth-sort this first.
            foreach (var mesh in m_renderablesInFrustum)
            {
                mesh.Draw(this);
            }

            DrawOrientationWidget(x, y, viewMatrix, projMatrix);
            ResetGraphicsState();
        }
Exemple #3
0
        public FRay ProjectScreenToWorld(Vector2 mousePosition)
        {
            FRect viewportDimensions = GetViewportDimensions();

            mousePosition.X -= viewportDimensions.X;
            mousePosition.Y -= viewportDimensions.Y;

            Vector3 mouseViewportA = new Vector3(mousePosition.X / viewportDimensions.Width, mousePosition.Y / viewportDimensions.Height, 0f);
            Vector3 mouseViewportB = new Vector3(mousePosition.X / viewportDimensions.Width, mousePosition.Y / viewportDimensions.Height, 1f);

            Vector4 nearUnproj = FFrustum.UnProject(m_viewCamera.ProjectionMatrix, m_viewCamera.ViewMatrix, mouseViewportA);
            Vector4 farUnproj  = FFrustum.UnProject(m_viewCamera.ProjectionMatrix, m_viewCamera.ViewMatrix, mouseViewportB);

            Vector3 dir = farUnproj.Xyz - nearUnproj.Xyz;

            dir.Normalize();

            return(new FRay(nearUnproj.Xyz, dir));
        }
Exemple #4
0
        public void DrawFrame()
        {
            ResetGraphicsState();

            int x      = (int)(m_viewportRect.X * m_viewWidth);
            int y      = (int)(m_viewportRect.Y * m_viewHeight);
            int width  = (int)(m_viewportRect.Width * m_viewWidth);
            int height = (int)(m_viewportRect.Height * m_viewHeight);

            GL.Viewport(x, y, width, height);
            GL.Scissor(x, y, width, height);

            GL.ClearColor(m_viewportRect.X, m_viewportRect.Y, m_viewportRect.Width, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 viewMatrix, projMatrix;

            GetViewAndProjMatrixForView(out viewMatrix, out projMatrix);
            FFrustum frustum = new FFrustum(ref viewMatrix, ref projMatrix);

            // Resize our list if needed.
            m_renderablesInFrustum.Clear();
            m_renderablesInFrustum.Capacity = Math.Max(m_opaqueRenderList.Count, m_transparentRenderList.Count);

            FrustumCullList(frustum, m_opaqueRenderList, m_renderablesInFrustum);
            //m_renderablesInFrustum = new List<IRenderable>(m_opaqueRenderList);

            foreach (var mesh in m_renderablesInFrustum)
            {
                if (mesh.GetType() == typeof(WSkyboxNode))
                {
                    mesh.Draw(this);
                    break;
                }
            }

            // Render all Opaque Geometry first.
            foreach (var mesh in m_renderablesInFrustum)
            {
                if (mesh is WDOMNode)
                {
                    WDOMNode node = (WDOMNode)mesh;
                    if (mesh.GetType() != typeof(WSkyboxNode) && node.IsRendered)
                    {
                        float dist = (mesh.GetPosition() - GetCameraPos()).Length;

                        if (dist < MaxDist || mesh.GetType() == typeof(J3DNode))
                        {
                            mesh.Draw(this);
                        }
                    }
                }
                else
                {
                    mesh.Draw(this);
                }
            }

            // Now cull us against translucent geometry.
            m_renderablesInFrustum.Clear();
            FrustumCullList(frustum, m_transparentRenderList, m_renderablesInFrustum);

            // Render all Transparent Geometry afterwards. ToDo: depth-sort this first.
            foreach (var mesh in m_renderablesInFrustum)
            {
                if (mesh is WDOMNode)
                {
                    WDOMNode node = (WDOMNode)mesh;
                    if (node.IsRendered)
                    {
                        mesh.Draw(this);
                    }
                }
                else
                {
                    mesh.Draw(this);
                }
            }

            DrawOrientationWidget(x, y, viewMatrix, projMatrix);
            ResetGraphicsState();
        }