47 m(w),
a(x),
b(y),
c(z) {}
54 template<
typename T,
size_t BitsPerElement = 12>
58 static constexpr
float SMALLEST_THREE_UNPACK = 0.70710678118654752440084436210485f + 0.0000001f;
59 static constexpr
float SMALLEST_THREE_PACK = 1.0f / SMALLEST_THREE_UNPACK;
64 constexpr
float half_range =
static_cast<float>(1 << (BitsPerElement - 1));
65 constexpr
float packer = SMALLEST_THREE_PACK * half_range;
67 float max_value = -1.0f;
68 bool sign_minus =
false;
74 for (uint32_t i = 0; i < 4; i++)
76 float element = quaternion[i];
78 float abs = element > 0.0f ? element : -element;
82 sign_minus = element < 0.0f;
118 a =
static_cast<uint32_t
>((-af * packer) + half_range);
119 b =
static_cast<uint32_t
>((-bf * packer) + half_range);
120 c =
static_cast<uint32_t
>((-cf * packer) + half_range);
124 a =
static_cast<uint32_t
>((af * packer) + half_range);
125 b =
static_cast<uint32_t
>((bf * packer) + half_range);
126 c =
static_cast<uint32_t
>((cf * packer) + half_range);
129 return { m, a, b, c };
134 constexpr uint32_t half_range = (1 << (BitsPerElement - 1));
135 constexpr
float unpacker = SMALLEST_THREE_UNPACK * (1.0f / half_range);
137 float a =
static_cast<float>(data.a * unpacker - half_range * unpacker);
138 float b =
static_cast<float>(data.b * unpacker - half_range * unpacker);
139 float c =
static_cast<float>(data.c * unpacker - half_range * unpacker);
141 float d = std::sqrt(1.0f - ((a * a) + (b * b) + (c * c)));
146 return T{ d, a, b, c };
148 return T{ a, d, b, c };
150 return T{ a, b, d, c };
152 return T{ a, b, c, d };
Class for quantizing a user-specified quaternion into fewer bits using the smallest-three algorithm.
Definition: smallest_three.h:56
static T dequantize(const quantized_quaternion &data) noexcept
Definition: smallest_three.h:132
static quantized_quaternion quantize(const T &quaternion) noexcept
Definition: smallest_three.h:62
Definition: bounded_range.h:28
A quantized representation of a quaternion.
Definition: smallest_three.h:34
uint32_t c
Definition: smallest_three.h:38
constexpr quantized_quaternion(uint32_t w, uint32_t x, uint32_t y, uint32_t z) noexcept
Definition: smallest_three.h:46
uint32_t m
Definition: smallest_three.h:35
constexpr quantized_quaternion() noexcept
Definition: smallest_three.h:40
uint32_t b
Definition: smallest_three.h:37
uint32_t a
Definition: smallest_three.h:36