-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.Mouse.go
48 lines (39 loc) · 999 Bytes
/
Events.Mouse.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
package main
import (
"time"
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/go-gl/mathgl/mgl32"
)
var _oldMousePosX, _oldMousePosY float64
func EventMouseRay(ctx *glfw.Window, store *V3_ChunkStore, vox Vox, camera, projection mgl32.Mat4) {
currentTime := time.Now().UnixNano() / 1000000
if ctx.GetMouseButton(glfw.MouseButton1) == 1 && currentTime-buttonTimeout >= 250 {
store.SendDeleteRay(vox, camera, projection)
buttonTimeout = currentTime
}
}
func _mouseMovements(ctx *glfw.Window, vox *Vox) {
posX, posY := ctx.GetCursorPos()
if _oldMousePosX == 0 {
_oldMousePosX = posX
}
if _oldMousePosY == 0 {
_oldMousePosY = posY
}
vox.rot = vox.rot.Add(mgl32.Vec3{
-float32((_oldMousePosY - posY) * 0.001),
-float32((_oldMousePosX - posX) * 0.001),
0,
})
if vox.rot[0] > 1.0 {
vox.rot[0] = 1.0
}
if vox.rot[0] < -1.0 {
vox.rot[0] = -1.0
}
_oldMousePosX = posX
_oldMousePosY = posY
}
func EventsMouse(ctx *glfw.Window, vox *Vox) {
_mouseMovements(ctx, vox)
}