commit
f081e9e6b4
2 changed files with 43 additions and 12 deletions
|
@ -24,12 +24,13 @@ type Rect struct {
|
|||
}
|
||||
|
||||
type Tri struct {
|
||||
*gx.DrawableTriangles
|
||||
*gx.DrawablePolygon
|
||||
}
|
||||
|
||||
func NewTri() *Tri {
|
||||
ret := &Tri{}
|
||||
ret.DrawableTriangles = &gx.DrawableTriangles{}
|
||||
ret.DrawablePolygon = &gx.DrawablePolygon{}
|
||||
ret.Transform.S = gx.V(1, 1)
|
||||
|
||||
ret.Triangles = gx.Triangles{
|
||||
gx.Triangle{
|
||||
|
@ -88,6 +89,7 @@ var (
|
|||
player *Player
|
||||
rectMove gx.Rectangle
|
||||
rect *Rect
|
||||
tri *Tri
|
||||
)
|
||||
|
||||
func NewPlayer() *Player {
|
||||
|
@ -190,6 +192,12 @@ func (p *Player) Update(e *gx.Engine) error {
|
|||
} else {
|
||||
c.RA.Y += gx.Pi * p.MoveSpeed * dt
|
||||
}
|
||||
case ebiten.KeyV :
|
||||
if e.KeyIsPressed(ebiten.KeyShift) {
|
||||
tri.R -= gx.Pi * 0.3 * dt
|
||||
} else {
|
||||
tri.R += gx.Pi * 0.3 * dt
|
||||
}
|
||||
case ebiten.KeyLeftBracket :
|
||||
if e.KeyIsPressed(ebiten.KeyShift) {
|
||||
rect.R -= gx.Pi * 0.3 * dt
|
||||
|
@ -241,7 +249,7 @@ func main() {
|
|||
|
||||
player = NewPlayer()
|
||||
rect = NewRect()
|
||||
tri := NewTri()
|
||||
tri = NewTri()
|
||||
|
||||
e.Add(1, &Debug{})
|
||||
e.Add(0, player)
|
||||
|
|
|
@ -1,29 +1,52 @@
|
|||
package gx
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
type PolygonTriangle struct {
|
||||
P, S int
|
||||
T, S int
|
||||
}
|
||||
|
||||
// Grouped triangles type.
|
||||
type Polygon struct {
|
||||
Transform
|
||||
base Triangle
|
||||
triangles []PolygonTriangle
|
||||
Triangles
|
||||
}
|
||||
|
||||
// Polygon that can be drawn.
|
||||
type DrawablePolygon struct {
|
||||
Polygon
|
||||
|
||||
ShaderOptions
|
||||
Visibility
|
||||
Colority
|
||||
}
|
||||
|
||||
func NewPolygon(base Triangle) *Polygon {
|
||||
ret := &Polygon{
|
||||
Transform: T(),
|
||||
base: base,
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *Polygon) Triangles() Triangles {
|
||||
return Triangles{}
|
||||
func (p *DrawablePolygon) Draw(
|
||||
e *Engine,
|
||||
i *Image,
|
||||
) {
|
||||
(&DrawableTriangles{
|
||||
Visibility: p.Visibility,
|
||||
Colority: p.Colority,
|
||||
ShaderOptions: p.ShaderOptions,
|
||||
Triangles: p.MakeTriangles(),
|
||||
}).Draw(e, i)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue