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

q_math: do tracing in id Software/J.M.P. van Waveren's QuatFromMatrix() implementation like Martin John Baker's one did, fix model distortion with GCC 14 #1532

Merged
merged 4 commits into from
Jan 29, 2025
Merged
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
22 changes: 13 additions & 9 deletions src/engine/qcommon/q_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ void MatrixFromQuat( matrix_t m, const quat_t q )
* February 27th 2005
* J.M.P. van Waveren
*
* http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm
* https://web.archive.org/web/20100818052330/http://cache-www.intel.com/cd/00/00/29/37/293748_293748.pdf
*/
float x2, y2, z2 /*, w2*/;
float yy2, xy2;
Expand Down Expand Up @@ -2864,14 +2864,18 @@ void QuatFromMatrix( quat_t q, const matrix_t m )
* February 27th 2005
* J.M.P. van Waveren
*
* http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm
* https://web.archive.org/web/20100818052330/http://cache-www.intel.com/cd/00/00/29/37/293748_293748.pdf
*/
float t, s;

if ( m[ 0 ] + m[ 5 ] + m[ 10 ] > 0.0f )
/* For the +1 that deviates from the original implementation,
see https://github.com/DaemonEngine/Daemon/issues/1527 */

float t = m[ 0 ] + m[ 5 ] + m[ 10 ] + 1.0f;
float s;

if ( t > 0.0f )
{
t = m[ 0 ] + m[ 5 ] + m[ 10 ] + 1.0f;
s = ( 1.0f / sqrtf( t ) ) * 0.5f;
s = Q_rsqrt( t ) * 0.5f;

q[ 3 ] = s * t;
q[ 2 ] = ( m[ 1 ] - m[ 4 ] ) * s;
Expand All @@ -2882,7 +2886,7 @@ void QuatFromMatrix( quat_t q, const matrix_t m )
else if ( m[ 0 ] > m[ 5 ] && m[ 0 ] > m[ 10 ] )
{
t = m[ 0 ] - m[ 5 ] - m[ 10 ] + 1.0f;
s = ( 1.0f / sqrtf( t ) ) * 0.5f;
s = Q_rsqrt( t ) * 0.5f;

q[ 0 ] = s * t;
q[ 1 ] = ( m[ 1 ] + m[ 4 ] ) * s;
Expand All @@ -2893,7 +2897,7 @@ void QuatFromMatrix( quat_t q, const matrix_t m )
else if ( m[ 5 ] > m[ 10 ] )
{
t = -m[ 0 ] + m[ 5 ] - m[ 10 ] + 1.0f;
s = ( 1.0f / sqrtf( t ) ) * 0.5f;
s = Q_rsqrt( t ) * 0.5f;

q[ 1 ] = s * t;
q[ 0 ] = ( m[ 1 ] + m[ 4 ] ) * s;
Expand All @@ -2904,7 +2908,7 @@ void QuatFromMatrix( quat_t q, const matrix_t m )
else
{
t = -m[ 0 ] - m[ 5 ] + m[ 10 ] + 1.0f;
s = ( 1.0f / sqrtf( t ) ) * 0.5f;
s = Q_rsqrt( t ) * 0.5f;

q[ 2 ] = s * t;
q[ 3 ] = ( m[ 1 ] - m[ 4 ] ) * s;
Expand Down
Loading