2023-10-23 15:45:18 +03:00
|
|
|
package gg
|
2023-06-03 22:41:00 +03:00
|
|
|
|
2023-06-20 14:04:55 +03:00
|
|
|
import (
|
|
|
|
)
|
|
|
|
|
2023-06-15 20:18:58 +03:00
|
|
|
type PolygonTriangle struct {
|
2023-06-20 14:04:55 +03:00
|
|
|
T, S int
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|
2023-06-20 14:04:55 +03:00
|
|
|
// Grouped triangles type.
|
2023-06-15 20:18:58 +03:00
|
|
|
type Polygon struct {
|
|
|
|
Transform
|
2023-06-20 14:04:55 +03:00
|
|
|
Triangles
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|
2023-12-23 00:09:07 +03:00
|
|
|
func (p *Polygon) ContainsPoint(pnt Point) bool {
|
|
|
|
return p.MakeTriangles().ContainsPoint(pnt)
|
|
|
|
}
|
|
|
|
|
2023-06-20 14:04:55 +03:00
|
|
|
// Polygon that can be drawn.
|
2023-06-15 20:18:58 +03:00
|
|
|
type DrawablePolygon struct {
|
|
|
|
Polygon
|
2023-06-20 14:04:55 +03:00
|
|
|
|
2023-06-15 20:18:58 +03:00
|
|
|
ShaderOptions
|
2023-06-20 14:04:55 +03:00
|
|
|
Visibility
|
|
|
|
Colority
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|
2023-06-20 14:04:55 +03:00
|
|
|
func (p *Polygon) MakeTriangles() Triangles {
|
|
|
|
mv := p.Matrix()
|
|
|
|
m := &mv
|
|
|
|
|
|
|
|
ret := make(Triangles, len(p.Triangles))
|
|
|
|
for i, t := range p.Triangles {
|
|
|
|
ret[i] = Triangle{
|
|
|
|
t[0].Apply(m),
|
|
|
|
t[1].Apply(m),
|
|
|
|
t[2].Apply(m),
|
|
|
|
}
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
2023-06-20 14:04:55 +03:00
|
|
|
|
2023-06-03 22:41:00 +03:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-12-20 22:39:33 +03:00
|
|
|
func (p *DrawablePolygon) Draw(c *Context) {
|
2023-06-20 14:04:55 +03:00
|
|
|
(&DrawableTriangles{
|
|
|
|
Visibility: p.Visibility,
|
|
|
|
Colority: p.Colority,
|
|
|
|
ShaderOptions: p.ShaderOptions,
|
|
|
|
Triangles: p.MakeTriangles(),
|
2023-12-20 22:39:33 +03:00
|
|
|
}).Draw(c)
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|