From 46f44b5d59df57a6ba6c7ad051c3b507a0cb4093 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 13 Oct 2022 12:12:07 +0800 Subject: [PATCH] Add getBulletQuaternion for MiniGLM --- lib/graphics_engine/include/mini_glm.hpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/graphics_engine/include/mini_glm.hpp b/lib/graphics_engine/include/mini_glm.hpp index dd5eea173..c035f801f 100644 --- a/lib/graphics_engine/include/mini_glm.hpp +++ b/lib/graphics_engine/include/mini_glm.hpp @@ -509,13 +509,13 @@ namespace MiniGLM return ret.normalize(); } // decompressbtQuaternion // ------------------------------------------------------------------------ - inline core::quaternion getQuaternion(const core::matrix4& m) + inline std::array getQuaternionInternal(const core::matrix4& m) { btVector3 row[3]; memcpy(&row[0][0], &m[0], 12); memcpy(&row[1][0], &m[4], 12); memcpy(&row[2][0], &m[8], 12); - btVector3 q; + std::array q; float root = row[0].x() + row[1].y() + row[2].z(); const float trace = root; if (trace > 0.0f) @@ -551,9 +551,22 @@ namespace MiniGLM q[k] = root * (row[i][k] + row[k][i]); q[3] = root * (row[j][k] - row[k][j]); } + return q; + } + // ------------------------------------------------------------------------ + inline core::quaternion getQuaternion(const core::matrix4& m) + { + std::array q = getQuaternionInternal(m); return core::quaternion(q[0], q[1], q[2], q[3]).normalize(); } // ------------------------------------------------------------------------ + inline btQuaternion getBulletQuaternion(const core::matrix4& m) + { + std::array q = getQuaternionInternal(m); + return btQuaternion(q[0], q[1], q[2], q[3]).normalize(); + } + // ------------------------------------------------------------------------ + inline uint32_t quickTangent(uint32_t packed_normal) { core::vector3df normal = decompressVector3(packed_normal);