add rotation

This commit is contained in:
Josh Deprez 2021-08-31 12:52:28 +10:00
parent f3bff2b393
commit 30224c15bf
2 changed files with 6 additions and 4 deletions

View file

@ -24,9 +24,10 @@ type Camera struct {
ID
// Camera controls
Centre image.Point // world coordinates
Filter ebiten.Filter
Zoom float64 // unitless
Centre image.Point // world coordinates
Filter ebiten.Filter
Rotation float64 // radians
Zoom float64 // unitless
game *Game
}

View file

@ -79,8 +79,9 @@ func (s *Scene) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
// Compute common matrix (parts independent of parallax, which is step 1).
// Moving centre to the origin happens per component.
var comm ebiten.GeoM
// 2. Zoom (this is also where rotation would be)
// 2. Zoom and rotate
comm.Scale(zoom, zoom)
comm.Rotate(s.Camera.Rotation)
// 3. Move the origin to the centre of screen space.
comm.Translate(sw2, sh2)
// 4. Apply transforms from the caller.