forked from SolarLune/masterplan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
80 lines (54 loc) · 1.72 KB
/
common.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"math"
"os"
"path/filepath"
rl "github.com/gen2brain/raylib-go/raylib"
"github.com/gen2brain/raylib-go/raymath"
)
func GetMousePosition() rl.Vector2 {
pos := rl.GetMousePosition()
// pos.X *= float32(screenWidth) / float32(rl.GetScreenWidth())
// pos.Y *= float32(screenHeight) / float32(rl.GetScreenHeight())
pos.X = float32(math.Round(float64(pos.X)))
pos.Y = float32(math.Round(float64(pos.Y)))
return pos
}
func GetWorldMousePosition() rl.Vector2 {
pos := camera.Target
mousePos := GetMousePosition()
// mousePos.X -= screenWidth / 2
// mousePos.Y -= screenHeight / 2
mousePos.X -= float32(rl.GetScreenWidth() / 2)
mousePos.Y -= float32(rl.GetScreenHeight() / 2)
mousePos.X /= camera.Zoom
mousePos.Y /= camera.Zoom
pos.X += mousePos.X
pos.Y += mousePos.Y
return pos
}
var PrevMousePosition rl.Vector2 = rl.Vector2{}
func GetMouseDelta() rl.Vector2 {
vec := raymath.Vector2Subtract(GetMousePosition(), PrevMousePosition)
raymath.Vector2Scale(&vec, 1/camera.Zoom)
return vec
}
func GetPath(folders ...string) string {
// Running apps from Finder in MacOS makes the working directory the home directory, which is nice, because
// now I have to make this function to do what should be done anyway and give me a relative path starting from
// the executable so that I can load assets from the assets directory. :,)
exePath, _ := os.Executable()
exeDir := filepath.Dir(exePath)
if releaseMode == "false" {
// Not in release mode, so current working directory is the root.
exeDir, _ = os.Getwd()
}
return filepath.Join(exeDir, filepath.Join(folders...))
}
func FileExists(filepath string) bool {
_, err := os.Stat(filepath)
if os.IsNotExist(err) {
return false
}
return true
}