private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; GraphicsSurface framebuffer = e.Framebuffer; if (_AnimationBegin == DateTime.MinValue) { _AnimationBegin = DateTime.UtcNow; } PerspectiveProjectionMatrix matrixProjection = new PerspectiveProjectionMatrix(); Matrix4x4 matrixView; // Set projection matrixProjection.SetPerspective(60.0f, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, 1000.0f); // Set view ModelMatrix matrixViewModel = new ModelMatrix(); matrixViewModel.RotateX(_ViewElevation); matrixViewModel.RotateY(_ViewAzimuth); matrixViewModel.Translate(0.0f, 0.0f, _ViewDistance); matrixView = matrixViewModel.GetInverseMatrix(); _NewtonProgram.Bind(ctx); _NewtonProgram.SetUniform(ctx, "hal_ModelViewProjection", matrixProjection * matrixView); _NewtonProgram.SetUniform(ctx, "hal_FrameTimeInterval", (float)(DateTime.UtcNow - _AnimationBegin).TotalSeconds); _NewtonVertexArray.Draw(ctx, _NewtonProgram); SwapNewtonVertexArrays(); // Issue another rendering SampleGraphicsControl.Invalidate(); }
private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; GraphicsSurface framebuffer = e.Framebuffer; #if DEBUG _GeometryClipmapObject = new GeometryClipmapObject(6, 7, _BlockUnit); #else _GeometryClipmapObject = new GeometryClipmapObject(9, 11, _BlockUnit); #endif string workingDir = Directory.GetCurrentDirectory(); _GeometryClipmapObject.SetTerrainElevationFactory(Path.Combine(workingDir, @"..\..\..\Data\Terrain.vrt"), 45.5, 10.5); _GeometryClipmapScene = new SceneGraph(); _GeometryClipmapScene.AddChild(new SceneGraphCameraObject()); _GeometryClipmapScene.AddChild(_GeometryClipmapObject); _GeometryClipmapScene.Create(ctx); // Set projection _GeometryClipmapScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix( _ViewFov / 16.0f * 9.0f, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, _ViewDepth );; // Clear color framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f)); }
public static bool ClipPolyToLine(GraphicsSurface surface, Line ClipLine) { bool result = false; FigPolyline new_fig = new FigPolyline(); if (surface.selected.Count == 0 || surface.selected.Count > 1) { return(result); // nothing selected } if (surface.selected[0] is FigPolyline) { PointF s, p, i; int j; FigPolyline inPoly = surface.selected[0] as FigPolyline; s = inPoly.Points[inPoly.Points.Count - 1]; for (j = 0; j < inPoly.Points.Count; j++) { p = inPoly.Points[j]; if (Inside(p, ClipLine)) // {Cases 1 and 4} { if (Inside(s, ClipLine)) { new_fig.Points.Add(p); // {Case 1} } else { Intersect(s, p, ClipLine, out i); new_fig.Points.Add(i); new_fig.Points.Add(p); } } else // {Cases 2 and 3} { if (Inside(s, ClipLine)) // {Cases 2} { Intersect(s, p, ClipLine, out i); new_fig.Points.Add(i); } // {No action for case 3} } s = p; // {Advance to next pair of vertices} } // replace selected surface.Drawing.RemoveFigures(surface.selected); surface.Drawing.AddFigure(new_fig); // set new selection surface.selected.Clear(); //surface.AddToSelected(new_fig); surface.selected.Add(new_fig); return(result); } else { return(result); } }
/// <summary> /// /// </summary> /// <param name="graphicsSurface"></param> public ViewportState(GraphicsSurface graphicsSurface) { if (graphicsSurface == null) { throw new ArgumentNullException("graphicsSurface"); } ViewportSize = new Vertex2f(graphicsSurface.Width, graphicsSurface.Height); }
public ClientWindow() { InitializeComponent(); PanelDocument_Resize(PanelDocument, new EventArgs()); SurfaceObject = new GraphicsSurface(PanelCanvas); SurfaceObject.Renderer = new DocumentRenderer(); }
private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; GraphicsSurface framebuffer = e.Framebuffer; // Create Newton program _NewtonProgram = ShadersLibrary.Instance.CreateProgram("Newton"); _NewtonProgram.AddFeedbackVarying("hal_VertexPosition"); _NewtonProgram.AddFeedbackVarying("hal_VertexSpeed"); _NewtonProgram.AddFeedbackVarying("hal_VertexAcceleration"); _NewtonProgram.AddFeedbackVarying("hal_VertexMass"); _NewtonProgram.Create(ctx); // Initialize first vertex array NewtonVertex[] newtonArray = new NewtonVertex[VertexCount]; Random random = new Random(); for (int i = 0; i < newtonArray.Length; i++) { NewtonVertex newtonVertex = new NewtonVertex(); newtonVertex.Position = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized()); newtonVertex.Speed = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized()); newtonVertex.Acceleration = new Vertex3f(); newtonVertex.Mass = RandomNormalized(); newtonArray[i] = newtonVertex; } // Create vertex arrays ArrayBufferObjectBase newtonVertexArrayBuffer1, newtonVertexArrayBuffer2; _NewtonVertexArray1 = CreateVertexArray(newtonArray, out newtonVertexArrayBuffer1); _NewtonVertexArray2 = CreateVertexArray(null, out newtonVertexArrayBuffer2); _NewtonVertexArray1.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer2)); _NewtonVertexArray2.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer1)); _NewtonVertexArray1.Create(ctx); _NewtonVertexArray2.Create(ctx); // Starts from initialized buffer _NewtonVertexArray = _NewtonVertexArray1; // Clear color framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f)); }
private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; GraphicsSurface framebuffer = e.Framebuffer; // Update position KeyTimer_Tick(); // Define view _GeometryClipmapScene.CurrentView.LocalModel.SetIdentity(); _GeometryClipmapScene.CurrentView.LocalModel.Translate(_ViewPosition); _GeometryClipmapScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _GeometryClipmapScene.CurrentView.LocalModel.RotateX(_ViewElevation); // Draw geometry clipmap _GeometryClipmapScene.Draw(ctx); SampleGraphicsControl.Invalidate(); }
/// <summary> /// /// </summary> /// <param name="graphicsSurface"></param> public ViewportState(GraphicsSurface graphicsSurface) { if (graphicsSurface == null) throw new ArgumentNullException("graphicsSurface"); ViewportSize = new Vertex2f(graphicsSurface.Width, graphicsSurface.Height); }
/// <summary> /// Replace the selected lines or polylines with a single polyline. /// </summary> /// <param name="surface"></param> /// <returns></returns> public static bool MakePath(GraphicsSurface surface) { bool result = false; FigPolyline new_fig = new FigPolyline(); if (surface.selected.Count == 0) { return(result); // nothing selected } foreach (Figure fig in surface.selected) { if (!((fig is Line) || (fig is FigPolyline))) { return(false); } } foreach (Figure fig in surface.selected) { if (new_fig.Points.Count == 0) { if (fig is Line) { Line line = fig as Line; new_fig.Points.Add(new PointF(line.p1.X, line.p1.Y)); new_fig.Points.Add(new PointF(line.p2.X, line.p2.Y)); new_fig.LineProperties = line.LineProperties; } else { FigPolyline poly = fig as FigPolyline; foreach (PointF p in poly.Points) { new_fig.Points.Add(new PointF(p.X, p.Y)); } new_fig.LineProperties = poly.LineProperties; } } else { // check contiguous if (fig is Line) { Line line = fig as Line; if (new_fig.Points[new_fig.Points.Count - 1] == line.p1) { new_fig.Points.Add(new PointF(line.p2.X, line.p2.Y)); } else if (new_fig.Points[new_fig.Points.Count - 1] == line.p2) { new_fig.Points.Add(new PointF(line.p1.X, line.p1.Y)); } else if (new_fig.Points[0] == line.p1) { new_fig.Points.Insert(0, new PointF(line.p2.X, line.p2.Y)); } else if (new_fig.Points[0] == line.p2) { new_fig.Points.Insert(0, new PointF(line.p1.X, line.p1.Y)); } else { return(false); } } else { //polyline FigPolyline poly = fig as FigPolyline; if (new_fig.Points[new_fig.Points.Count - 1] == poly.Points[0]) { AddPoints(ref new_fig.Points, poly.Points, 1); } else if (new_fig.Points[new_fig.Points.Count - 1] == poly.Points[poly.Points.Count - 1]) { AddPointsReverse(ref new_fig.Points, poly.Points, 1); } } } } surface.Drawing.RemoveFigures(surface.selected); surface.Drawing.AddFigure(new_fig); // set new selection //surface.ClearSelected(); surface.selected.Clear(); //surface.AddToSelected(new_fig); surface.selected.Add(new_fig); return(result); }