diff options
author | anon5 <anon5clam@protonmail.com> | 2021-06-21 18:47:26 +0000 |
---|---|---|
committer | anon5 <anon5clam@protonmail.com> | 2021-06-21 18:47:26 +0000 |
commit | 425da65ed46061303604610bb539d6495b2b1f3f (patch) | |
tree | 10ae3e665132c369ce0207676321cef870679923 /pos.go | |
parent | 9f239d341ef46b656dda759020da87bdd0606344 (diff) | |
download | mt-425da65ed46061303604610bb539d6495b2b1f3f.tar.xz |
Add high-level protocol (de)serialization
Diffstat (limited to 'pos.go')
-rw-r--r-- | pos.go | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +package mt + +import "math" + +// A Pos is a world space position, +// represented as a Vec from the origin. +type Pos Vec + +// Add returns p+v. +func (p Pos) Add(v Vec) Pos { + return Pos(Vec(p).Add(v)) +} + +// Sub returns p-v. +func (p Pos) Sub(v Vec) Pos { + return Pos(Vec(p).Sub(v)) +} + +// From returns the Vec which moves to p from q. +func (p Pos) From(q Pos) Vec { + return Vec(p).Sub(Vec(q)) +} + +// Int returns the position of the node which the Pos is inside. +func (p Pos) Int() (ip [3]int16) { + for i := range ip { + ip[i] = int16(math.Round(float64(p[i]) / 10)) + } + return +} + +// IntPos returns the Pos of the node at ip. +func IntPos(ip [3]int16) (p Pos) { + for i := range p { + p[i] = 10 * float32(ip[i]) + } + return +} |