Program.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Iisu;
  9. namespace bbiwarg
  10. {
  11. class Program : GameWindow
  12. {
  13. static void Main(string[] args)
  14. {
  15. Program demo = new Program();
  16. demo.init();
  17. demo.Run(30);
  18. }
  19. protected override void OnLoad(EventArgs e)
  20. {
  21. base.OnLoad(e);
  22. Title = "Hello OpenTK!";
  23. GL.ClearColor(Color.CornflowerBlue);
  24. }
  25. protected override void OnRenderFrame(FrameEventArgs e)
  26. {
  27. base.OnRenderFrame(e);
  28. device.UpdateFrame(true);
  29. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  30. Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
  31. GL.MatrixMode(MatrixMode.Modelview);
  32. GL.LoadMatrix(ref modelview);
  33. // triangle
  34. GL.Begin(BeginMode.Triangles);
  35. float x = palmPosition.Value._X;
  36. float y = palmPosition.Value._Y;
  37. float z = palmPosition.Value._Z;
  38. GL.Vertex3(-1.0f + x, -1.0f + z, 4.0f - 10*y);
  39. GL.Vertex3(1.0f, -1.0f, 4.0f);
  40. GL.Vertex3(0.0f, 1.0f, 4.0f);
  41. GL.End();
  42. SwapBuffers();
  43. device.ReleaseFrame();
  44. }
  45. protected override void OnResize(EventArgs e)
  46. {
  47. base.OnResize(e);
  48. GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
  49. Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 64.0f);
  50. GL.MatrixMode(MatrixMode.Projection);
  51. GL.LoadMatrix(ref projection);
  52. }
  53. private IHandle handle;
  54. private IDevice device;
  55. private IDataHandle<Iisu.Data.Vector3> palmPosition;
  56. public void init()
  57. {
  58. handle = Iisu.Iisu.Context.CreateHandle();
  59. device = handle.InitializeDevice();
  60. IEventManager em = handle.EventManager;
  61. palmPosition = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmPosition3D");
  62. device.Start();
  63. }
  64. }
  65. }