Point.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using OpenTK.Graphics.OpenGL;
  8. using MathNet.Numerics.LinearAlgebra.Single;
  9. namespace bbiwarg.Graphics
  10. {
  11. class Point : IGraphicElement
  12. {
  13. public Vertex position;
  14. public Color color;
  15. public float size;
  16. public Point(Vertex position, Color color, float size)
  17. {
  18. this.position = position;
  19. this.color = color;
  20. this.size = size;
  21. }
  22. public void draw(int width, int height)
  23. {
  24. GL.Color4(color);
  25. float relX = position.x - width / 2;
  26. float relY = height / 2 - position.y;
  27. GL.Begin(BeginMode.Polygon);
  28. GL.Vertex3(relX - size, relY + size, -position.z);
  29. GL.Vertex3(relX + size, relY + size, -position.z);
  30. GL.Vertex3(relX + size, relY - size, -position.z);
  31. GL.Vertex3(relX - size, relY - size, -position.z);
  32. GL.End();
  33. }
  34. public List<Vector> getVertices(int width, int height)
  35. {
  36. float relX = position.x - width / 2;
  37. float relY = height / 2 - position.y;
  38. List<Vector> result = new List<Vector>();
  39. Vector temp = new DenseVector(new float[] { relX - size, relY + size, -position.z });
  40. result.Add(temp);
  41. temp = new DenseVector(new float[] { relX + size, relY + size, -position.z });
  42. result.Add(temp);
  43. temp = new DenseVector(new float[] { relX + size, relY - size, -position.z });
  44. result.Add(temp);
  45. temp = new DenseVector(new float[] { relX - size, relY - size, -position.z });
  46. result.Add(temp);
  47. return result;
  48. }
  49. public uint[] getTriangleIndices()
  50. {
  51. return new uint[] { 0, 1, 2, 0, 2, 3 };
  52. }
  53. public Color getColor()
  54. {
  55. return color;
  56. }
  57. }
  58. }