Implemented proper transformation of rectangle into triangles.

This commit is contained in:
Andrey Parhomenko 2023-05-30 22:51:50 +03:00
parent bc2b5809c5
commit ccefc2669b
2 changed files with 7 additions and 14 deletions

View file

@ -53,6 +53,7 @@ func NewRect() *Rect {
} }
func (r *Rect) Update(e *gx.Engine) error { func (r *Rect) Update(e *gx.Engine) error {
r.R += 0.3 * e.DT()
return nil return nil
} }
@ -90,7 +91,7 @@ func (p *Player) Draw(e *gx.Engine, i *gx.Image) {
Rectangle: gx.Rectangle{ Rectangle: gx.Rectangle{
Transform: gx.Transform{ Transform: gx.Transform{
P: player.P, P: player.P,
S: gx.Vector{10, 10}, S: gx.Vector{100, 100},
}, },
}, },
Color: gx.Color{0, 0, gx.MaxColorV, gx.MaxColorV}, Color: gx.Color{0, 0, gx.MaxColorV, gx.MaxColorV},

View file

@ -41,8 +41,8 @@ func (r Rectangle) Triangles() Triangles {
p1 := V(0, 0).Apply(&m) p1 := V(0, 0).Apply(&m)
p2 := V(1, 0).Apply(&m) p2 := V(1, 0).Apply(&m)
p3 := V(1, -1).Apply(&m) p3 := V(1, 1).Apply(&m)
p4 := V(0, -1).Apply(&m) p4 := V(0, 1).Apply(&m)
//fmt.Println("in:", p1, p2, p3, p4) //fmt.Println("in:", p1, p2, p3, p4)
@ -66,17 +66,14 @@ func (r *DrawableRectangle) Draw(
e *Engine, e *Engine,
i *Image, i *Image,
) { ) {
t := r.Transform m := r.Matrix()
rm := e.Camera().RealMatrix(e)
m.Concat(rm)
// Draw solid color if no shader. // Draw solid color if no shader.
if r.Shader == nil { if r.Shader == nil {
img := NewImage(1, 1) img := NewImage(1, 1)
img.Set(0, 0, r.Color) img.Set(0, 0, r.Color)
m := t.Matrix()
rm := e.Camera().RealMatrix(e)
m.Concat(rm)
opts := &ebiten.DrawImageOptions{ opts := &ebiten.DrawImageOptions{
GeoM: m, GeoM: m,
@ -103,11 +100,6 @@ func (r *DrawableRectangle) Draw(
t.S.Y *= r.H t.S.Y *= r.H
}*/ }*/
rm := e.Camera().RealMatrix(e)
m := t.Matrix()
m.Concat(rm)
// Drawing with shader. // Drawing with shader.
opts := &ebiten.DrawRectShaderOptions{ opts := &ebiten.DrawRectShaderOptions{
GeoM: m, GeoM: m,