OutputTest.cs 3.6 KB

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