/// <summary> /// Adds a child. /// </summary> /// <param name="child">The child scene element.</param> public void AddChild(SceneElement child) { // Throw an exception if the child already has a parent. if (child.Parent != null) throw new Exception("Cannot add the child element '" + child.Name + "' - it is already in the Scene Tree."); // Add the child and set the parent. children.Add(child); child.Parent = this; // If the child has OpenGL context which is different to this, we must create it. if (child is IHasOpenGLContext) { // Cast the chil.d IHasOpenGLContext contextChild = child as IHasOpenGLContext; // Get the parent OpenGL. OpenGL gl = TraverseToRootElement().ParentScene.OpenGL; // If we don't exist in this context, create in this context. if(contextChild.CurrentOpenGLContext != gl) contextChild.CreateInContext(gl); } }
/// <summary> /// Pushes the effect onto the specified parent element. /// </summary> /// <param name="gl">The OpenGL instance.</param> /// <param name="parentElement">The parent element.</param> public override void Push(OpenGL gl, SceneElement parentElement) { // Create a combined mask. AttributeMask attributeFlags = AttributeMask.None; attributeFlags &= accumBufferAttributes.AreAnyAttributesSet() ? accumBufferAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= colorBufferAttributes.AreAnyAttributesSet() ? colorBufferAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= currentAttributes.AreAnyAttributesSet() ? currentAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= depthBufferAttributes.AreAnyAttributesSet() ? depthBufferAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= enableAttributes.AreAnyAttributesSet() ? enableAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= fogAttributes.AreAnyAttributesSet() ? fogAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= lightingAttributes.AreAnyAttributesSet() ? lightingAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= lineAttributes.AreAnyAttributesSet() ? lineAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= pointAttributes.AreAnyAttributesSet() ? pointAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= polygonAttributes.AreAnyAttributesSet() ? polygonAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= evalAttributes.AreAnyAttributesSet() ? evalAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= hintAttributes.AreAnyAttributesSet() ? hintAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= listAttributes.AreAnyAttributesSet() ? listAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= pixelModeAttributes.AreAnyAttributesSet() ? pixelModeAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= polygonStippleAttributes.AreAnyAttributesSet() ? polygonStippleAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= scissorAttributes.AreAnyAttributesSet() ? scissorAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= stencilBufferAttributes.AreAnyAttributesSet() ? stencilBufferAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= textureAttributes.AreAnyAttributesSet() ? textureAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= transformAttributes.AreAnyAttributesSet() ? transformAttributes.AttributeFlags : AttributeMask.None; attributeFlags &= viewportAttributes.AreAnyAttributesSet() ? viewportAttributes.AttributeFlags : AttributeMask.None; // Push the attribute stack. gl.PushAttrib((uint)attributeFlags); // Set the attributes. accumBufferAttributes.SetAttributes(gl); colorBufferAttributes.SetAttributes(gl); currentAttributes.SetAttributes(gl); depthBufferAttributes.SetAttributes(gl); enableAttributes.SetAttributes(gl); fogAttributes.SetAttributes(gl); lightingAttributes.SetAttributes(gl); lineAttributes.SetAttributes(gl); pointAttributes.SetAttributes(gl); polygonAttributes.SetAttributes(gl); evalAttributes.SetAttributes(gl); hintAttributes.SetAttributes(gl); listAttributes.SetAttributes(gl); pixelModeAttributes.SetAttributes(gl); polygonStippleAttributes.SetAttributes(gl); scissorAttributes.SetAttributes(gl); stencilBufferAttributes.SetAttributes(gl); textureAttributes.SetAttributes(gl); transformAttributes.SetAttributes(gl); viewportAttributes.SetAttributes(gl); }
/// <summary> /// Adds the element to tree. /// </summary> /// <param name="sceneElement">The scene element.</param> /// <param name="nodes">The nodes.</param> private void AddElementToTree(SceneElement sceneElement, TreeNodeCollection nodes) { // Add the element. TreeNode newNode = new TreeNode() { Text = sceneElement.Name, Tag = sceneElement }; nodes.Add(newNode); // Add each child. foreach (var element in sceneElement.Children) AddElementToTree(element, newNode.Nodes); }
/// <summary> /// Removes the child scene element. /// </summary> /// <param name="child">The child scene element.</param> public void RemoveChild(SceneElement child) { // If the child has OpenGL context which is not the current one, we must destroy it. if (child is IHasOpenGLContext) if(((IHasOpenGLContext)child).CurrentOpenGLContext != TraverseToRootElement().ParentScene.OpenGL) ((IHasOpenGLContext)child).DestroyInContext(TraverseToRootElement().ParentScene.OpenGL); // Throw an exception if the child is not a child of this element.. if (child.Parent != this) throw new Exception("Cannot remove the child element '" + child.Name + "' - it is not a child of '" + Name + "'."); // Remove the child. children.Remove(child); child.Parent = null; }
/// <summary> /// Removes the child scene element. /// </summary> /// <param name="child">The child scene element.</param> public void RemoveChild(SceneElement child) { // If the child has OpenGL context which is not the current one, we must destroy it. if (child is IHasOpenGLContext) { if (((IHasOpenGLContext)child).CurrentOpenGLContext != TraverseToRootElement().ParentScene.OpenGL) { ((IHasOpenGLContext)child).DestroyInContext(TraverseToRootElement().ParentScene.OpenGL); } } // Throw an exception if the child is not a child of this element.. if (child.Parent != this) { throw new Exception("Cannot remove the child element '" + child.Name + "' - it is not a child of '" + Name + "'."); } // Remove the child. children.Remove(child); child.Parent = null; }
/// <summary> /// Pushes the effect onto the specified parent element. /// </summary> /// <param name="gl">The OpenGL instance.</param> /// <param name="parentElement">The parent element.</param> public override void Push(OpenGL gl, SceneElement parentElement) { }
/// <summary> /// Renders the element for hit test. /// </summary> /// <param name="sceneElement">The scene element.</param> /// <param name="hitMap">The hit map.</param> /// <param name="currentName">Current hit name.</param> private void RenderElementForHitTest(SceneElement sceneElement, Dictionary<uint, SceneElement> hitMap, ref uint currentName) { // If the element is disabled, we're done. // Also, never hit test the current camera. if (sceneElement.IsEnabled == false || sceneElement == currentCamera) return; // Push each effect. foreach (var effect in sceneElement.Effects) if (effect.IsEnabled) effect.Push(gl, sceneElement); // If the element has an object space, transform into it. if (sceneElement is IHasObjectSpace) ((IHasObjectSpace)sceneElement).PushObjectSpace(gl); // If the element is volume bound, render the volume. if (sceneElement is IVolumeBound) { // Load and map the name. gl.LoadName(currentName); hitMap[currentName] = sceneElement; // Render the bounding volume. ((IVolumeBound)sceneElement).BoundingVolume.Render(gl, RenderMode.HitTest); // Increment the name. currentName++; } // Recurse through the children. foreach (var childElement in sceneElement.Children) RenderElementForHitTest(childElement, hitMap, ref currentName); // If the element has an object space, transform out of it. if (sceneElement is IHasObjectSpace) ((IHasObjectSpace)sceneElement).PopObjectSpace(gl); // Pop each effect. for (int i = sceneElement.Effects.Count - 1; i >= 0; i--) if (sceneElement.Effects[i].IsEnabled) sceneElement.Effects[i].Pop(gl, sceneElement); }
/// <summary> /// Renders the element. /// </summary> /// <param name="gl">The gl.</param> /// <param name="renderMode">The render mode.</param> public void RenderElement(SceneElement sceneElement, RenderMode renderMode) { // If the element is disabled, we're done. if (sceneElement.IsEnabled == false) return; // Push each effect. foreach (var effect in sceneElement.Effects) if(effect.IsEnabled) effect.Push(gl, sceneElement); // If the element can be bound, bind it. if (sceneElement is IBindable) ((IBindable)sceneElement).Bind(gl); // If the element has an object space, transform into it. if (sceneElement is IHasObjectSpace) ((IHasObjectSpace)sceneElement).PushObjectSpace(gl); // If the element can be rendered, render it. if (sceneElement is IRenderable) ((IRenderable)sceneElement).Render(gl, renderMode); // IF the element is volume bound and we are rendering volumes, render the volume. if (RenderBoundingVolumes && sceneElement is IVolumeBound) ((IVolumeBound)sceneElement).BoundingVolume.Render(gl, renderMode); // Recurse through the children. foreach (var childElement in sceneElement.Children) RenderElement(childElement, renderMode); // If the element has an object space, transform out of it. if (sceneElement is IHasObjectSpace) ((IHasObjectSpace)sceneElement).PopObjectSpace(gl); // Pop each effect. for (int i = sceneElement.Effects.Count - 1; i >= 0; i--) if(sceneElement.Effects[i].IsEnabled) sceneElement.Effects[i].Pop(gl, sceneElement); }
/// <summary> /// This function writes an object to the stream. /// </summary> /// <param name="writer">The writer to write to.</param> /// <param name="sceneObject">The object to write.</param> public virtual void Write(BinaryWriter writer, SceneElement sceneObject) { }
/// <summary> /// Pushes the effect onto the specified parent element. /// </summary> /// <param name="gl">The OpenGL instance.</param> /// <param name="parentElement">The parent element.</param> public override void Push(OpenGL gl, SceneElement parentElement) { // Use this shader object. gl.UseProgram(ProgramObject); }
/// <summary> /// Pops the effect off the specified parent element. /// </summary> /// <param name="gl">The OpenGL instance.</param> /// <param name="parentElement">The parent element.</param> public override void Pop(OpenGL gl, SceneElement parentElement) { // Un-use this shader object. gl.UseProgram(0); }
/// <summary> /// Pops the effect off the specified parent element. /// </summary> /// <param name="gl">The OpenGL instance.</param> /// <param name="parentElement">The parent element.</param> public abstract void Pop(OpenGL gl, SceneElement parentElement);
/// <summary> /// Pops the effect off the specified parent element. /// </summary> /// <param name="gl">The OpenGL instance.</param> /// <param name="parentElement">The parent element.</param> public override void Pop(OpenGL gl, SceneElement parentElement) { // Pop the attribute stack. gl.PopAttrib(); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { SelectedSceneElement = listBox1.SelectedItem as SceneElement; }
/// <summary> /// Writes the data. /// </summary> /// <param name="writer">The writer.</param> /// <param name="sceneObject">The scene object.</param> protected virtual void WriteData(BinaryWriter writer, SceneElement sceneObject) { }
private void sceneControl1_MouseClick(object sender, MouseEventArgs e) { // Do a hit test. SelectedSceneElement = null; listBox1.Items.Clear(); var itemsHit = sceneControl1.Scene.DoHitTest(e.X, e.Y); foreach (var item in itemsHit) listBox1.Items.Add(item); if (listBox1.Items.Count >0) { listBox1.SetSelected(0, true); // listBox1_SelectedIndexChanged(this, null); } }
public static bool SceneElementEqual(SceneElement x, SceneElement y) { if ((x == null && y != null) || (x != null && y == null)) return false; // ReSharper disable ConditionIsAlwaysTrueOrFalse if (x == null && y == null) return true; // ReSharper restore ConditionIsAlwaysTrueOrFalse return x.GetType() == y.GetType() && x.Name == y.Name && (Equal(x as Polygon, y as Polygon) || Equal(x as Cylinder, y as Cylinder) || Equal(x as Disk, y as Disk) || Equal(x as Sphere, y as Sphere) || Equal(x as LookAtCamera, y as LookAtCamera) || Equal(x as ArcBallCamera, y as ArcBallCamera) || Equal(x as OrthographicCamera, y as OrthographicCamera) || Equal(x as FrustumCamera, y as FrustumCamera) || Equal(x as Light, y as Light)); }