diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index d2150ad..7a9fdd4 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -39,7 +39,7 @@ func NewPlayer() *Player { func (p *Player) Start(e *gx.Engine) { c := e.Camera() - c.Object.T.RA = gx.V(360, -120) + c.Object.T.RA = gx.V(360, -240) } func (p *Player) Update(e *gx.Engine) error { diff --git a/src/gx/camera.go b/src/gx/camera.go index 69d20b2..6556a7b 100644 --- a/src/gx/camera.go +++ b/src/gx/camera.go @@ -24,11 +24,13 @@ func (c *Camera)RealMatrix( ) Matrix { g := &Matrix{} - // For rotating around. - g.Translate( - -c.Object.T.RA.X, - c.Object.T.RA.Y, - ) + + if scale { + g.Scale( + c.Object.T.S.X, + c.Object.T.S.Y, + ) + } g.Translate( -c.Object.T.P.X, @@ -41,13 +43,6 @@ func (c *Camera)RealMatrix( -c.Object.T.RA.Y, ) - if scale { - g.Scale( - c.Object.T.S.X, - c.Object.T.S.Y, - ) - } - return *g } diff --git a/src/gx/main.go b/src/gx/main.go index 4b180f3..a375e43 100644 --- a/src/gx/main.go +++ b/src/gx/main.go @@ -137,6 +137,7 @@ func (e *Engine) DT() Float { func (e *Engine) Run() error { ebiten.SetWindowTitle(e.wcfg.Title) ebiten.SetWindowSize(e.wcfg.Width, e.wcfg.Height) + ebiten.SetWindowSizeLimits(1, 1, e.wcfg.Width, e.wcfg.Height) e.lastTime = time.Now() diff --git a/src/gx/sprite.go b/src/gx/sprite.go index 12dc19b..e001408 100644 --- a/src/gx/sprite.go +++ b/src/gx/sprite.go @@ -15,8 +15,9 @@ func (s *Sprite) Draw( i *Image, ) { op := &ebiten.DrawImageOptions{} - m := s.Object.T.Matrix(e) + m := &Matrix{} + m.Concat(s.Object.T.Matrix(e)) if e.camera != nil { m.Concat(e.camera.RealMatrix( e, @@ -24,7 +25,7 @@ func (s *Sprite) Draw( )) } - op.GeoM = m + op.GeoM = *m i.DrawImage(s.Image, op) } diff --git a/src/gx/transform.go b/src/gx/transform.go index b4b2fdc..c322b6b 100644 --- a/src/gx/transform.go +++ b/src/gx/transform.go @@ -2,6 +2,7 @@ package gx import ( "github.com/hajimehoshi/ebiten/v2" + "math" ) type Matrix = ebiten.GeoM @@ -22,6 +23,25 @@ func V(x, y Float) Vector { return Vector{x, y} } +// Returns the vector with the matrix applied +func (v Vector) Apply(m *Matrix) Vector { + x, y := m.Apply(v.X, v.Y) + return V(x, y) +} + +// Returns the vector rotated by "a" angle in radians. +func (v Vector) Rotate(a Float) Vector { + m := &Matrix{} + m.Rotate(a) + return v.Apply(m) +} + +// Returns the normalized vector. +func (v Vector) Norm() Vector { + l := math.Sqrt(v.X*v.X + v.Y*v.Y) + return V(v.X / l, v.Y / l) +} + func T() Transform { ret := Transform{} return ret