Esempio n. 1
0
        private void RenderUnderLight(SceneNodeBase sceneNodeBase, ShadowMappingUnderLightEventArgs arg)
        {
            if (sceneNodeBase != null)
            {
                var      node     = sceneNodeBase as ISupportShadowMapping;
                TwoFlags flags    = (node != null) ? node.EnableShadowMapping : TwoFlags.None;
                bool     before   = (node != null) && ((flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren);
                bool     children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);

                if (before)
                {
                    flags  = node.EnableRenderUnderLight;
                    before = (flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren;
                }

                if (children)
                {
                    flags    = (node != null) ? node.EnableRenderUnderLight : TwoFlags.None;
                    children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);
                }

                if (before)
                {
                    node.RenderUnderLight(arg);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        RenderUnderLight(item, arg);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sceneNodeBase"></param>
        /// <param name="arg"></param>
        static void Extrude(SceneNodeBase sceneNodeBase, ShadowVolumeExtrudeEventArgs arg)
        {
            if (sceneNodeBase != null)
            {
                var      node     = sceneNodeBase as ISupportShadowVolume;
                TwoFlags flags    = (node != null) ? node.EnableShadowVolume : TwoFlags.None;
                bool     before   = (node != null) && ((flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren);
                bool     children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);

                if (before)
                {
                    flags  = node.EnableExtrude;
                    before = (flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren;
                }

                if (children)
                {
                    flags    = (node != null) ? node.EnableExtrude : TwoFlags.None;
                    children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);
                }

                if (before)
                {
                    node.ExtrudeShadow(arg);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        Extrude(item, arg);
                    }
                }
            }
        }
Esempio n. 3
0
        private PickedGeometry Pick(uint stageVertexId, PickingEventArgs arg, SceneNodeBase node)
        {
            PickedGeometry pickedGeometry = null;

            if (node != null)
            {
                var pickable = node as IPickable;
                if (pickable != null)
                {
                    pickedGeometry = pickable.GetPickedGeometry(arg, stageVertexId);
                }

                if (pickedGeometry == null)
                {
                    foreach (var item in node.Children)
                    {
                        pickedGeometry = Pick(stageVertexId, arg, item);
                        if (pickedGeometry != null)
                        {
                            break;
                        }
                    }
                }
            }

            return(pickedGeometry);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sceneNodeBase"></param>
        /// <param name="arg"></param>
        public static void Render(SceneNodeBase sceneNodeBase, RenderEventArgs arg)
        {
            if (sceneNodeBase != null)
            {
                var        node     = sceneNodeBase as IRenderable;
                ThreeFlags flags    = (node != null) ? node.EnableRendering : ThreeFlags.None;
                bool       before   = (node != null) && ((flags & ThreeFlags.BeforeChildren) == ThreeFlags.BeforeChildren);
                bool       children = (node == null) || ((flags & ThreeFlags.Children) == ThreeFlags.Children);
                bool       after    = (node != null) && ((flags & ThreeFlags.AfterChildren) == ThreeFlags.AfterChildren);

                if (before)
                {
                    node.RenderBeforeChildren(arg);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        Render(item, arg);
                    }
                }

                if (after)
                {
                    node.RenderAfterChildren(arg);
                }
            }
        }
        private void ShadowMapping(SceneNodeBase sceneElement, ShdowMappingEventArgs arg)
        {
            if (sceneElement != null)
            {
                var lightContainer = sceneElement as ILocalLightContainer;
                if (lightContainer != null)
                {
                    foreach (var light in lightContainer.LightList)
                    {
                        arg.CurrentLight = light;
                        light.Begin();
                        foreach (var child in sceneElement.Children)
                        {
                            this.CastShadow(child, arg);
                        }
                        light.End();
                        arg.CurrentLight = null;
                    }
                }

                foreach (var child in sceneElement.Children)
                {
                    this.ShadowMapping(child, arg);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Sort billboards in depth order.
        /// </summary>
        /// <param name="rootNode"></param>
        /// <param name="camera"></param>
        public BillboardSortAction(SceneNodeBase rootNode, ICamera camera)
        {
            this.Far2Near = true;

            this.rootNode = rootNode;
            this.camera   = camera;
        }
Esempio n. 7
0
        private void RenderForPicking(SceneNodeBase sceneElement, LegacyPickingEventArgs arg, ref uint currentName)
        {
            if (sceneElement != null)
            {
                var        pickable = sceneElement as ILegacyPickable;
                ThreeFlags flags    = (pickable != null) ? (pickable.EnableLegacyPicking) : ThreeFlags.None;
                bool       before   = (pickable != null) && ((flags & ThreeFlags.BeforeChildren) == ThreeFlags.BeforeChildren);
                bool       children = (pickable == null) || ((flags & ThreeFlags.Children) == ThreeFlags.Children);

                if (before)
                {
                    //  Load and map the name.
                    GL.Instance.LoadName(currentName);
                    arg.hitMap[currentName] = sceneElement;

                    pickable.RenderBeforeChildrenForLegacyPicking(arg);

                    //  Increment the name.
                    currentName++;
                }

                if (children)
                {
                    foreach (var item in sceneElement.Children)
                    {
                        this.RenderForPicking(item, arg, ref currentName);
                    }
                }
            }
        }
Esempio n. 8
0
        private void RenderForPicking(SceneNodeBase sceneElement, PickingEventArgs arg)
        {
            if (sceneElement != null)
            {
                var      pickable = sceneElement as IPickable;
                TwoFlags flags    = (pickable != null) ? pickable.EnablePicking : TwoFlags.None;
                bool     before   = ((flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren);
                bool     children = (pickable == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);

                if (before)
                {
                    pickable.PickingBaseId += arg.RenderedVertexCount;
                    pickable.RenderForPicking(arg);
                    arg.RenderedVertexCount += pickable.GetVertexCount();
                }

                if (children)
                {
                    foreach (var item in sceneElement.Children)
                    {
                        this.RenderForPicking(item, arg);
                    }
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Push and calculate model matrix in legacy OpenGL.
 /// </summary>
 /// <param name="node"></param>
 public static void PushModelMatrix(this SceneNodeBase node)
 {
     GL.Instance.MatrixMode(GL.GL_MODELVIEW);
     GL.Instance.PushMatrix();
     GL.Instance.LoadIdentity();
     // note: node.modelMatrix has already been updated in Scene.Render(RendererBase sceneElement, RenderEventArgs arg);
     GL.Instance.MultMatrixf(node.cascadeModelMatrix.ToArray());
 }
Esempio n. 10
0
        /// <summary>
        /// Push and calculate projection+view matrix in legacy OpenGL for picking.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="arg"></param>
        public static void PushProjectionViewMatrix(this SceneNodeBase node, LegacyPickingEventArgs arg)
        {
            GL.Instance.MatrixMode(GL.GL_PROJECTION);
            GL.Instance.PushMatrix();
            mat4 projection = arg.pickMatrix * arg.scene.Camera.GetProjectionMatrix();
            mat4 view       = arg.scene.Camera.GetViewMatrix();

            GL.Instance.LoadIdentity();
            GL.Instance.MultMatrixf((projection * view).ToArray());
        }
Esempio n. 11
0
        /// <summary>
        /// Rotate model using arc-ball method.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="bindingMouseButtons"></param>
        public TranslateManipulater(SceneNodeBase renderer, GLMouseButtons bindingMouseButtons = GLMouseButtons.Left)
        {
            this.renderer            = renderer;
            this.MouseSensitivity    = 6.0f;
            this.BindingMouseButtons = bindingMouseButtons;

            this.mouseDownEvent  = (((IMouseHandler)this).canvas_MouseDown);
            this.mouseMoveEvent  = (((IMouseHandler)this).canvas_MouseMove);
            this.mouseUpEvent    = (((IMouseHandler)this).canvas_MouseUp);
            this.mouseWheelEvent = (((IMouseHandler)this).canvas_MouseWheel);
        }
Esempio n. 12
0
        /// <summary>
        /// Push and calculate projection+view matrix in legacy OpenGL.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="arg"></param>
        public static void PushProjectionViewMatrix(this SceneNodeBase node, RenderEventArgs arg)
        {
            GL.Instance.MatrixMode(GL.GL_PROJECTION);
            GL.Instance.PushMatrix();
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();

            GL.Instance.LoadIdentity();
            GL.Instance.MultMatrixf((projection * view).ToArray());
        }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        public RotationManipulater(SceneNodeBase rootNode, GLMouseButtons bindingMouseButtons = GLMouseButtons.Left)
        {
            this.rootNode = rootNode;

            this.HorizontalRotationFactor = 4;
            this.VerticalRotationFactor   = 4;
            this.BindingMouseButtons      = bindingMouseButtons;
            this.mouseDownEvent           = (((IMouseHandler)this).canvas_MouseDown);
            this.mouseMoveEvent           = (((IMouseHandler)this).canvas_MouseMove);
            this.mouseUpEvent             = (((IMouseHandler)this).canvas_MouseUp);
            this.mouseWheelEvent          = (((IMouseHandler)this).canvas_MouseWheel);
        }
Esempio n. 14
0
        private void Render(SceneNodeBase sceneElement, TransformEventArgs arg)
        {
            if (sceneElement != null)
            {
                mat4 parentCascadeModelMatrix = arg.ModelMatrixStack.Peek();
                sceneElement.cascadeModelMatrix = sceneElement.GetModelMatrix(parentCascadeModelMatrix);

                arg.ModelMatrixStack.Push(sceneElement.cascadeModelMatrix);
                foreach (var item in sceneElement.Children)
                {
                    this.Render(item, arg);
                }
                arg.ModelMatrixStack.Pop();
            }
        }
Esempio n. 15
0
        private void Sort(SceneNodeBase sceneElement, mat4 viewMat)
        {
            if (sceneElement != null)
            {
                var billboard = sceneElement as TextBillboardNode;
                if (billboard != null)
                {
                    Insert(billboard, viewMat);
                }

                foreach (var item in sceneElement.Children)
                {
                    this.Sort(item, viewMat);
                }
            }
        }
        private void CastShadow(SceneNodeBase sceneElement, ShdowMappingEventArgs arg)
        {
            if (sceneElement != null)
            {
                var renderable = sceneElement as IShadowMapping;
                if (renderable != null && renderable.EnableShadowMapping)
                {
                    renderable.CastShadow(arg);
                }

                foreach (var item in sceneElement.Children)
                {
                    CastShadow(item, arg);
                }
            }
        }
Esempio n. 17
0
        private void RenderAmbientColor(SceneNodeBase sceneNodeBase, ShadowVolumeAmbientEventArgs arg)
        {
            if (sceneNodeBase != null)
            {
                var      node     = sceneNodeBase as ISupportShadowVolume;
                TwoFlags flags    = (node != null) ? node.EnableShadowVolume : TwoFlags.None;
                bool     before   = (node != null) && ((flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren);
                bool     children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);

                if (before)
                {
                    node.RenderAmbientColor(arg);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        RenderAmbientColor(item, arg);
                    }
                }
            }
        }
Esempio n. 18
0
        private static void RenderAmbientColor(SceneNodeBase sceneNodeBase, BlinnPhongAmbientEventArgs arg)
        {
            if (sceneNodeBase != null)
            {
                var        node     = sceneNodeBase as IBlinnPhong;
                ThreeFlags flags    = (node != null) ? node.EnableRendering : ThreeFlags.None;
                bool       before   = (node != null) && ((flags & ThreeFlags.BeforeChildren) == ThreeFlags.BeforeChildren);
                bool       children = (node == null) || ((flags & ThreeFlags.Children) == ThreeFlags.Children);
                bool       after    = (node != null) && ((flags & ThreeFlags.AfterChildren) == ThreeFlags.AfterChildren);

                if (before || after)
                {
                    node.RenderAmbientColor(arg);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        RenderAmbientColor(item, arg);
                    }
                }
            }
        }
Esempio n. 19
0
 /// <summary>
 /// Pop projection+view matrix.
 /// </summary>
 public static void PopProjectionViewMatrix(this SceneNodeBase node)
 {
     GL.Instance.MatrixMode(GL.GL_PROJECTION);
     GL.Instance.PopMatrix();
 }
Esempio n. 20
0
 /// <summary>
 /// Pop model matrix.
 /// </summary>
 public static void PopModelMatrix(this SceneNodeBase node)
 {
     GL.Instance.MatrixMode(GL.GL_MODELVIEW);
     GL.Instance.PopMatrix();
 }
Esempio n. 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sceneElement"></param>
 /// <param name="zNear"></param>
 /// <param name="zFar"></param>
 public HitTarget(SceneNodeBase sceneElement, uint zNear, uint zFar)
 {
     this.node  = sceneElement;
     this.zNear = zNear;
     this.zFar  = zFar;
 }
Esempio n. 22
0
 /// <summary>
 /// Render <see cref="IWorldSpace"/> objects.
 /// </summary>
 /// <param name="rootNode"></param>
 public TransformAction(SceneNodeBase rootNode)
 {
     this.rootNode = rootNode;
 }