Use Ebitens coordinate system for showing.
This commit is contained in:
parent
421321cc62
commit
bc2b5809c5
7 changed files with 38 additions and 53 deletions
|
@ -37,11 +37,11 @@ func main() {
|
||||||
|
|
||||||
t := gx.Rectangle{
|
t := gx.Rectangle{
|
||||||
Transform: gx.Transform{
|
Transform: gx.Transform{
|
||||||
S: gx.Vector{1, 1},
|
S: gx.Vector{100, 200},
|
||||||
P: gx.Point{0, 200},
|
P: gx.Point{0, 200},
|
||||||
|
RA: gx.Point{0, 0},
|
||||||
|
R: 0,
|
||||||
},
|
},
|
||||||
W: 100,
|
|
||||||
H: 200,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
points := []gx.Point{
|
points := []gx.Point{
|
||||||
|
|
|
@ -26,9 +26,12 @@ type Rect struct {
|
||||||
func NewRect() *Rect {
|
func NewRect() *Rect {
|
||||||
return &Rect{&gx.DrawableRectangle{
|
return &Rect{&gx.DrawableRectangle{
|
||||||
Rectangle: gx.Rectangle{
|
Rectangle: gx.Rectangle{
|
||||||
Transform: gx.T(),
|
Transform: gx.Transform{
|
||||||
W: 200,
|
S: gx.Vector{
|
||||||
H: 400,
|
X: 200,
|
||||||
|
Y: 400,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Color: gx.Color{
|
Color: gx.Color{
|
||||||
gx.MaxColorV,
|
gx.MaxColorV,
|
||||||
|
@ -85,9 +88,10 @@ func (p *Player) Draw(e *gx.Engine, i *gx.Image) {
|
||||||
p.Sprite.Draw(e, i)
|
p.Sprite.Draw(e, i)
|
||||||
r := &gx.DrawableRectangle{
|
r := &gx.DrawableRectangle{
|
||||||
Rectangle: gx.Rectangle{
|
Rectangle: gx.Rectangle{
|
||||||
Transform: p.Transform,
|
Transform: gx.Transform{
|
||||||
W: 10,
|
P: player.P,
|
||||||
H: 10,
|
S: gx.Vector{10, 10},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Color: gx.Color{0, 0, gx.MaxColorV, gx.MaxColorV},
|
Color: gx.Color{0, 0, gx.MaxColorV, gx.MaxColorV},
|
||||||
}
|
}
|
||||||
|
@ -97,7 +101,7 @@ func (p *Player) Draw(e *gx.Engine, i *gx.Image) {
|
||||||
func (p *Player) Start(e *gx.Engine, v ...any) {
|
func (p *Player) Start(e *gx.Engine, v ...any) {
|
||||||
fmt.Println("starting")
|
fmt.Println("starting")
|
||||||
c := e.Camera()
|
c := e.Camera()
|
||||||
c.RA = gx.V(360, -240)
|
c.RA = gx.V(360, 240)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) Update(e *gx.Engine) error {
|
func (p *Player) Update(e *gx.Engine) error {
|
||||||
|
|
|
@ -16,22 +16,10 @@ func (c *Camera)RealMatrix(
|
||||||
e *Engine,
|
e *Engine,
|
||||||
) Matrix {
|
) Matrix {
|
||||||
g := &Matrix{}
|
g := &Matrix{}
|
||||||
|
g.Scale(c.S.X, c.S.Y)
|
||||||
g.Scale(
|
g.Translate(-c.P.X, -c.P.Y)
|
||||||
c.S.X,
|
g.Rotate(c.R)
|
||||||
c.S.Y,
|
g.Translate(c.RA.X, c.RA.Y)
|
||||||
)
|
|
||||||
|
|
||||||
g.Translate(
|
|
||||||
-c.P.X,
|
|
||||||
c.P.Y,
|
|
||||||
)
|
|
||||||
g.Rotate(-c.R)
|
|
||||||
|
|
||||||
g.Translate(
|
|
||||||
c.RA.X,
|
|
||||||
-c.RA.Y,
|
|
||||||
)
|
|
||||||
|
|
||||||
return *g
|
return *g
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,7 @@ package gx
|
||||||
|
|
||||||
// The structure represents any circles.
|
// The structure represents any circles.
|
||||||
type Circle struct {
|
type Circle struct {
|
||||||
// Position.
|
Transform
|
||||||
P Point
|
|
||||||
// Radius.
|
|
||||||
R Float
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Circle) ColliderSimplify() Rectangle {
|
|
||||||
return Rectangle{
|
|
||||||
W: c.R * 2,
|
|
||||||
H: c.R * 2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||||
"github.com/surdeus/godat/src/sparsex"
|
"github.com/surdeus/godat/src/sparsex"
|
||||||
"github.com/surdeus/godat/src/poolx"
|
"github.com/surdeus/godat/src/poolx"
|
||||||
//"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,6 +56,9 @@ func (e *Engine) Keys() []Key {
|
||||||
func New(
|
func New(
|
||||||
cfg *WindowConfig,
|
cfg *WindowConfig,
|
||||||
) *Engine {
|
) *Engine {
|
||||||
|
w := Float(cfg.Width)
|
||||||
|
h := Float(cfg.Height)
|
||||||
|
fmt.Println("res:", w, h)
|
||||||
return &Engine{
|
return &Engine{
|
||||||
wcfg: cfg,
|
wcfg: cfg,
|
||||||
layers: sparsex.New[
|
layers: sparsex.New[
|
||||||
|
@ -65,6 +68,7 @@ func New(
|
||||||
camera: &Camera{
|
camera: &Camera{
|
||||||
Transform: Transform{
|
Transform: Transform{
|
||||||
S: Vector{1, 1},
|
S: Vector{1, 1},
|
||||||
|
RA: V(w/2, h/2),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
updaters: poolx.New[Updater](),
|
updaters: poolx.New[Updater](),
|
|
@ -12,10 +12,8 @@ type Rectangle struct {
|
||||||
// Position of up left corner
|
// Position of up left corner
|
||||||
// and the point to
|
// and the point to
|
||||||
// rotate around(relatively of position, not absolute).
|
// rotate around(relatively of position, not absolute).
|
||||||
|
// Scale represent width and height.
|
||||||
Transform
|
Transform
|
||||||
// Width and height.
|
|
||||||
W, H Float
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The type describes rectangle that can be drawn.
|
// The type describes rectangle that can be drawn.
|
||||||
|
@ -40,10 +38,13 @@ func (r Rectangle) Corners() []Point {
|
||||||
// Get 2 triangles that the rectangle consists of.
|
// Get 2 triangles that the rectangle consists of.
|
||||||
func (r Rectangle) Triangles() Triangles {
|
func (r Rectangle) Triangles() Triangles {
|
||||||
m := r.Matrix()
|
m := r.Matrix()
|
||||||
p1 := r.P.Apply(&m)
|
|
||||||
p2 := r.P.Add(Vector{r.W, 0}).Apply(&m)
|
p1 := V(0, 0).Apply(&m)
|
||||||
p3 := r.P.Add(Vector{r.W, -r.H}).Apply(&m)
|
p2 := V(1, 0).Apply(&m)
|
||||||
p4 := r.P.Add(Vector{0, -r.H}).Apply(&m)
|
p3 := V(1, -1).Apply(&m)
|
||||||
|
p4 := V(0, -1).Apply(&m)
|
||||||
|
|
||||||
|
//fmt.Println("in:", p1, p2, p3, p4)
|
||||||
|
|
||||||
return Triangles{
|
return Triangles{
|
||||||
Triangle{p1, p2, p3},
|
Triangle{p1, p2, p3},
|
||||||
|
@ -72,9 +73,6 @@ func (r *DrawableRectangle) Draw(
|
||||||
img := NewImage(1, 1)
|
img := NewImage(1, 1)
|
||||||
img.Set(0, 0, r.Color)
|
img.Set(0, 0, r.Color)
|
||||||
|
|
||||||
t.S.X *= r.W
|
|
||||||
t.S.Y *= r.H
|
|
||||||
|
|
||||||
m := t.Matrix()
|
m := t.Matrix()
|
||||||
rm := e.Camera().RealMatrix(e)
|
rm := e.Camera().RealMatrix(e)
|
||||||
|
|
||||||
|
@ -89,21 +87,21 @@ func (r *DrawableRectangle) Draw(
|
||||||
|
|
||||||
|
|
||||||
// Use the Color as base image if no is provided.
|
// Use the Color as base image if no is provided.
|
||||||
var did bool
|
//var did bool
|
||||||
if r.Images[0] == nil {
|
if r.Images[0] == nil {
|
||||||
r.Images[0] = NewImage(1, 1)
|
r.Images[0] = NewImage(1, 1)
|
||||||
r.Images[0].Set(0, 0, r.Color)
|
r.Images[0].Set(0, 0, r.Color)
|
||||||
did = true
|
//did = true
|
||||||
}
|
}
|
||||||
|
|
||||||
w, h := r.Images[0].Size()
|
w, h := r.Images[0].Size()
|
||||||
if !did {
|
/*if !did {
|
||||||
t.S.X /= Float(w)
|
t.S.X /= Float(w)
|
||||||
t.S.Y /= Float(h)
|
t.S.Y /= Float(h)
|
||||||
|
|
||||||
t.S.X *= r.W
|
t.S.X *= r.W
|
||||||
t.S.Y *= r.H
|
t.S.Y *= r.H
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
rm := e.Camera().RealMatrix(e)
|
rm := e.Camera().RealMatrix(e)
|
||||||
|
|
|
@ -21,14 +21,14 @@ func T() Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the GeoM with corresponding
|
// Returns the GeoM with corresponding
|
||||||
// to the transfrom transformation
|
// to the transfrom transformation.
|
||||||
func (t Transform)Matrix() Matrix {
|
func (t Transform)Matrix() Matrix {
|
||||||
g := &Matrix{}
|
g := &Matrix{}
|
||||||
|
|
||||||
g.Scale(t.S.X, t.S.Y)
|
g.Scale(t.S.X, t.S.Y)
|
||||||
g.Translate(-t.RA.X, -t.RA.Y)
|
g.Translate(-t.RA.X, -t.RA.Y)
|
||||||
g.Rotate(t.R)
|
g.Rotate(t.R)
|
||||||
g.Translate(t.P.X, -t.P.Y)
|
g.Translate(t.P.X, t.P.Y)
|
||||||
|
|
||||||
return *g
|
return *g
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue