-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey-callback.go
More file actions
146 lines (121 loc) · 4.12 KB
/
key-callback.go
File metadata and controls
146 lines (121 loc) · 4.12 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"fmt"
// "github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/go-gl/mathgl/mgl32"
"strconv"
// "math"
// "github.com/mki1967/go-mki3d/mki3d"
// "github.com/mki1967/go-mki3d/glmki3d"
)
var oldIsZenity bool
func (g *Mki3dGame) KeyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
if action == glfw.Release {
if action == glfw.Release {
g.CancelAction()
return
}
}
if action == glfw.Press {
// g.Paused = false // old version
g.Paused = false // new version
g.LastActivityTime = glfw.GetTime()
// g := GamePtr // short name
switch {
/* rotate player */
case key == glfw.KeyRight && mods == 0:
g.SetAction(g.ActionRotRight)
case key == glfw.KeyLeft && mods == 0:
g.SetAction(g.ActionRotLeft)
case key == glfw.KeyUp && mods == 0:
g.SetAction(g.ActionRotUp)
case key == glfw.KeyDown && mods == 0:
g.SetAction(g.ActionRotDown)
case key == glfw.KeySpace:
g.SetAction(g.ActionLevel)
/* move player */
case key == glfw.KeyRight && mods == glfw.ModShift:
g.SetAction(g.ActionMoveRight)
case key == glfw.KeyLeft && mods == glfw.ModShift:
g.SetAction(g.ActionMoveLeft)
case key == glfw.KeyUp && mods == glfw.ModShift:
g.SetAction(g.ActionMoveUp)
case key == glfw.KeyDown && mods == glfw.ModShift:
g.SetAction(g.ActionMoveDown)
case key == glfw.KeyF && mods == glfw.ModShift:
fallthrough
case key == glfw.KeyF && mods == 0, key == glfw.KeyEnter:
g.SetAction(g.ActionMoveForward)
case key == glfw.KeyB && mods == glfw.ModShift:
fallthrough
case key == glfw.KeyB && mods == 0, key == glfw.KeyBackspace:
g.SetAction(g.ActionMoveBackward)
case key == glfw.KeyL && mods == 0: /* light */
g.StageDSPtr.UniPtr.LightUni = g.StageDSPtr.UniPtr.ViewUni.Mat3().Inv().Mul3x1(mgl32.Vec3{0, 0, 1}).Normalize()
case key == glfw.KeyX && mods == 0: /* light */
fmt.Println("RELOADING RANDOM STAGE ...")
ZenityInfo("NEXT RANDOM STAGE ...", "1")
g.NextStage()
case key == glfw.KeyZ && mods == 0: /* zoom out */
width, height := w.GetSize()
zy := g.StageDSPtr.Mki3dPtr.Projection.ZoomY / 1.1
fmt.Println("ZoomY: ", zy)
g.StageDSPtr.Mki3dPtr.Projection.ZoomY = zy
g.StageDSPtr.UniPtr.SetProjectionFromMki3d(g.StageDSPtr.Mki3dPtr, width, height)
case key == glfw.KeyZ && mods == glfw.ModShift: /* zoom in */
width, height := w.GetSize()
zy := g.StageDSPtr.Mki3dPtr.Projection.ZoomY * 1.1
fmt.Println("ZoomY: ", zy)
g.StageDSPtr.Mki3dPtr.Projection.ZoomY = zy
g.StageDSPtr.UniPtr.SetProjectionFromMki3d(g.StageDSPtr.Mki3dPtr, width, height)
/* help */
case key == glfw.KeyH && mods == 0:
message(helpText)
ZenityHelp()
case key == glfw.KeyP && mods == 0: /* PAUSE */
// g.PauseRequest.Set()
g.Paused = true
fmt.Println("PAUSED")
ZenityInfo("PAUSED", "1")
case key == glfw.KeyQ && mods == glfw.ModShift: /* QUIT */
g.Quit = true
case key == glfw.KeyQ && mods == 0: /* QUERY REMAINING TOKENS */
ts := strconv.FormatFloat(g.TotalScore, 'f', 2, 64)
ZenityInfo(
"TOTAL SCORE: "+ts+
"\nREMAINING TOKENS ON THIS STAGE: "+strconv.Itoa(g.TokensRemaining),
"4")
case key == glfw.KeyS && mods == 0: /* Togle skybox */
g.withSkybox = !g.withSkybox
ZenityInfo(
"WITH SKYBOX: "+strconv.FormatBool(g.withSkybox),
"1")
case key == glfw.KeyN && mods == 0: /* Togle skybox */
ZenityInfo(
"NEW SKYBOX !",
"1")
g.Skybox.RenderRandomCube()
g.withSkybox = true
case key == glfw.KeyF11: /* toggle full-screen */
if !g.FullScreen {
/// set full-screen
g.PosX, g.PosY = w.GetPos()
g.SizeWidth, g.SizeHeight = w.GetSize()
monitor := glfw.GetPrimaryMonitor()
mode := monitor.GetVideoMode()
w.SetMonitor(monitor, 0, 0, mode.Width, mode.Height, mode.RefreshRate)
g.FullScreen = true
oldIsZenity = IsZenity
IsZenity = false
} else {
// unset full-screen
monitor := glfw.GetPrimaryMonitor()
mode := monitor.GetVideoMode()
w.SetMonitor(nil, g.PosX, g.PosY, g.SizeWidth, g.SizeHeight, mode.RefreshRate)
g.FullScreen = false
IsZenity = oldIsZenity
}
}
}
}