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(); } } }
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); }
/// <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; }
/// <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)); }
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); } } }
/// <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()); }
/// <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)); }
/// <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)); }
/// <summary> /// /// </summary> protected override void DisposeUnmanagedResources() { RendererBase renderer = this.Renderer; if (renderer != null) { renderer.Dispose(); } }
///// <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); } }
/// <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()); }
/// <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); }
/// <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()); }
/// <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); }
/// <summary> /// /// </summary> protected override void DoInitialize() { this.viewportState = new ViewportState(); this.scissorTestState = new ScissorTestState(); RendererBase renderer = this.Renderer; if (renderer != null) { renderer.Initialize(); } }
/// <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(); }
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++; //} } }
/// <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]); } }
/// <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(); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="deltaTranslate"></param> public override void Setup(RendererBase renderer, vec3 deltaTranslate) { renderer.WorldPosition += deltaTranslate; }
/// <summary> /// Pop projection+view matrix. /// </summary> public static void PopProjectionViewMatrix(this RendererBase renderer) { GL.Instance.MatrixMode(GL.GL_PROJECTION); GL.Instance.PopMatrix(); }
/// <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)); }
/// <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; }
public FormRendererBaseEditor(RendererBase renderer) { InitializeComponent(); this.propertyGrid.SelectedObject = renderer; }
/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="deltaTranslate"></param> public abstract void Setup(RendererBase renderer, vec3 deltaTranslate);
/// <summary> /// Pop model matrix. /// </summary> public static void PopModelMatrix(this RendererBase renderer) { GL.Instance.MatrixMode(GL.GL_MODELVIEW); GL.Instance.PopMatrix(); }