/// <summary> /// Initializes a new instance of the <see cref="ParticleSystem"/> class. /// </summary> public ParticleSystem() { // Create the effect for the system. OpenGLAttributesEffect attributesEffect = new OpenGLAttributesEffect(); attributesEffect.LightingAttributes.Enable = false; // Add the effects. AddEffect(attributesEffect); }
public Wall(Vertex[] vertex1, string name, OpenGL gl) { DepthBufferAttributes depthBufferAttributes = new DepthBufferAttributes(); depthBufferAttributes.DepthFunction = DepthFunction.LessThanOrEqual; depthBufferAttributes.EnableDepthTest = true; Name = name; // ==== Fill polygon === PolygonAttributes polygonFillAttributes = new PolygonAttributes(); polygonFillAttributes.PolygonMode = PolygonMode.Filled; polygonFillAttributes.CullFaces = FaceMode.Back; polygonFillAttributes.EnableCullFace = true; polygonFillAttributes.OffsetFactor = 0f; polygonFillAttributes.OffsetBias = 0; polygonFillAttributes.EnableOffsetFill = true; OpenGLAttributesEffect polyFillEffect = new OpenGLAttributesEffect(); polyFillEffect.PolygonAttributes = polygonFillAttributes; //polyFillEffect.DepthBufferAttributes = depthBufferAttributes; SharpGL.SceneGraph.Primitives.Polygon polyFill = new Polygon(this.Name, vertex1); polyFill.Material = Materials.Pink(gl); polyFill.AddEffect(polyFillEffect); this.Children.Add(polyFill); // ==== Border polygon === PolygonAttributes polygonBorderAttributes = new PolygonAttributes(); polygonBorderAttributes.PolygonMode = PolygonMode.Lines; polygonBorderAttributes.OffsetFactor = -.5f; polygonBorderAttributes.OffsetBias = -.5f; polygonBorderAttributes.EnableOffsetLine = true; polygonBorderAttributes.CullFaces = FaceMode.Back; polygonBorderAttributes.EnableCullFace = true; OpenGLAttributesEffect polyBorderEffect = new OpenGLAttributesEffect(); polyBorderEffect.PolygonAttributes = polygonBorderAttributes; //polyBorderEffect.DepthBufferAttributes = depthBufferAttributes; SharpGL.SceneGraph.Primitives.Polygon polyBorder = new Polygon(this.Name, vertex1); polyBorder.Material = Materials.DarkGrey(gl); polyBorder.AddEffect(polyBorderEffect); this.Children.Add(polyBorder); this.polyFill = polyFill; }
/// <summary> /// /// </summary> /// <param name="camera">if null, please set camera for result's orthoArcBallEffect.Camera property later.</param> /// <returns></returns> public static OrthoAxisElement Create(LookAtCamera camera = null) { OrthoAxisElement element = new OrthoAxisElement() { Name = "orthogonal axis element" }; // Create a set of scene attributes. OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect() { Name = "Scene Attributes" }; // Specify the scene attributes. sceneAttributes.EnableAttributes.EnableDepthTest = true; sceneAttributes.EnableAttributes.EnableNormalize = true; sceneAttributes.EnableAttributes.EnableLighting = false; //sceneAttributes.EnableAttributes.EnableTexture2D = true; //sceneAttributes.EnableAttributes.EnableBlend = true; //sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; //sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; //sceneAttributes.LightingAttributes.TwoSided = true; //sceneAttributes.TransformAttributes.MatrixMode = MatrixMode.Projection; element.AddEffect(sceneAttributes); OrthoArcBallEffect orthoAxisArcBallEffect = new OrthoArcBallEffect(camera); element.AddEffect(orthoAxisArcBallEffect); Axies axies = new Axies(); element.AddChild(axies); LinearTransformationEffect transform = new LinearTransformationEffect(); transform.LinearTransformation.ScaleX = 10; transform.LinearTransformation.ScaleY = 10; transform.LinearTransformation.ScaleZ = 10; axies.AddEffect(transform); //Grid grid = new Grid(); //element.AddChild(grid); //LinearTransformationEffect transform = new LinearTransformationEffect(); //transform.LinearTransformation.ScaleX = 0.1f; //transform.LinearTransformation.ScaleY = 0.1f; //transform.LinearTransformation.ScaleZ = 0.1f; //grid.AddEffect(transform); element.orthoArcBallEffect = orthoAxisArcBallEffect; return(element); }
private OpenGLAttributesEffect InitializeSceneAttributes(SceneElement parent) { // Create a set of scene attributes. OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect() { Name = "Scene Attributes" }; // Specify the scene attributes. sceneAttributes.EnableAttributes.EnableDepthTest = true; sceneAttributes.EnableAttributes.EnableNormalize = true; sceneAttributes.EnableAttributes.EnableLighting = false; sceneAttributes.EnableAttributes.EnableTexture2D = true; //sceneAttributes.EnableAttributes.EnableBlend = true; sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; sceneAttributes.LightingAttributes.TwoSided = true; sceneAttributes.LightingAttributes.AmbientLight = new GLColor(1, 1, 1, 1); parent.AddEffect(sceneAttributes); return(sceneAttributes); }
public static unsafe OrthoColorIndicatorElement Create(ColorTemplate colorTemplate) { OrthoColorIndicatorElement element = new OrthoColorIndicatorElement() { Name = "orthogonal color indicator element" }; OrthoColorIndicatorBar bar = CreateBar(colorTemplate); element.AddChild(bar); element.bar = bar; OrthoColorIndicatorNumber number = CreateNumber(colorTemplate); element.AddChild(number); element.number = number; // Create a set of scene attributes. OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect() { Name = "Scene Attributes" }; // Specify the scene attributes. sceneAttributes.EnableAttributes.EnableDepthTest = true; sceneAttributes.EnableAttributes.EnableNormalize = true; sceneAttributes.EnableAttributes.EnableLighting = false; //sceneAttributes.EnableAttributes.EnableTexture2D = true; //sceneAttributes.EnableAttributes.EnableBlend = true; //sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; //sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; //sceneAttributes.LightingAttributes.TwoSided = true; //sceneAttributes.TransformAttributes.MatrixMode = MatrixMode.Projection; element.AddEffect(sceneAttributes); return(element); }
public void AddSymbol(Circle circle, OpenGL gl) { DepthBufferAttributes depthBufferAttributes = new DepthBufferAttributes(); depthBufferAttributes.DepthFunction = DepthFunction.LessThanOrEqual; depthBufferAttributes.EnableDepthTest = true; PolygonAttributes polygonBorderAttributes = new PolygonAttributes(); polygonBorderAttributes.PolygonMode = PolygonMode.Lines; polygonBorderAttributes.EnableOffsetLine = true; polygonBorderAttributes.OffsetFactor = -3f; polygonBorderAttributes.OffsetBias = -3f; OpenGLAttributesEffect polyBorderEffect = new OpenGLAttributesEffect(); polyBorderEffect.PolygonAttributes = polygonBorderAttributes; polyBorderEffect.DepthBufferAttributes = depthBufferAttributes; circle.Material = Materials.DarkGrey(gl); circle.AddEffect(polyBorderEffect); this.Children.Add(circle); }
/// <summary> /// Initialises a modeling scene. A modeling scene has: /// - A 'Look At' camera targetting the centre of the scene /// - Three gentle omnidirectional lights /// - A design time grid and axis. /// </summary> /// <param name="scene">The scene.</param> public static void InitialiseModelingScene(ColorCodedPickingScene scene) { // Create the 'Look At' camera var lookAtCamera = new ScientificCamera() { Position = new Vertex(-10f, -10f, 10f), Target = new Vertex(0f, 0f, 0f), UpVector = new Vertex(0f, 0f, 1f) }; // Set the look at camera as the current camera. scene.CurrentCamera = lookAtCamera; // Add some design-time primitives. var folder = new Folder() { Name = "Design Primitives" }; folder.AddChild(new Grid()); folder.AddChild(new Axies()); scene.SceneContainer.AddChild(folder); // Create some lights. Light light1 = new Light() { Name = "Light 1", On = true, Position = new Vertex(-9, -9, 11), GLCode = OpenGL.GL_LIGHT0 }; Light light2 = new Light() { Name = "Light 2", On = true, Position = new Vertex(9, -9, 11), GLCode = OpenGL.GL_LIGHT1 }; Light light3 = new Light() { Name = "Light 3", On = true, Position = new Vertex(0, 15, 15), GLCode = OpenGL.GL_LIGHT2 }; // Add the lights. folder = new Folder() { Name = "Lights" }; folder.AddChild(light1); folder.AddChild(light2); folder.AddChild(light3); scene.SceneContainer.AddChild(folder); // Create a set of scene attributes. OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect() { Name = "Scene Attributes" }; // Specify the scene attributes. sceneAttributes.EnableAttributes.EnableDepthTest = true; sceneAttributes.EnableAttributes.EnableNormalize = true; sceneAttributes.EnableAttributes.EnableLighting = true; sceneAttributes.EnableAttributes.EnableTexture2D = true; sceneAttributes.EnableAttributes.EnableBlend = true; sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; sceneAttributes.LightingAttributes.TwoSided = true; scene.SceneContainer.AddEffect(sceneAttributes); }
private void InitializeModelScene(Scene scene, Rect3D rect3D, OpenGLControl sceneControl, ArcBallEffect arcBallEffect) { float centerX = rect3D.X + rect3D.Size.x / 2.0f; float centerY = rect3D.Y + rect3D.Size.y / 2.0f; float centerZ = rect3D.Z + rect3D.Size.z / 2.0f; //scene.CreateInContext(scenContor); Vertex center = new Vertex(centerX, centerY, centerZ); Vertex position = center + new Vertex(0.0f, 0.0f, 1.0f) * (rect3D.Size.z * 2); Vertex PositionNear = center + new Vertex(0.0f, 0.0f, 1.0f) * (rect3D.Size.z * 0.52f); //arcBallEffect. var lookAtCamera = new LookAtCamera() { Position = position, Target = center, UpVector = new Vertex(0f, 1f, 0f), FieldOfView = 60, AspectRatio = 1.0f, Near = (PositionNear - center).Z, Far = float.MaxValue }; scene.CurrentCamera = lookAtCamera; Vertex lightPosition = center; Light light1 = new Light() { Name = "Light 1", On = true, Position = lightPosition, GLCode = OpenGL.GL_LIGHT0 }; /* * Light light2 = new Light() * { * Name = "Light 2", * On = true, * Position = center + new Vertex(1.0f,0.0f,0.0f)* rect3D.Size.x, * GLCode = OpenGL.GL_LIGHT1 * }; * * Light light3 = new Light() * { * Name = "Light 3", * On = true, * Position = center + new Vertex(0.0f,1.0f,0.0f)*rect3D.Size.y, * GLCode = OpenGL.GL_LIGHT2 * }; */ var folder = new Folder() { Name = "Lights" }; folder.AddChild(light1); //folder.AddChild(light2); //folder.AddChild(light3); scene.SceneContainer.AddChild(folder); // Create a set of scene attributes. OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect() { Name = "Scene Attributes" }; // Specify the scene attributes. sceneAttributes.EnableAttributes.EnableDepthTest = true; sceneAttributes.EnableAttributes.EnableNormalize = true; sceneAttributes.EnableAttributes.EnableLighting = true; sceneAttributes.EnableAttributes.EnableTexture2D = true; sceneAttributes.EnableAttributes.EnableBlend = true; sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; sceneAttributes.LightingAttributes.TwoSided = true; scene.SceneContainer.AddEffect(sceneAttributes); sceneControl.OpenGL.SetDimensions(sceneControl.Width, sceneControl.Height); scene.Resize(sceneControl.Width, sceneControl.Height); }
public RoundColumn(OpenGL gl, string name, Circle circle, float bottomPoint, float topPoint) : base() { this.Name = name; this.circle = circle; this.bottomPoint = bottomPoint; this.topPoint = topPoint; boundingVolumeHelper = new BoundingVolumeHelper(); Vertex startPoint = circle.StartPoint; Vertex secondPoint = circle.SecondPoint; Vertex endPoint = circle.EndPoint; // ==== Create bottom circle of column ==== startPoint.Z = bottomPoint; secondPoint.Z = bottomPoint; endPoint.Z = bottomPoint; DepthBufferAttributes depthBufferAttributes = new DepthBufferAttributes(); depthBufferAttributes.DepthFunction = DepthFunction.LessThanOrEqual; depthBufferAttributes.EnableDepthTest = true; PolygonAttributes polygonAttributes = new PolygonAttributes(); polygonAttributes.PolygonMode = PolygonMode.Lines; polygonAttributes.EnableOffsetLine = true; polygonAttributes.OffsetFactor = -.9f; polygonAttributes.OffsetBias = -.9f; OpenGLAttributesEffect openGLAttributesEffect = new OpenGLAttributesEffect(); openGLAttributesEffect.PolygonAttributes = polygonAttributes; //openGLAttributesEffect.DepthBufferAttributes = depthBufferAttributes; Circle bottomCircle = new Circle(new Vertex(startPoint), new Vertex(secondPoint), new Vertex(endPoint)); bottomCircle.Material = Materials.DarkGrey(gl); bottomCircle.AddEffect(openGLAttributesEffect); AddChild(bottomCircle); // ==== Create top circle of column ==== startPoint.Z = topPoint; secondPoint.Z = topPoint; endPoint.Z = topPoint; Circle topCircle = new Circle(new Vertex(startPoint), new Vertex(secondPoint), new Vertex(endPoint)); topCircle.Material = Materials.DarkGrey(gl); topCircle.AddEffect(openGLAttributesEffect); AddChild(topCircle); // ==== Create column body ==== // Create the display list. this.Material = Materials.Purple(gl); displayList = new DisplayList(); // Generate the display list and displayList.Generate(gl); displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute); gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL); gl.Begin(BeginMode.QuadStrip); double angle = 0; while (angle <= 2 * Math.PI * 1.01) { double xTmp = circle.Radius * Math.Cos(angle); double yTmp = circle.Radius * Math.Sin(angle); gl.Vertex(circle.Center.X + xTmp, circle.Center.Y + yTmp, bottomPoint); gl.Vertex(circle.Center.X + xTmp, circle.Center.Y + yTmp, topPoint); angle += 0.1; } gl.End(); // End the display list. displayList.End(gl); }
/// <summary> /// Construct a new scene, optionally enableing post-processing, if available. /// </summary> /// <param name="postprocessingEnabled">Whether or not to enable post-processing; defaults to false</param> public Scene(OpenGL gl, Size viewportSize) { this.gl = gl; this.viewportSize = viewportSize; model = null; postprocessingEnabled = false; ClearColor = Color.Black; camera = new MovingLookAtCamera() { Position = new Vertex(10f, 0f, 0f), Target = new Vertex(0f, 0f, 0f), UpVector = new Vertex(0f, 0f, 1f), Near = 0, Far = 250, HorizontalTheta = 0.785f, VerticalTheta = -0.785f }; RenderGrid = true; RenderAxies = true; grid = new Grid(); grid.Size = 150; axies = new Axies(); axies.Size = 150; //Set attributes attrs = new OpenGLAttributesEffect(); attrs.EnableAttributes.EnableDepthTest = true; attrs.EnableAttributes.EnableNormalize = true; attrs.EnableAttributes.EnableLighting = true; attrs.EnableAttributes.EnableTexture2D = true; attrs.LightingAttributes.TwoSided = false; Color col = Color.FromArgb(40, 40, 40); // Nice soft-ish lighting Light light = new Light(OpenGL.GL_LIGHT0) { Position = new Vertex(-9, -9, 11), Ambient = Color.Black, Diffuse = col, Specular = col }; this.Children.Add(light); light = new Light(OpenGL.GL_LIGHT1) { Position = new Vertex(9, -9, 11), Ambient = Color.Black, Diffuse = col, Specular = col }; this.Children.Add(light); light = new Light(OpenGL.GL_LIGHT2) { Position = new Vertex(0, 15, 15), Ambient = Color.Black, Diffuse = col, Specular = col }; this.Children.Add(light); }