|
|
@ -2,28 +2,41 @@ package ent
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"github.com/jordanorelli/hyperstone/bit"
|
|
|
|
"github.com/jordanorelli/hyperstone/bit"
|
|
|
|
|
|
|
|
"math"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type qangle struct{ pitch, yaw, roll float32 }
|
|
|
|
|
|
|
|
|
|
|
|
func qAngleType(spec *typeSpec, env *Env) tÿpe {
|
|
|
|
func qAngleType(spec *typeSpec, env *Env) tÿpe {
|
|
|
|
if spec.typeName != "QAngle" {
|
|
|
|
if spec.typeName != "QAngle" {
|
|
|
|
return nil
|
|
|
|
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 {
|
|
|
|
switch spec.bits {
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
|
Debug.Printf(" qangle type")
|
|
|
|
Debug.Printf(" qangle type")
|
|
|
|
return typeFn(func(r bit.Reader) (value, error) {
|
|
|
|
return typeFn(func(r bit.Reader) (value, error) {
|
|
|
|
x, y, z := bit.ReadBool(r), bit.ReadBool(r), bit.ReadBool(r)
|
|
|
|
var q qangle
|
|
|
|
var v vector
|
|
|
|
pitch, yaw, roll := bit.ReadBool(r), bit.ReadBool(r), bit.ReadBool(r)
|
|
|
|
if x {
|
|
|
|
if pitch {
|
|
|
|
v.x = bit.ReadCoord(r)
|
|
|
|
q.pitch = bit.ReadCoord(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if y {
|
|
|
|
if yaw {
|
|
|
|
v.y = bit.ReadCoord(r)
|
|
|
|
q.yaw = bit.ReadCoord(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if z {
|
|
|
|
if roll {
|
|
|
|
v.z = bit.ReadCoord(r)
|
|
|
|
q.roll = bit.ReadCoord(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return v, nil
|
|
|
|
return q, nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
case 32:
|
|
|
|
case 32:
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -31,3 +44,19 @@ func qAngleType(spec *typeSpec, env *Env) tÿpe {
|
|
|
|
return nil
|
|
|
|
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()
|
|
|
|
|
|
|
|
}
|
|
|
|