Started implementing cameras rotating point.
This commit is contained in:
parent
e3e84b4f23
commit
02a6cc3e88
5 changed files with 37 additions and 9 deletions
|
@ -26,9 +26,8 @@ func NewPlayer() *Player {
|
|||
Sprite: &gx.Sprite{
|
||||
Object: &gx.Object{
|
||||
T: gx.Transform {
|
||||
P: gx.Vector{100, 150},
|
||||
S: gx.Vector{5, 5},
|
||||
RA: gx.Vector{200, 200},
|
||||
RA: gx.Vector{320, 240},
|
||||
},
|
||||
},
|
||||
Image: playerImg,
|
||||
|
@ -38,6 +37,9 @@ func NewPlayer() *Player {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Player) Start(e *gx.Engine) {
|
||||
}
|
||||
|
||||
func (p *Player) Update(e *gx.Engine) error {
|
||||
dt := e.DT()
|
||||
c := e.Camera()
|
||||
|
@ -76,6 +78,18 @@ func (p *Player) Update(e *gx.Engine) error {
|
|||
} else {
|
||||
c.Object.T.S.Y += gx.Pi * p.ScaleSpeed * dt
|
||||
}
|
||||
case ebiten.KeyZ :
|
||||
if e.KeyIsPressed(ebiten.KeyShift) {
|
||||
c.Object.T.RA.X -= gx.Pi * p.MoveSpeed * dt
|
||||
} else {
|
||||
c.Object.T.RA.X += gx.Pi * p.MoveSpeed * dt
|
||||
}
|
||||
case ebiten.KeyX :
|
||||
if e.KeyIsPressed(ebiten.KeyShift) {
|
||||
c.Object.T.RA.Y -= gx.Pi * p.MoveSpeed * dt
|
||||
} else {
|
||||
c.Object.T.RA.Y += gx.Pi * p.MoveSpeed * dt
|
||||
}
|
||||
}}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -18,7 +18,10 @@ const (
|
|||
// position, scale and rotation to apply
|
||||
// it to the objects to get the real
|
||||
// transform to display on the screen.
|
||||
func (c *Camera)Matrix(scale bool) Matrix {
|
||||
func (c *Camera)RealMatrix(
|
||||
e *Engine,
|
||||
scale bool,
|
||||
) Matrix {
|
||||
g := &Matrix{}
|
||||
|
||||
// For rotating around.
|
||||
|
@ -27,12 +30,16 @@ func (c *Camera)Matrix(scale bool) Matrix {
|
|||
c.Object.T.RA.Y,
|
||||
)
|
||||
|
||||
g.Rotate(c.Object.T.R)
|
||||
|
||||
g.Translate(
|
||||
-c.Object.T.P.X,
|
||||
c.Object.T.P.Y,
|
||||
)
|
||||
g.Rotate(-c.Object.T.R)
|
||||
|
||||
g.Translate(
|
||||
c.Object.T.RA.X,
|
||||
-c.Object.T.RA.Y,
|
||||
)
|
||||
|
||||
if scale {
|
||||
g.Scale(
|
||||
|
|
|
@ -33,6 +33,10 @@ func (e *Engine) Camera() *Camera {
|
|||
return e.camera
|
||||
}
|
||||
|
||||
func (e *Engine) SetCamera(c *Camera) {
|
||||
e.camera = c
|
||||
}
|
||||
|
||||
func (e *Engine) Keys() []Key {
|
||||
return e.keys
|
||||
}
|
||||
|
@ -50,7 +54,6 @@ func New(
|
|||
Object: &Object{
|
||||
T: Transform{
|
||||
S: Vector{1, 1},
|
||||
RA: Vector{480, 320},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -121,6 +124,7 @@ func (e *engine) Layout(ow, oh int) (int, int) {
|
|||
if e.wcfg.FixedSize {
|
||||
return e.wcfg.Width, e.wcfg.Height
|
||||
}
|
||||
|
||||
return ow, oh
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,13 @@ func (s *Sprite) Draw(
|
|||
i *Image,
|
||||
) {
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
m := s.Object.T.Matrix()
|
||||
m := s.Object.T.Matrix(e)
|
||||
|
||||
if e.camera != nil {
|
||||
m.Concat(e.camera.Matrix(true))
|
||||
m.Concat(e.camera.RealMatrix(
|
||||
e,
|
||||
true,
|
||||
))
|
||||
}
|
||||
|
||||
op.GeoM = m
|
||||
|
|
|
@ -25,7 +25,7 @@ func T() Transform {
|
|||
|
||||
// Returns the GeoM with corresponding
|
||||
// to the transfrom transformation
|
||||
func (t Transform)Matrix() Matrix {
|
||||
func (t Transform)Matrix(e *Engine) Matrix {
|
||||
g := &Matrix{}
|
||||
|
||||
g.Scale(t.S.X, t.S.Y)
|
||||
|
|
Loading…
Reference in a new issue