Skip to content

Commit

Permalink
fix(sourcepp): compressed quats in source engine use positive w to in…
Browse files Browse the repository at this point in the history
…dicate a negative w in the final quat
  • Loading branch information
craftablescience authored Jun 6, 2024
1 parent ff317fd commit 24ba9c4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/sourcepp/math/Angles.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct QuatCompressed48 {
uint16_t x : 16;
uint16_t y : 16;
uint16_t z : 15;
uint16_t w : 1;
uint16_t wn : 1;

[[nodiscard]] Quat decompress() const {
// Convert from 16-bit (or 15-bit) integers to floating point values in the range [-1, 1]
Expand All @@ -27,20 +27,20 @@ struct QuatCompressed48 {
float fw = std::sqrt(1.f - fx * fx - fy * fy - fz * fz);

// Adjust w based on the stored sign bit
if (this->w == 0) {
if (this->wn) {
fw = -fw;
}

return {fx, fy, fz, fw};
}
};

/// Lower precision Quat compressed to 12 bytes
/// Lower precision Quat compressed to 8 bytes
struct QuatCompressed64 {
uint32_t x : 21;
uint32_t y : 21;
uint32_t z : 21;
uint32_t w : 1;
uint32_t wn : 1;

[[nodiscard]] Quat decompress() const {
// Convert from 21-bit integers to floating point values in the range [-1, 1]
Expand All @@ -52,7 +52,7 @@ struct QuatCompressed64 {
double fw = std::sqrt(1.0 - fx * fx - fy * fy - fz * fz);

// Adjust w based on the stored sign bit
if (this->w == 0) {
if (this->wn) {
fw = -fw;
}

Expand Down

0 comments on commit 24ba9c4

Please sign in to comment.