Last active
February 19, 2018 07:51
-
-
Save quillaja/5a8238fd7e41a897aa4ed7366c469799 to your computer and use it in GitHub Desktop.
camera example from https://github.com/elliotmr/tmx/tree/master/pixeltmx/example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cameraOrigin := pixel.ZV.Add(win.Bounds().Center()) | |
scale := 1.0 | |
dragOrigin := pixel.V(0, 0) | |
second := time.Tick(time.Second) | |
viewMatrix := pixel.IM | |
frames := 0 | |
for !win.Closed() { | |
if win.MouseScroll().Y != 0 { | |
factor := math.Pow(1.2, win.MouseScroll().Y) | |
zoomDeltaStart := viewMatrix.Unproject(win.MousePosition()) | |
scale *= factor | |
cameraOrigin = zoomDeltaStart.Add(win.Bounds().Center().Sub(win.MousePosition().Scaled(1 / scale))) | |
} | |
if win.JustPressed(pixelgl.MouseButton1) { | |
dragOrigin = win.MousePosition().Scaled(1 / scale) | |
} else if win.Pressed(pixelgl.MouseButton1) { | |
newOrigin := win.MousePosition().Scaled(1 / scale) | |
cameraOrigin = cameraOrigin.Sub(newOrigin.Sub(dragOrigin)) | |
dragOrigin = newOrigin | |
} | |
viewMatrix = pixel.IM.Moved(win.Bounds().Center().Sub(cameraOrigin)).Scaled(pixel.ZV, scale) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment