clean up projection from camera

This commit is contained in:
Josh Deprez 2021-09-07 14:18:09 +10:00
parent 766ee272d5
commit da7d988383
2 changed files with 5 additions and 8 deletions

View file

@ -27,10 +27,9 @@ type Camera struct {
// Camera controls // Camera controls
// These directly manipulate the camera. If you want to restrict the camera // These directly manipulate the camera. If you want to restrict the camera
// view area to the child's bounding rectangle, use PointAt. // view area to the child's bounding rectangle, use PointAt.
Centre image.Point // world coordinates Centre image.Point // voxel coordinates
Rotation float64 // radians Rotation float64 // radians
Zoom float64 // unitless Zoom float64 // unitless
Projection IntProjection
game *Game game *Game
} }
@ -41,7 +40,7 @@ func (c *Camera) PointAt(centre Int3, 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.Projection.Project(centre) c.Centre = c.game.Projection.Project(centre)
c.Zoom = zoom c.Zoom = zoom
return return
} }
@ -63,7 +62,7 @@ func (c *Camera) PointAt(centre Int3, 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)
cent := c.Projection.Project(centre) cent := c.game.Projection.Project(centre)
if cent.X-swz < br.Min.X { if cent.X-swz < br.Min.X {
cent.X = br.Min.X + swz cent.X = br.Min.X + swz
} }

View file

@ -69,8 +69,6 @@ func main() {
&engine.Camera{ &engine.Camera{
ID: "game_camera", ID: "game_camera",
Child: lev1, Child: lev1,
// Each step in Z becomes a step in Y:
Projection: engine.IntProjection{X: 0, Y: 1},
}, },
&engine.DebugToast{ID: "toast", Pos: image.Pt(0, 15)}, &engine.DebugToast{ID: "toast", Pos: image.Pt(0, 15)},
engine.PerfDisplay{}, engine.PerfDisplay{},