Triangles.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Graphics;
  7. namespace StarWarrior.Primitives
  8. {
  9. public class Triangle
  10. {
  11. PrimitiveBatch batch;
  12. List<Vector2> point = new List<Vector2>();
  13. Color color = Color.White;
  14. bool fill = true;
  15. RasterizerState state;
  16. GraphicsDevice device;
  17. public Triangle(GraphicsDevice device,PrimitiveBatch primitiveBatch)
  18. {
  19. this.device = device;
  20. this.batch = primitiveBatch;
  21. state = new RasterizerState();
  22. state.CullMode = CullMode.CullCounterClockwiseFace;
  23. state.FillMode = FillMode.WireFrame;
  24. }
  25. public void AddTriangle(float x1, float y1, float x2, float y2, float x3, float y3)
  26. {
  27. point.Add(new Vector2(x1,y1));
  28. point.Add(new Vector2(x2, y2));
  29. point.Add(new Vector2(x3, y3));
  30. }
  31. public void SetColor(Color color)
  32. {
  33. this.color = color;
  34. }
  35. public void SetFillMode(bool fill)
  36. {
  37. this.fill = fill;
  38. }
  39. public void Draw(Vector2 transform)
  40. {
  41. //if (fill == false)
  42. //{
  43. // device.RasterizerState = state;
  44. //}
  45. foreach (var item in point)
  46. {
  47. batch.AddVertex(item + transform, color);
  48. }
  49. //if (fill == false)
  50. //{
  51. // device.RasterizerState = RasterizerState.CullCounterClockwise;
  52. //}
  53. }
  54. }
  55. }