OutputTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using OpenTK;
  7. using OpenTK.Graphics.OpenGL;
  8. using MathNet.Numerics.LinearAlgebra.Single;
  9. using bbiwarg.DataSource;
  10. namespace Test.bbiwarg
  11. {
  12. class OutputTest : GameWindow
  13. {
  14. IVideoDataSource source;
  15. static void Main(string[] args)
  16. {
  17. OutputTest demo = new OutputTest();
  18. demo.initSource();
  19. demo.Run(30);
  20. }
  21. public void initSource()
  22. {
  23. source = new IIsuDataSource("..\\..\\videos\\10.skv");
  24. source.init();
  25. source.start();
  26. }
  27. protected override void OnLoad(EventArgs e)
  28. {
  29. base.OnLoad(e);
  30. Title = "OutputTest";
  31. GL.ClearColor(Color.CornflowerBlue);
  32. }
  33. protected override void OnRenderFrame(FrameEventArgs e)
  34. {
  35. base.OnRenderFrame(e);
  36. bool isActive = source.isActive();
  37. if (isActive)
  38. {
  39. source.updateFrame();
  40. }
  41. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  42. Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
  43. GL.MatrixMode(MatrixMode.Modelview);
  44. GL.LoadMatrix(ref modelview);
  45. DepthImage depthImage = source.getDepthImage();
  46. int width = depthImage.getWidth();
  47. int height = depthImage.getHeight();
  48. for (int x = 0; x < width; x++) {
  49. for (int y = 0; y < height; y++) {
  50. short depth = depthImage.getDepth(x, y);
  51. int relX = x - width / 2;
  52. int relY = y - height / 2;
  53. GL.Begin(BeginMode.Polygon);
  54. GL.Vertex3(relX-0.5f, relY+0.5f, -depth);
  55. GL.Vertex3(relX+0.5f, relY+0.5f, -depth);
  56. GL.Vertex3(relX+0.5f, relY-0.5f, -depth);
  57. GL.Vertex3(relX-0.5f, relY-0.5f, -depth);
  58. GL.End();
  59. }
  60. }
  61. /*
  62. GL.Begin(BeginMode.Triangles);
  63. GL.Vertex3(0.0f, 0.0f, -4.0f);
  64. GL.Vertex3(2.0f, 0.0f, -4.0f);
  65. GL.Vertex3(0.0f, 1.0f, -4.0f);
  66. GL.End();
  67. */
  68. SwapBuffers();
  69. if(isActive) {
  70. source.releaseFrame();
  71. }
  72. /*
  73. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  74. Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
  75. GL.MatrixMode(MatrixMode.Modelview);
  76. GL.LoadMatrix(ref modelview);
  77. // triangle
  78. GL.Begin(BeginMode.Triangles);
  79. float x = palmPosition.Value._X;
  80. float y = palmPosition.Value._Y;
  81. float z = palmPosition.Value._Z;
  82. GL.Vertex3(-1.0f + x, -1.0f + z, 4.0f - 10 * y);
  83. GL.Vertex3(1.0f, -1.0f, 4.0f);
  84. GL.Vertex3(0.0f, 1.0f, 4.0f);
  85. GL.End();
  86. SwapBuffers();*/
  87. }
  88. protected override void OnResize(EventArgs e)
  89. {
  90. base.OnResize(e);
  91. GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
  92. Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 640.0f);
  93. GL.MatrixMode(MatrixMode.Projection);
  94. GL.LoadMatrix(ref projection);
  95. }
  96. }
  97. }