vertice.go 818 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package gg
  2. import "github.com/hajimehoshi/ebiten/v2"
  3. import "surdeus.su/core/gg/mx"
  4. type EVertice = ebiten.Vertex
  5. // Ebitens vector in better abstractions like Vectors.
  6. type Vertice struct {
  7. Dst mx.Vector
  8. Src mx.Vector
  9. Color
  10. }
  11. // Convert the vertice into the Ebiten's type.
  12. func (v Vertice) ToAPI() EVertice {
  13. r, g, b, a := v.RGBA()
  14. return EVertice {
  15. DstX: float32(v.Dst.X),
  16. DstY: float32(v.Dst.Y),
  17. SrcX: float32(v.Src.X),
  18. SrcY: float32(v.Src.Y),
  19. ColorR: float32(r)/(float32(MaxColorValue)),
  20. ColorG: float32(g)/(float32(MaxColorValue)),
  21. ColorB: float32(b)/(float32(MaxColorValue)),
  22. ColorA: float32(a)/(float32(MaxColorValue)),
  23. }
  24. }
  25. type Vertices []Vertice
  26. func (vs Vertices) ToAPI() []EVertice {
  27. ret := make([]EVertice, len(vs))
  28. for i, v := range vs {
  29. ret[i] = v.ToAPI()
  30. }
  31. return ret
  32. }