OutputTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 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. ushort depth = depthImage.getDepth(x, y);
  51. int depth2 = depth;
  52. //depth = 60;
  53. int relX = x - width / 2;
  54. int relY = y - height / 2;
  55. GL.Begin(BeginMode.Polygon);
  56. GL.Vertex3(relX-0.5f, relY+0.5f, -depth2);
  57. GL.Vertex3(relX+0.5f, relY+0.5f, -depth2);
  58. GL.Vertex3(relX+0.5f, relY-0.5f, -depth2);
  59. GL.Vertex3(relX-0.5f, relY-0.5f, -depth2);
  60. GL.End();
  61. }
  62. }
  63. /*
  64. GL.Begin(BeginMode.Triangles);
  65. GL.Vertex3(0.0f, 0.0f, -4.0f);
  66. GL.Vertex3(2.0f, 0.0f, -4.0f);
  67. GL.Vertex3(0.0f, 1.0f, -4.0f);
  68. GL.End();
  69. */
  70. SwapBuffers();
  71. if(isActive) {
  72. source.releaseFrame();
  73. }
  74. /*
  75. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  76. Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
  77. GL.MatrixMode(MatrixMode.Modelview);
  78. GL.LoadMatrix(ref modelview);
  79. // triangle
  80. GL.Begin(BeginMode.Triangles);
  81. float x = palmPosition.Value._X;
  82. float y = palmPosition.Value._Y;
  83. float z = palmPosition.Value._Z;
  84. GL.Vertex3(-1.0f + x, -1.0f + z, 4.0f - 10 * y);
  85. GL.Vertex3(1.0f, -1.0f, 4.0f);
  86. GL.Vertex3(0.0f, 1.0f, 4.0f);
  87. GL.End();
  88. SwapBuffers();*/
  89. }
  90. protected override void OnResize(EventArgs e)
  91. {
  92. base.OnResize(e);
  93. GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
  94. Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 640.0f);
  95. GL.MatrixMode(MatrixMode.Projection);
  96. GL.LoadMatrix(ref projection);
  97. }
  98. }
  99. }