using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenTK; using OpenTK.Graphics.OpenGL; using MathNet.Numerics.LinearAlgebra.Single; using bbiwarg.DataSource; namespace bbiwarg.Graphics { class Output : GameWindow { private IVideoDataSource source; private Point[,] depthPixels = new Point[320,240]; private List graphicElements = new List(); private Point palmPixel; public Output(IVideoDataSource source) { this.source = source; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); Title = "OutputTest"; GL.ClearColor(Color.Black); for (int x = 0; x < 320; x++) { for (int y = 0; y < 240; y++) { Vertex vertex = new Vertex(x,y, 0.0f); Color color = Color.White; float size = 0.5f; Point pixel = new Point(vertex, color, size); depthPixels[x, y] = pixel; graphicElements.Add(pixel); } } Vertex palmVertex = new Vertex(0.0f, 0.0f, 0.0f); Color palmColor = Color.Yellow; float palmSize = 5.0f; palmPixel = new Point(palmVertex, palmColor, palmSize); graphicElements.Add(palmPixel); } protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref modelview); source.updateFrame(); ImageData image = source.getImageData(); int width = image.getWidth(); int height = image.getHeight(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Point depthPixel = depthPixels[x, y]; depthPixel.position.z = image.getDepth(x, y); depthPixel.color = image.getColor(x, y); } } Vector palmPosition2D = source.getPalmPosition2D(1); palmPixel.position.x = (int)palmPosition2D[0]; palmPixel.position.y = (int)palmPosition2D[1]; palmPixel.position.z = image.getDepth((int)palmPosition2D[0], (int)palmPosition2D[1]); foreach(IGraphicElement graphicElement in graphicElements) { graphicElement.draw(width, height); } SwapBuffers(); source.releaseFrame(); } protected override void OnResize(EventArgs e) { base.OnResize(e); GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height); Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 3000.0f); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref projection); } } }