]> git.lizzy.rs Git - mt.git/blob - pos.go
Add WaitGroup to SerializePkt
[mt.git] / pos.go
1 package mt
2
3 import "math"
4
5 // A Pos is a world space position,
6 // represented as a Vec from the origin.
7 type Pos Vec
8
9 // Add returns p+v.
10 func (p Pos) Add(v Vec) Pos {
11         return Pos(Vec(p).Add(v))
12 }
13
14 // Sub returns p-v.
15 func (p Pos) Sub(v Vec) Pos {
16         return Pos(Vec(p).Sub(v))
17 }
18
19 // From returns the Vec which moves to p from q.
20 func (p Pos) From(q Pos) Vec {
21         return Vec(p).Sub(Vec(q))
22 }
23
24 // Int returns the position of the node which the Pos is inside.
25 func (p Pos) Int() (ip [3]int16) {
26         for i := range ip {
27                 ip[i] = int16(math.Round(float64(p[i]) / 10))
28         }
29         return
30 }
31
32 // IntPos returns the Pos of the node at ip.
33 func IntPos(ip [3]int16) (p Pos) {
34         for i := range p {
35                 p[i] = 10 * float32(ip[i])
36         }
37         return
38 }