|
@@ -15,16 +15,15 @@ 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;
|
|
|
- private Point[] fingerPixel = new Point[5];
|
|
|
+ private Point[,] depthPixels = new Point[320,240];
|
|
|
+ private bool initialized = false;
|
|
|
+ private ImageData currentImage;
|
|
|
+
|
|
|
+ private List<IGraphicElement> graphicElements = new List<IGraphicElement>();
|
|
|
private int VBOid = new int();
|
|
|
private int IBOid = new int();
|
|
|
private float[] vertices = new float[0];
|
|
|
private uint[] triangles = new uint[0];
|
|
|
- private int width = 320;
|
|
|
- private int height = 240;
|
|
|
|
|
|
|
|
|
public Output(IVideoDataSource source)
|
|
@@ -37,38 +36,6 @@ 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);
|
|
|
-
|
|
|
- for (int i = 0; i < 5; i++) {
|
|
|
- Vertex vertex = new Vertex(0.0f, 0.0f, 0.0f);
|
|
|
-
|
|
|
- fingerPixel[i] = new Point(vertex, palmColor, palmSize);
|
|
|
- graphicElements.Add(fingerPixel[i]);
|
|
|
- }
|
|
|
-
|
|
|
- initBuffers();
|
|
|
- updateData(graphicElements);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e)
|
|
@@ -79,51 +46,18 @@ namespace bbiwarg.Graphics
|
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
|
|
GL.LoadMatrix(ref modelview);
|
|
|
|
|
|
- source.updateFrame();
|
|
|
-
|
|
|
- ImageData image = source.getImageData();
|
|
|
- width = image.getWidth();
|
|
|
- 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 = palmPosition2D[0];
|
|
|
- palmPixel.position.y = palmPosition2D[1];
|
|
|
- palmPixel.position.z = image.getDepth((int)palmPosition2D[0], (int)palmPosition2D[1]);
|
|
|
-
|
|
|
-
|
|
|
- for (int i = 0; i < 5; i++) {
|
|
|
- DetectionStatus[] fingerStatus = source.getFingerStatus(1);
|
|
|
- Vector[] fingerPositions = source.getFingerTipPositions2D(1);
|
|
|
- if (fingerStatus[i] == DetectionStatus.Tracked)
|
|
|
- {
|
|
|
- fingerPixel[i].position.x = fingerPositions[i][0];
|
|
|
- fingerPixel[i].position.y = fingerPositions[i][1];
|
|
|
- fingerPixel[i].position.z = image.getDepth((int)fingerPositions[i][0], (int)fingerPositions[i][1]);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- fingerPixel[i].position.x = 0;
|
|
|
- fingerPixel[i].position.y = 0;
|
|
|
- fingerPixel[i].position.z = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- /*
|
|
|
- foreach (IGraphicElement graphicElement in graphicElements)
|
|
|
- {
|
|
|
- graphicElement.draw(width, height);
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- updateData(graphicElements);
|
|
|
+ source.updateFrame();
|
|
|
+ currentImage = source.getImageData();
|
|
|
+
|
|
|
+ if (!initialized) {
|
|
|
+ initializeDepthPixels();
|
|
|
+ initBuffers();
|
|
|
+ initialized = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateDepthPixels();
|
|
|
+
|
|
|
+ updateBuffer();
|
|
|
drawBuffer();
|
|
|
|
|
|
SwapBuffers();
|
|
@@ -133,13 +67,46 @@ namespace bbiwarg.Graphics
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
+ private void initializeDepthPixels()
|
|
|
+ {
|
|
|
+ int width = currentImage.getWidth();
|
|
|
+ int height = currentImage.getHeight();
|
|
|
+
|
|
|
+ for (int x = 0; x < width; x++)
|
|
|
+ {
|
|
|
+ for (int y = 0; y < height; 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateDepthPixels()
|
|
|
+ {
|
|
|
+ for (int x = 0; x < currentImage.getWidth(); x++)
|
|
|
+ {
|
|
|
+ for (int y = 0; y < currentImage.getHeight(); y++)
|
|
|
+ {
|
|
|
+ Point depthPixel = depthPixels[x, y];
|
|
|
+
|
|
|
+ depthPixel.position.z = currentImage.getDepth(x, y);
|
|
|
+ depthPixel.color = currentImage.getColor(x, y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void initBuffers()
|
|
|
{
|
|
|
GL.EnableClientState(ArrayCap.VertexArray);
|
|
@@ -157,26 +124,14 @@ namespace bbiwarg.Graphics
|
|
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
|
}
|
|
|
|
|
|
- private void drawBuffer()
|
|
|
- {
|
|
|
- GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
|
|
|
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
|
|
|
-
|
|
|
- GL.InterleavedArrays(InterleavedArrayFormat.C3fV3f, 0, IntPtr.Zero);
|
|
|
- GL.DrawElements(BeginMode.Triangles, triangles.Length, DrawElementsType.UnsignedInt, 0);
|
|
|
-
|
|
|
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
|
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
|
- }
|
|
|
-
|
|
|
- public void updateData(List<IGraphicElement> list)
|
|
|
+ public void updateBuffer()
|
|
|
{
|
|
|
List<float> verticesData = new List<float>();
|
|
|
List<uint> triangleData = new List<uint>();
|
|
|
|
|
|
- foreach (IGraphicElement graphicElement in list)
|
|
|
+ foreach (IGraphicElement graphicElement in graphicElements)
|
|
|
{
|
|
|
- List<Vector> elementVertices = graphicElement.getVertices(width, height);
|
|
|
+ List<Vector> elementVertices = graphicElement.getVertices(currentImage.getWidth(), currentImage.getHeight());
|
|
|
uint[] elementTriangles = graphicElement.getTriangleIndices();
|
|
|
Color elementColor = graphicElement.getColor();
|
|
|
|
|
@@ -206,6 +161,18 @@ namespace bbiwarg.Graphics
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void drawBuffer()
|
|
|
+ {
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
|
|
|
+
|
|
|
+ GL.InterleavedArrays(InterleavedArrayFormat.C3fV3f, 0, IntPtr.Zero);
|
|
|
+ GL.DrawElements(BeginMode.Triangles, triangles.Length, DrawElementsType.UnsignedInt, 0);
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
|
+ }
|
|
|
+
|
|
|
private List<float> convertColor(Color color)
|
|
|
{
|
|
|
List<float> result = new List<float>();
|