...
This commit is contained in:
parent
e03c1479e2
commit
4f42968d2d
5 changed files with 32 additions and 15 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue