-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
25 lines (20 loc) · 783 Bytes
/
utils.go
File metadata and controls
25 lines (20 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main
import (
"github.com/veandco/go-sdl2/sdl"
)
func ScreenSpaceToGRIDSpace(p Vec2D) (x int, y int) {
return int(GRID_WORLD_DIMENSION * (p.X / float64(WINDOW_WIDTH))),
int(GRID_WORLD_DIMENSION * (1.0 - p.Y/float64(WINDOW_HEIGHT)))
}
func GRIDSpaceToScreenSpace(p Vec2D) (x int, y int) {
return int(WINDOW_WIDTH * (p.X / float64(GRID_WORLD_DIMENSION))),
int(WINDOW_HEIGHT * (1.0 - p.Y/float64(GRID_WORLD_DIMENSION)))
}
func MouseButtonEventToVec2D(me *sdl.MouseButtonEvent) Vec2D {
x, y := ScreenSpaceToGRIDSpace(Vec2D{float64(me.X), float64(me.Y)})
return Vec2D{float64(x), float64(y)}
}
func MouseMotionEventToVec2D(me *sdl.MouseMotionEvent) Vec2D {
x, y := ScreenSpaceToGRIDSpace(Vec2D{float64(me.X), float64(me.Y)})
return Vec2D{float64(x), float64(y)}
}