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

@ -26,6 +26,7 @@ type Camera struct {
// Camera controls // Camera controls
Centre image.Point // world coordinates Centre image.Point // world coordinates
Filter ebiten.Filter Filter ebiten.Filter
Rotation float64 // radians
Zoom float64 // unitless Zoom float64 // unitless
game *Game 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). // Compute common matrix (parts independent of parallax, which is step 1).
// Moving centre to the origin happens per component. // Moving centre to the origin happens per component.
var comm ebiten.GeoM var comm ebiten.GeoM
// 2. Zoom (this is also where rotation would be) // 2. Zoom and rotate
comm.Scale(zoom, zoom) comm.Scale(zoom, zoom)
comm.Rotate(s.Camera.Rotation)
// 3. Move the origin to the centre of screen space. // 3. Move the origin to the centre of screen space.
comm.Translate(sw2, sh2) comm.Translate(sw2, sh2)
// 4. Apply transforms from the caller. // 4. Apply transforms from the caller.