camera point at Point3
This commit is contained in:
parent
5699d70be6
commit
843db79af9
2 changed files with 15 additions and 13 deletions
|
@ -35,11 +35,12 @@ type Camera struct {
|
||||||
|
|
||||||
// PointAt points the camera at a particular centre point and zoom, but adjusts
|
// PointAt points the camera at a particular centre point and zoom, but adjusts
|
||||||
// for the bounds of the child component (if available).
|
// for the bounds of the child component (if available).
|
||||||
func (c *Camera) PointAt(centre image.Point, zoom float64) {
|
func (c *Camera) PointAt(centre Point3, zoom float64) {
|
||||||
// Special sauce: if Child has a BoundingRect, make some adjustments
|
// Special sauce: if Child has a BoundingRect, make some adjustments
|
||||||
bnd, ok := c.Child.(Bounder)
|
bnd, ok := c.Child.(Bounder)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.Centre, c.Zoom = centre, zoom
|
c.Centre = centre.IsoProject(c.IsoProjection)
|
||||||
|
c.Zoom = zoom
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,19 +61,20 @@ func (c *Camera) PointAt(centre image.Point, zoom float64) {
|
||||||
// Camera frame currently Rectangle{ centre ± (screen/(2*zoom)) }.
|
// Camera frame currently Rectangle{ centre ± (screen/(2*zoom)) }.
|
||||||
sw2, sh2 := cfloat(c.game.ScreenSize.Div(2))
|
sw2, sh2 := cfloat(c.game.ScreenSize.Div(2))
|
||||||
swz, shz := int(sw2/zoom), int(sh2/zoom)
|
swz, shz := int(sw2/zoom), int(sh2/zoom)
|
||||||
if centre.X-swz < br.Min.X {
|
cent := centre.IsoProject(c.IsoProjection)
|
||||||
centre.X = br.Min.X + swz
|
if cent.X-swz < br.Min.X {
|
||||||
|
cent.X = br.Min.X + swz
|
||||||
}
|
}
|
||||||
if centre.Y-shz < br.Min.Y {
|
if cent.Y-shz < br.Min.Y {
|
||||||
centre.Y = br.Min.Y + shz
|
cent.Y = br.Min.Y + shz
|
||||||
}
|
}
|
||||||
if centre.X+swz > br.Max.X {
|
if cent.X+swz > br.Max.X {
|
||||||
centre.X = br.Max.X - swz
|
cent.X = br.Max.X - swz
|
||||||
}
|
}
|
||||||
if centre.Y+shz > br.Max.Y {
|
if cent.Y+shz > br.Max.Y {
|
||||||
centre.Y = br.Max.Y - shz
|
cent.Y = br.Max.Y - shz
|
||||||
}
|
}
|
||||||
c.Centre, c.Zoom = centre, zoom
|
c.Centre, c.Zoom = cent, zoom
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare grabs a copy of game (needed for screen dimensions)
|
// Prepare grabs a copy of game (needed for screen dimensions)
|
||||||
|
|
|
@ -70,8 +70,8 @@ func (aw *Awakeman) Update() error {
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyShift) {
|
if ebiten.IsKeyPressed(ebiten.KeyShift) {
|
||||||
z = 2.0
|
z = 2.0
|
||||||
}
|
}
|
||||||
pos := aw.Sprite.Actor.Pos.XY()
|
pos := aw.Sprite.Actor.Pos
|
||||||
size := aw.Sprite.Actor.Size.XY()
|
size := aw.Sprite.Actor.Size
|
||||||
aw.camera.PointAt(pos.Add(size.Div(2)), z)
|
aw.camera.PointAt(pos.Add(size.Div(2)), z)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue