예제 #1
0
        /// <summary>
        /// Traverses the specified graph path</summary>
        /// <param name="graphPath">The graph path</param>
        /// <param name="action">The render action</param>
        /// <param name="camera">The camera</param>
        /// <param name="list">The list</param>
        /// <returns></returns>
        public override TraverseState Traverse(Stack<SceneNode> graphPath, IRenderAction action, Camera camera, ICollection<TraverseNode> list)
        {
            // Get the "top matrix" before we push a new matrix on to it, just in case we need
            //  it for the bounding box test.
            Matrix4F parentToWorld = action.TopMatrix;

            // Push matrix onto the matrix stack even if we're not visible because this class
            //  implements the marker interface ISetsLocalTransform.
            action.PushMatrix(m_node.Transform, true);

            // If node is invisible then cull
            if (!m_node.Visible)
                return TraverseState.Cull;

            TraverseState dResult = action.TraverseState;
            if (dResult == TraverseState.None)
            {
                // Test if bounding sphere is contained in frustum
                if (s_enableVFCull)
                {
                    // Construct bounding box
                    Box box = new Box();
                    box.Extend(m_node.BoundingBox);

                    // Transform the bounding box into view space
                    Matrix4F localToView = Matrix4F.Multiply(parentToWorld, camera.ViewMatrix);
                    box.Transform(localToView);

                    if (!camera.Frustum.Contains(box))
                        dResult = TraverseState.Cull;
                }
            }
            return dResult;
        }
예제 #2
0
        /// <summary>
        /// Traverses the specified graph path</summary>
        /// <param name="graphPath">The graph path</param>
        /// <param name="action">The render action</param>
        /// <param name="camera">The camera</param>
        /// <param name="list">The list</param>
        /// <returns></returns>
        public override TraverseState Traverse(Stack <SceneNode> graphPath, IRenderAction action, Camera camera, ICollection <TraverseNode> list)
        {
            // Get the "top matrix" before we push a new matrix on to it, just in case we need
            //  it for the bounding box test.
            Matrix4F parentToWorld = action.TopMatrix;

            // Push matrix onto the matrix stack even if we're not visible because this class
            //  implements the marker interface ISetsLocalTransform.
            action.PushMatrix(m_node.Transform, true);

            // If node is invisible then cull
            if (!m_node.Visible)
            {
                return(TraverseState.Cull);
            }

            TraverseState dResult = action.TraverseState;

            if (dResult == TraverseState.None)
            {
                // Test if bounding sphere is contained in frustum
                if (s_enableVFCull)
                {
                    // Construct bounding box
                    Box box = new Box();
                    box.Extend(m_node.BoundingBox);

                    // Transform the bounding box into view space
                    Matrix4F localToView = Matrix4F.Multiply(parentToWorld, camera.ViewMatrix);
                    box.Transform(localToView);

                    if (!camera.Frustum.Contains(box))
                    {
                        dResult = TraverseState.Cull;
                    }
                }
            }
            return(dResult);
        }
예제 #3
0
        // For 'action', first set the TypeFilter and call Init. If picking is true and pickManipulatorOnly
        // is true, then only the currently active manipulator is tested against, which is a huge speed-up.
        private void Render(IRenderAction action, bool picking, bool pickManipulatorOnly)
        {
            base.BeginPaint(picking);

            action.Title          = Camera.ViewTypeName;
            action.ViewportWidth  = Width;
            action.ViewportHeight = Height;

            // If we're doing a picking operation, then we don't need to display the results to the user, etc.
            if (picking)
            {
                RenderState pickState = new RenderState(m_renderState);
                pickState.RenderMode        &= ~(RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha);
                pickState.OverrideChildState = RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha;
                pickState.InheritState       = 0;

                RenderStateGuardian.Reset();

                // Manipulator picking can be further optimized to only render the manipulator.
                if (pickManipulatorOnly &&
                    m_manipulator != null &&
                    m_manipulatorNode != null)
                {
                    // Replace the scene node's children temporarily with just our one child of interest.
                    // Replacing the children is easier than creating a new Scene because the manipulators
                    //  need the HitRecord.GraphPath to have the full correct Scene, not a temp Scene.
                    List <SceneNode> originalChildren = new List <SceneNode>(m_scene.Children);
                    m_scene.Children.Clear();
                    m_scene.Children.Add(m_manipulatorNode);

                    m_scene.StateStack.Push(pickState);
                    action.PushMatrix(m_manipulatorParentToWorld, false);
                    action.Dispatch(m_scene, Camera);
                    action.PopMatrix();
                    m_scene.StateStack.Pop();

                    m_scene.Children.Clear();
                    foreach (SceneNode node in originalChildren)
                    {
                        m_scene.Children.Add(node);
                    }
                }
                else
                {   //Regular picking. Render the whole scene.
                    m_scene.StateStack.Push(pickState);
                    action.Dispatch(m_scene, Camera);
                    m_scene.StateStack.Pop();
                }

                // When picking, we don't want to display this buffer, so don't swap OpenGl buffers.
                // This property gets reset by base.EndPaint().
                SwapBuffers = false;
            }
            else
            {
                m_scene.StateStack.Push(m_renderState);
                RenderStateGuardian.Reset();
                action.Dispatch(m_scene, Camera);
                RenderAxisSystem(action);
                m_scene.StateStack.Pop();
            }

            base.EndPaint();
        }
예제 #4
0
        // For 'action', first set the TypeFilter and call Init. If picking is true and pickManipulatorOnly
        // is true, then only the currently active manipulator is tested against, which is a huge speed-up.
        private void Render(IRenderAction action, bool picking, bool pickManipulatorOnly)
        {
            base.BeginPaint(picking);

            action.Title = Camera.ViewTypeName;
            action.ViewportWidth = Width;
            action.ViewportHeight = Height;
            
            // If we're doing a picking operation, then we don't need to display the results to the user, etc.
            if (picking)
            {
                RenderState pickState = new RenderState(m_renderState);
                pickState.RenderMode &= ~(RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha);
                pickState.OverrideChildState = RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha;
                pickState.InheritState = 0;

                RenderStateGuardian.Reset();

                // Manipulator picking can be further optimized to only render the manipulator.
                if (pickManipulatorOnly &&
                    m_manipulator != null &&
                    m_manipulatorNode != null)
                {
                    // Replace the scene node's children temporarily with just our one child of interest.
                    // Replacing the children is easier than creating a new Scene because the manipulators
                    //  need the HitRecord.GraphPath to have the full correct Scene, not a temp Scene.
                    List<SceneNode> originalChildren = new List<SceneNode>(m_scene.Children);
                    m_scene.Children.Clear();
                    m_scene.Children.Add(m_manipulatorNode);

                    m_scene.StateStack.Push(pickState);
                    action.PushMatrix(m_manipulatorParentToWorld, false);
                    action.Dispatch(m_scene, Camera);
                    action.PopMatrix();
                    m_scene.StateStack.Pop();

                    m_scene.Children.Clear();
                    foreach (SceneNode node in originalChildren)
                        m_scene.Children.Add(node);
                }
                else
                {   //Regular picking. Render the whole scene.
                    m_scene.StateStack.Push(pickState);
                    action.Dispatch(m_scene, Camera);
                    m_scene.StateStack.Pop();
                }

                // When picking, we don't want to display this buffer, so don't swap OpenGl buffers.
                // This property gets reset by base.EndPaint().
                SwapBuffers = false;
            }
            else
            {
                m_scene.StateStack.Push(m_renderState);
                RenderStateGuardian.Reset();
                action.Dispatch(m_scene, Camera);
                RenderAxisSystem(action);
                m_scene.StateStack.Pop();
            }

            base.EndPaint();
        }