Point.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. result.Add(new DenseVector(new float[] { relX - size, relY + size, -position.z }));
  40. result.Add(new DenseVector(new float[] { relX + size, relY + size, -position.z }));
  41. result.Add(new DenseVector(new float[] { relX + size, relY - size, -position.z }));
  42. result.Add(new DenseVector(new float[] { relX - size, relY - size, -position.z }));
  43. return result;
  44. }
  45. public uint[] getTriangleIndices()
  46. {
  47. return new uint[] { 0, 1, 2, 0, 2, 3 };
  48. }
  49. public Color getColor()
  50. {
  51. return color;
  52. }
  53. }
  54. }