summaryrefslogtreecommitdiff
path: root/pos.go
diff options
context:
space:
mode:
Diffstat (limited to 'pos.go')
-rw-r--r--pos.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/pos.go b/pos.go
new file mode 100644
index 0000000..7242a6e
--- /dev/null
+++ b/pos.go
@@ -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
+}