Sfoglia il codice sorgente

improved graphic-files

Alexander Hendrich 11 anni fa
parent
commit
bcc82b8ffd

+ 1 - 1
bbiwarg/Graphics/IGraphicElement.cs

@@ -8,6 +8,6 @@ namespace bbiwarg.Graphics
 {
     interface IGraphicElement
     {
-        void draw();
+        void draw(int width, int height);
     }
 }

+ 36 - 19
bbiwarg/Graphics/Output.cs

@@ -15,6 +15,9 @@ namespace bbiwarg.Graphics
     class Output : GameWindow
     {
         private IVideoDataSource source;
+        private Point[,] depthPixels = new Point[320,240];
+        private List<IGraphicElement> graphicElements = new List<IGraphicElement>();
+        private Point palmPixel;
 
         public Output(IVideoDataSource source)
         {
@@ -26,6 +29,28 @@ namespace bbiwarg.Graphics
             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)
@@ -44,29 +69,21 @@ namespace bbiwarg.Graphics
 
             for (int x = 0; x < width; x++) {
                 for (int y = 0; y < height; y++) {
-                    if (image.getConfidence(x, y) > 100) {
-                        int depth = image.getDepth(x, y);
-                        Vertex vertex = new Vertex(x-width/2, height/2-y, depth);
-                        Color color = image.getColor(x, y);
-                        float size = 0.5f;
-
-                        Point pixel = new Point(vertex, color, size);
-                        pixel.draw();
-                    }
+                        Point depthPixel = depthPixels[x, y];
+
+                        depthPixel.position.z = image.getDepth(x, y);
+                        depthPixel.color = image.getColor(x, y);
                 }
             }
 
             Vector palmPosition2D = source.getPalmPosition2D(1);
-            int palmX = (int) palmPosition2D[0];
-            int palmY = (int) palmPosition2D[1];
-            int palmDepth = image.getDepth(palmX, palmY);
-            Vertex palmVertex = new Vertex(palmX - width / 2, height / 2 - palmY, palmDepth);
-            Color palmColor = Color.Yellow;
-            float palmSize = 5.0f;
-
-            Point palmPixel = new Point(palmVertex, palmColor, palmSize);
-            palmPixel.draw();
-
+            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();

+ 11 - 8
bbiwarg/Graphics/Point.cs

@@ -10,9 +10,9 @@ namespace bbiwarg.Graphics
 {
     class Point : IGraphicElement
     {
-        private Vertex position;
-        private Color color;
-        private float size;
+        public Vertex position;
+        public Color color;
+        public float size;
 
         public Point(Vertex position, Color color, float size) {
             this.position = position;
@@ -20,14 +20,17 @@ namespace bbiwarg.Graphics
             this.size = size;
         }
 
-        public void draw() {
+        public void draw(int width, int height) {
             GL.Color4(color);
 
+            float relX = position.x - width/2;
+            float relY = height/2-position.y;
+
             GL.Begin(BeginMode.Polygon);
-            GL.Vertex3(position.getX() - size, position.getY() + size, -position.getZ());
-            GL.Vertex3(position.getX() + size, position.getY() + size, -position.getZ());
-            GL.Vertex3(position.getX() + size, position.getY() - size, -position.getZ());
-            GL.Vertex3(position.getX() - size, position.getY() - size, -position.getZ());
+            GL.Vertex3(relX - size, relY + size, -position.z);
+            GL.Vertex3(relX + size, relY + size, -position.z);
+            GL.Vertex3(relX + size, relY - size, -position.z);
+            GL.Vertex3(relX - size, relY - size, -position.z);
             GL.End();
         }
     }

+ 3 - 18
bbiwarg/Graphics/Vertex.cs

@@ -8,29 +8,14 @@ namespace bbiwarg.Graphics
 {
     class Vertex
     {
-        private float x;
-        private float y;
-        private float z;
+        public float x;
+        public float y;
+        public float z;
 
         public Vertex(float x, float y, float z) {
             this.x = x;
             this.y = y;
             this.z = z;// 300;
         }
-
-        public float getX()
-        {
-            return x;
-        }
-
-        public float getY()
-        {
-            return y;
-        }
-
-        public float getZ()
-        {
-            return z;
-        }
     }
 }