예제 #1
0
        private void RenderForPicking(RendererBase sceneElement, PickEventArgs arg)
        {
            if (sceneElement != null)
            {
                mat4 parentCascadeModelMatrix = arg.ModelMatrixStack.Peek();
                sceneElement.cascadeModelMatrix = sceneElement.GetModelMatrix(parentCascadeModelMatrix);

                var      pickable = sceneElement as IPickable;
                TwoFlags flags    = (pickable != null) ? pickable.EnablePicking : TwoFlags.None;
                bool     before   = (pickable != null) && ((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)
                {
                    arg.ModelMatrixStack.Push(sceneElement.cascadeModelMatrix);
                    foreach (var item in sceneElement.Children)
                    {
                        this.RenderForPicking(item, arg);
                    }
                    arg.ModelMatrixStack.Pop();
                }
            }
        }
예제 #2
0
        private PickedGeometry Pick(uint stageVertexId, PickEventArgs arg, RendererBase renderer)
        {
            PickedGeometry pickedGeometry = null;

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

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

            return(pickedGeometry);
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="clear"></param>
 /// <param name="clearColor"></param>
 /// <param name="rootElement"></param>
 public RenderAction(bool clear, vec4 clearColor, RendererBase rootElement, ICamera camera)
 {
     this.Clear       = clear;
     this.ClearColor  = clearColor;
     this.RootElement = rootElement;
     this.Camera      = camera;
 }
예제 #4
0
 /// <summary>
 /// Gets a <see cref="SceneObject"/> that contains this renderer.
 /// </summary>
 /// <param name="renderer"></param>
 /// <param name="name"></param>
 /// <param name="scripts"></param>
 /// <returns></returns>
 public static SceneObject WrapToSceneObject(
     this RendererBase renderer,
     string name,
     params Script[] scripts)
 {
     return(WrapToSceneObject(renderer, name, false, scripts));
 }
예제 #5
0
        public static void Render(RendererBase sceneElement, RenderEventArgs arg)
        {
            if (sceneElement != null)
            {
                mat4 parentCascadeModelMatrix = arg.ModelMatrixStack.Peek();
                sceneElement.cascadeModelMatrix = sceneElement.GetModelMatrix(parentCascadeModelMatrix);

                var        renderable = sceneElement as IRenderable;
                ThreeFlags flags      = (renderable != null) ? renderable.EnableRendering : ThreeFlags.None;
                bool       before     = (renderable != null) && ((flags & ThreeFlags.BeforeChildren) == ThreeFlags.BeforeChildren);
                bool       children   = (renderable == null) || ((flags & ThreeFlags.Children) == ThreeFlags.Children);
                bool       after      = (renderable != null) && ((flags & ThreeFlags.AfterChildren) == ThreeFlags.AfterChildren);

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

                if (children)
                {
                    arg.ModelMatrixStack.Push(sceneElement.cascadeModelMatrix);
                    foreach (var item in sceneElement.Children)
                    {
                        RenderAction.Render(item, arg);
                    }
                    arg.ModelMatrixStack.Pop();
                }

                if (after)
                {
                    renderable.RenderAfterChildren(arg);
                }
            }
        }
예제 #6
0
 /// <summary>
 /// Push and calculate model matrix in legacy OpenGL.
 /// </summary>
 /// <param name="renderer"></param>
 public static void PushModelMatrix(this RendererBase renderer)
 {
     GL.Instance.MatrixMode(GL.GL_MODELVIEW);
     GL.Instance.PushMatrix();
     GL.Instance.LoadIdentity();
     // note: renderer.modelMatrix has already been updated in Scene.Render(RendererBase sceneElement, RenderEventArgs arg);
     GL.Instance.MultMatrixf(renderer.cascadeModelMatrix.ToArray());
 }
예제 #7
0
        /// <summary>
        /// Gets a <see cref="SceneObject"/> that contains this renderer.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="scripts"></param>
        /// <returns></returns>
        public static SceneObject WrapToSceneObject(
            this RendererBase renderer,
            params Script[] scripts)
        {
            string name = string.Format("{0}", renderer);

            return(WrapToSceneObject(renderer, name, false, scripts));
        }
예제 #8
0
        /// <summary>
        /// Gets a <see cref="SceneObject"/> that contains this renderer.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="generateBoundingBox"></param>
        /// <param name="scripts"></param>
        /// <returns></returns>
        public static SceneObject WrapToSceneObject(
            this RendererBase renderer,
            bool generateBoundingBox,
            params Script[] scripts)
        {
            string name = string.Format("{0}", renderer);

            return(WrapToSceneObject(renderer, name, generateBoundingBox, scripts));
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        protected override void DisposeUnmanagedResources()
        {
            RendererBase renderer = this.Renderer;

            if (renderer != null)
            {
                renderer.Dispose();
            }
        }
예제 #10
0
        ///// <summary>
        ///// Occurs before this object and all of its children's rendering.
        ///// </summary>
        //public event EventHandler BeforeRendering;

        ///// <summary>
        ///// Occurs before this object and all of its children's rendering.
        ///// </summary>
        //internal void DoBeforeRendering()
        //{
        //    EventHandler handler = this.BeforeRendering;
        //    if (handler != null)
        //    {
        //        handler(this, new EventArgs());
        //    }
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        public void Render(RenderEventArgs arg)
        {
            RendererBase renderer = this.Renderer;

            if (renderer != null)
            {
                renderer.Render(arg);
            }
        }
예제 #11
0
        /// <summary>
        /// Push and calculate projection+view matrix in legacy OpenGL for picking.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="arg"></param>
        public static void PushProjectionViewMatrix(this RendererBase renderer, LegacyPickEventArgs 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());
        }
예제 #12
0
        /// <summary>
        /// Rotate model using arc-ball method.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="bindingMouseButtons"></param>
        public TranslateManipulater(RendererBase renderer, MouseButtons bindingMouseButtons = MouseButtons.Left)
        {
            this.renderer = renderer;
            this.MouseSensitivity = 6.0f;
            this.BindingMouseButtons = bindingMouseButtons;

            this.mouseDownEvent = new MouseEventHandler(((IMouseHandler)this).canvas_MouseDown);
            this.mouseMoveEvent = new MouseEventHandler(((IMouseHandler)this).canvas_MouseMove);
            this.mouseUpEvent = new MouseEventHandler(((IMouseHandler)this).canvas_MouseUp);
            this.mouseWheelEvent = new MouseEventHandler(((IMouseHandler)this).canvas_MouseWheel);
        }
예제 #13
0
        /// <summary>
        /// Push and calculate projection+view matrix in legacy OpenGL.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="arg"></param>
        public static void PushProjectionViewMatrix(this RendererBase renderer, RenderEventArgs arg)
        {
            GL.Instance.MatrixMode(GL.GL_PROJECTION);
            GL.Instance.PushMatrix();
            ICamera camera     = arg.CameraStack.Peek();
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();

            GL.Instance.LoadIdentity();
            GL.Instance.MultMatrixf((projection * view).ToArray());
        }
예제 #14
0
        /// <summary>
        /// Rotate model using arc-ball method.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="bindingMouseButtons"></param>
        public TranslateManipulater(RendererBase renderer, MouseButtons bindingMouseButtons = MouseButtons.Left)
        {
            this.renderer            = renderer;
            this.MouseSensitivity    = 6.0f;
            this.BindingMouseButtons = bindingMouseButtons;

            this.mouseDownEvent  = new MouseEventHandler(((IMouseHandler)this).canvas_MouseDown);
            this.mouseMoveEvent  = new MouseEventHandler(((IMouseHandler)this).canvas_MouseMove);
            this.mouseUpEvent    = new MouseEventHandler(((IMouseHandler)this).canvas_MouseUp);
            this.mouseWheelEvent = new MouseEventHandler(((IMouseHandler)this).canvas_MouseWheel);
        }
예제 #15
0
        /// <summary>
        /// Gets a <see cref="SceneObject"/> that contains this renderer.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="name"></param>
        /// <param name="scripts"></param>
        /// <returns></returns>
        public static SceneObject WrapToSceneObject(
            this RendererBase renderer,
            string name, params Script[] scripts)
        {
            var obj = new SceneObject();

            obj.Renderer = renderer;
            obj.Name     = string.IsNullOrEmpty(name) ? string.Format("{0}", renderer) : name;
            obj.ScriptList.AddRange(scripts);

            return(obj);
        }
예제 #16
0
        /// <summary>
        ///
        /// </summary>
        protected override void DoInitialize()
        {
            this.viewportState    = new ViewportState();
            this.scissorTestState = new ScissorTestState();

            RendererBase renderer = this.Renderer;

            if (renderer != null)
            {
                renderer.Initialize();
            }
        }
예제 #17
0
        /// <summary>
        /// Render something.
        /// </summary>
        /// <param name="arg"></param>
        protected virtual void DoRender(RenderEventArgs arg)
        {
            if (this.locationUpdated)
            {
                this.viewportState.X    = this.Location.X;
                this.viewportState.Y    = this.Location.Y;
                this.scissorTestState.X = this.Location.X;
                this.scissorTestState.Y = this.Location.Y;
                this.locationUpdated    = false;
            }

            if (this.sizeUpdated)
            {
                this.viewportState.Width     = this.Size.Width;
                this.viewportState.Height    = this.Size.Height;
                this.scissorTestState.Width  = this.Size.Width;
                this.scissorTestState.Height = this.Size.Height;
                this.sizeUpdated             = false;
            }

            this.viewportState.On();
            this.scissorTestState.On();
            int count = this.stateList.Count;

            for (int i = 0; i < count; i++)
            {
                this.stateList[i].On();
            }

            if (this.ClearDepthBuffer)
            {
                // 把所有在此之前渲染的内容都推到最远。
                // Push all rendered stuff to farest position.
                OpenGL.Clear(OpenGL.GL_DEPTH_BUFFER_BIT);
            }

            RendererBase renderer = this.Renderer;

            if (renderer != null)
            {
                renderer.Render(arg);
            }

            for (int i = count - 1; i >= 0; i--)
            {
                this.stateList[i].Off();
            }
            this.scissorTestState.Off();
            this.viewportState.Off();
        }
예제 #18
0
        private void RenderForPicking(RendererBase sceneElement, LegacyPickEventArgs arg, ref uint currentName)
        {
            var pickable = sceneElement as ILegacyPickable;

            if (pickable != null)
            {
                mat4 parentCascadeModelMatrix = arg.ModelMatrixStack.Peek();
                sceneElement.cascadeModelMatrix = sceneElement.GetModelMatrix(parentCascadeModelMatrix);

                ThreeFlags flags = pickable.EnableLegacyPicking;
                if ((flags & ThreeFlags.BeforeChildren) == ThreeFlags.BeforeChildren)
                {
                    //  Load and map the name.
                    GL.Instance.LoadName(currentName);
                    arg.hitMap[currentName] = sceneElement;

                    pickable.RenderBeforeChildrenForLegacyPicking(arg);

                    //  Increment the name.
                    currentName++;
                }

                if ((flags & ThreeFlags.Children) == ThreeFlags.Children)
                {
                    arg.ModelMatrixStack.Push(sceneElement.cascadeModelMatrix);
                    foreach (var item in sceneElement.Children)
                    {
                        this.RenderForPicking(item, arg, ref currentName);
                    }
                    arg.ModelMatrixStack.Pop();
                }

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

                //    pickable.RenderAfterChildrenForLegacyPicking(arg);

                //    //  Increment the name.
                //    currentName++;
                //}
            }
        }
예제 #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clear"></param>
        /// <param name="clearColor"></param>
        /// <param name="rootElement"></param>
        /// <param name="camera"></param>
        public static void Render(bool clear, vec4 clearColor, RendererBase rootElement, ICamera camera)
        {
            int[] value = null;
            if (clear)
            {
                value = new int[4];
                GL.Instance.GetIntegerv((uint)GetTarget.ColorClearValue, value);
                GL.Instance.ClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
            }

            var arg = new RenderEventArgs(camera);

            RenderAction.Render(rootElement, arg);

            if (clear)
            {
                GL.Instance.ClearColor(value[0], value[1], value[2], value[3]);
            }
        }
예제 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        protected override void DoRender(RenderEventArgs arg)
        {
            this.viewportSwitch.X         = this.Location.X;
            this.viewportSwitch.Y         = this.Location.Y;
            this.viewportSwitch.Width     = this.Size.Width;
            this.viewportSwitch.Height    = this.Size.Height;
            this.scissorTestSwitch.X      = this.Location.X;
            this.scissorTestSwitch.Y      = this.Location.Y;
            this.scissorTestSwitch.Width  = this.Size.Width;
            this.scissorTestSwitch.Height = this.Size.Height;

            this.viewportSwitch.On();
            this.scissorTestSwitch.On();
            int count = this.switchList.Count;

            for (int i = 0; i < count; i++)
            {
                this.switchList[i].On();
            }

            // 把所有在此之前渲染的内容都推到最远。
            // Push all rendered stuff to farest position.
            OpenGL.Clear(OpenGL.GL_DEPTH_BUFFER_BIT);

            RendererBase renderer = this.Renderer;

            if (renderer != null)
            {
                renderer.Render(arg);
            }

            for (int i = count - 1; i >= 0; i--)
            {
                this.switchList[i].Off();
            }
            this.scissorTestSwitch.Off();
            this.viewportSwitch.Off();
        }
예제 #21
0
        /// <summary>
        /// Gets a <see cref="SceneObject"/> that contains this renderer.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="name"></param>
        /// <param name="generateBoundingBox"></param>
        /// <param name="scripts"></param>
        /// <returns></returns>
        public static SceneObject WrapToSceneObject(
            this RendererBase renderer,
            string name,
            bool generateBoundingBox,
            params Script[] scripts)
        {
            var obj = new SceneObject();

            obj.Renderer = renderer;
            obj.Name     = name;
            obj.Scripts.AddRange(scripts);
            if (generateBoundingBox)
            {
                BoundingBoxRenderer box = renderer.GetBoundingBoxRenderer();
                box.BoundingBoxColor = Color.Gray;
                var boxObj = new SceneObject();
                boxObj.Renderer = box;
                boxObj.Name     = string.Format("Box of [{0}]", name);
                obj.Children.Add(boxObj);
            }

            return(obj);
        }
예제 #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="renderer"></param>
 /// <param name="deltaTranslate"></param>
 public override void Setup(RendererBase renderer, vec3 deltaTranslate)
 {
     renderer.WorldPosition += deltaTranslate;
 }
예제 #23
0
 /// <summary>
 /// Pop projection+view matrix.
 /// </summary>
 public static void PopProjectionViewMatrix(this RendererBase renderer)
 {
     GL.Instance.MatrixMode(GL.GL_PROJECTION);
     GL.Instance.PopMatrix();
 }
예제 #24
0
 /// <summary>
 /// Gets a <see cref="SceneObject"/> that contains this renderer.
 /// </summary>
 /// <param name="renderer"></param>
 /// <param name="scripts"></param>
 /// <returns></returns>
 public static SceneObject WrapToSceneObject(
     this RendererBase renderer,
     params Script[] scripts)
 {
     return(WrapToSceneObject(renderer, "", scripts));
 }
예제 #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sceneElement"></param>
 /// <param name="zNear"></param>
 /// <param name="zFar"></param>
 public HitTarget(RendererBase sceneElement, uint zNear, uint zFar)
 {
     this.renderer = sceneElement;
     this.zNear    = zNear;
     this.zFar     = zFar;
 }
예제 #26
0
        public FormRendererBaseEditor(RendererBase renderer)
        {
            InitializeComponent();

            this.propertyGrid.SelectedObject = renderer;
        }
예제 #27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="renderer"></param>
 /// <param name="deltaTranslate"></param>
 public override void Setup(RendererBase renderer, vec3 deltaTranslate)
 {
     renderer.WorldPosition += deltaTranslate;
 }
예제 #28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="renderer"></param>
 /// <param name="deltaTranslate"></param>
 public abstract void Setup(RendererBase renderer, vec3 deltaTranslate);
예제 #29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="renderer"></param>
 /// <param name="deltaTranslate"></param>
 public abstract void Setup(RendererBase renderer, vec3 deltaTranslate);
예제 #30
0
 /// <summary>
 /// Pop model matrix.
 /// </summary>
 public static void PopModelMatrix(this RendererBase renderer)
 {
     GL.Instance.MatrixMode(GL.GL_MODELVIEW);
     GL.Instance.PopMatrix();
 }