forked from Minetest-j45/mt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerpos.go
78 lines (64 loc) · 1.24 KB
/
playerpos.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
package mt
type Keys uint32
const (
ForwardKey Keys = 1 << iota
BackwardKey
LeftKey
RightKey
JumpKey
SpecialKey
SneakKey
DigKey
PlaceKey
ZoomKey
)
type PlayerPos struct {
Pos100, Vel100 [3]int32
Pitch100, Yaw100 int32
Keys Keys
FOV80 uint8
WantedRange uint8 // in MapBlks.
}
func (p PlayerPos) Pos() (pos Pos) {
for i := range pos {
pos[i] = float32(p.Pos100[i]) / 100
}
return
}
func (p *PlayerPos) SetPos(pos Pos) {
for i, x := range pos {
p.Pos100[i] = int32(x * 100)
}
}
func (p PlayerPos) Vel() (vel Vec) {
for i := range vel {
vel[i] = float32(p.Vel100[i]) / 100
}
return
}
func (p *PlayerPos) SetVel(vel Vec) {
for i, x := range vel {
p.Vel100[i] = int32(x * 100)
}
}
func (p PlayerPos) Pitch() float32 {
return float32(p.Pitch100) / 100
}
func (p *PlayerPos) SetPitch(pitch float32) {
p.Pitch100 = int32(pitch * 100)
}
func (p PlayerPos) Yaw() float32 {
return float32(p.Yaw100) / 100
}
func (p *PlayerPos) SetYaw(yaw float32) {
p.Yaw100 = int32(yaw * 100)
}
func (p PlayerPos) FOV() float32 {
return float32(p.FOV80) / 80
}
func (p *PlayerPos) SetFOV(fov float32) {
p.FOV80 = uint8(fov * 80)
}
func (p PlayerPos) StoodOn() [3]int16 {
return p.Pos().Sub(Vec{1: 5}).Int()
}