Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quat packing XYZW usage (GLM_FORCE_QUAT_DATA_WXYZ and GLM_FORCE_QUAT_DATA_XYZW) #1203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions glm/detail/type_quat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ namespace glm
// -- Explicit basic constructors --

GLM_FUNC_DECL GLM_CONSTEXPR qua(T s, vec<3, T, Q> const& v);

# ifdef GLM_FORCE_QUAT_DATA_XYZW
GLM_FUNC_DECL GLM_CONSTEXPR qua(T x, T y, T z, T w);
# else
GLM_FUNC_DECL GLM_CONSTEXPR qua(T w, T x, T y, T z);
# endif
GLM_FUNC_DECL GLM_CONSTEXPR qua(T a, T b, T c, T d);

GLM_FUNC_DECL static GLM_CONSTEXPR qua<T, Q> wxyz(T w, T x, T y, T z);

Expand Down
8 changes: 2 additions & 6 deletions glm/detail/type_quat.inl
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ namespace detail
{}

template <typename T, qualifier Q>
GLM_CONSTEXPR qua<T, Q> qua<T, Q>::wxyz(T w, T x, T y, T z) {
# ifdef GLM_FORCE_QUAT_DATA_XYZW
return qua<T, Q>(x, y, z, w);
# else
return qua<T, Q>(w, x, y, z);
# endif
GLM_CONSTEXPR qua<T, Q> qua<T, Q>::wxyz(T a, T b, T c, T d) {
return qua<T, Q>(a, b, c, d);
}

// -- Conversion constructors --
Expand Down
26 changes: 13 additions & 13 deletions glm/detail/type_quat_simd.inl
Original file line number Diff line number Diff line change
Expand Up @@ -161,39 +161,39 @@ namespace detail
{
static vec<4, float, Q> call(qua<float, Q> const& q, vec<4, float, Q> const& v)
{
# ifdef GLM_FORCE_QUAT_DATA_XYZW
__m128 const q_wwww = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 3, 3, 3));
__m128 const q_swp0 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 0, 2, 1));
__m128 const q_swp1 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 1, 0, 2));
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
__m128 const q_wwww = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(0, 0, 0, 0));
__m128 const q_swp0 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(0, 1, 3, 2));
__m128 const q_swp1 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(0, 2, 1, 3));
__m128 const v_swp0 = _mm_shuffle_ps(v.data, v.data, _MM_SHUFFLE(3, 0, 2, 1));
__m128 const v_swp1 = _mm_shuffle_ps(v.data, v.data, _MM_SHUFFLE(3, 1, 0, 2));

__m128 uv = _mm_sub_ps(_mm_mul_ps(q_swp0, v_swp1), _mm_mul_ps(q_swp1, v_swp0));
__m128 uv = _mm_sub_ps(_mm_mul_ps(q_swp0, v_swp1), _mm_mul_ps(q_swp1, v_swp0));
__m128 uv_swp0 = _mm_shuffle_ps(uv, uv, _MM_SHUFFLE(3, 0, 2, 1));
__m128 uv_swp1 = _mm_shuffle_ps(uv, uv, _MM_SHUFFLE(3, 1, 0, 2));
__m128 uuv = _mm_sub_ps(_mm_mul_ps(q_swp0, uv_swp1), _mm_mul_ps(q_swp1, uv_swp0));
__m128 uuv = _mm_sub_ps(_mm_mul_ps(q_swp0, uv_swp1), _mm_mul_ps(q_swp1, uv_swp0));

__m128 const two = _mm_set1_ps(2.0f);
uv = _mm_mul_ps(uv, _mm_mul_ps(q_wwww, two));
uv = _mm_mul_ps(uv, _mm_mul_ps(q_wwww, two));
uuv = _mm_mul_ps(uuv, two);

vec<4, float, Q> Result;
Result.data = _mm_add_ps(v.data, _mm_add_ps(uv, uuv));
return Result;
# else
__m128 const q_wwww = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(0, 0, 0, 0));
__m128 const q_swp0 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(0, 1, 3, 2));
__m128 const q_swp1 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(0, 2, 1, 3));
__m128 const q_wwww = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 3, 3, 3));
__m128 const q_swp0 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 0, 2, 1));
__m128 const q_swp1 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 1, 0, 2));
__m128 const v_swp0 = _mm_shuffle_ps(v.data, v.data, _MM_SHUFFLE(3, 0, 2, 1));
__m128 const v_swp1 = _mm_shuffle_ps(v.data, v.data, _MM_SHUFFLE(3, 1, 0, 2));

__m128 uv = _mm_sub_ps(_mm_mul_ps(q_swp0, v_swp1), _mm_mul_ps(q_swp1, v_swp0));
__m128 uv = _mm_sub_ps(_mm_mul_ps(q_swp0, v_swp1), _mm_mul_ps(q_swp1, v_swp0));
__m128 uv_swp0 = _mm_shuffle_ps(uv, uv, _MM_SHUFFLE(3, 0, 2, 1));
__m128 uv_swp1 = _mm_shuffle_ps(uv, uv, _MM_SHUFFLE(3, 1, 0, 2));
__m128 uuv = _mm_sub_ps(_mm_mul_ps(q_swp0, uv_swp1), _mm_mul_ps(q_swp1, uv_swp0));
__m128 uuv = _mm_sub_ps(_mm_mul_ps(q_swp0, uv_swp1), _mm_mul_ps(q_swp1, uv_swp0));

__m128 const two = _mm_set1_ps(2.0f);
uv = _mm_mul_ps(uv, _mm_mul_ps(q_wwww, two));
uv = _mm_mul_ps(uv, _mm_mul_ps(q_wwww, two));
uuv = _mm_mul_ps(uuv, two);

vec<4, float, Q> Result;
Expand Down
6 changes: 3 additions & 3 deletions glm/gtx/matrix_decompose.inl
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ namespace detail
j = Next[i];
k = Next[j];

# ifdef GLM_FORCE_QUAT_DATA_XYZW
int off = 0;
# else
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
int off = 1;
# else
int off = 0;
# endif

root = sqrt(Row[i][i] - Row[j][j] - Row[k][k] + static_cast<T>(1.0));
Expand Down