From df813020339b6587dd63d136f649e6da8e9029b8 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 25 Sep 2016 18:27:20 -0400 Subject: [PATCH] pitch/yaw --- ent/qangle.go | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/ent/qangle.go b/ent/qangle.go index 38ffc49..e9745a5 100644 --- a/ent/qangle.go +++ b/ent/qangle.go @@ -2,28 +2,41 @@ package ent import ( "github.com/jordanorelli/hyperstone/bit" + "math" ) +type qangle struct{ pitch, yaw, roll float32 } + func qAngleType(spec *typeSpec, env *Env) tÿpe { if spec.typeName != "QAngle" { return nil } + if spec.encoder == "qangle_pitch_yaw" { + switch { + case spec.bits <= 0 || spec.bits > 32: + return typeError("qangle pitch_yaw has invalid bit size: %d", spec.bits) + case spec.bits == 32: + return typeFn(pitchYaw_t) + default: + return pitchYawAngles_t(spec.bits) + } + } switch spec.bits { case 0: Debug.Printf(" qangle type") return typeFn(func(r bit.Reader) (value, error) { - x, y, z := bit.ReadBool(r), bit.ReadBool(r), bit.ReadBool(r) - var v vector - if x { - v.x = bit.ReadCoord(r) + var q qangle + pitch, yaw, roll := bit.ReadBool(r), bit.ReadBool(r), bit.ReadBool(r) + if pitch { + q.pitch = bit.ReadCoord(r) } - if y { - v.y = bit.ReadCoord(r) + if yaw { + q.yaw = bit.ReadCoord(r) } - if z { - v.z = bit.ReadCoord(r) + if roll { + q.roll = bit.ReadCoord(r) } - return v, nil + return q, nil }) case 32: return nil @@ -31,3 +44,19 @@ func qAngleType(spec *typeSpec, env *Env) tÿpe { return nil } } + +func pitchYaw_t(r bit.Reader) (value, error) { + var q qangle + q.pitch = math.Float32frombits(uint32(r.ReadBits(32))) + q.yaw = math.Float32frombits(uint32(r.ReadBits(32))) + return q, r.Err() +} + +type pitchYawAngles_t uint + +func (t pitchYawAngles_t) read(r bit.Reader) (value, error) { + var q qangle + q.pitch = bit.ReadAngle(r, uint(t)) + q.yaw = bit.ReadAngle(r, uint(t)) + return q, r.Err() +}