From 004b65f6e3ffe0a6b92381d15582c8fba7299ecc Mon Sep 17 00:00:00 2001 From: Kyle De'Vir Date: Sun, 29 May 2016 03:55:47 +1000 Subject: [PATCH 1/3] Added HMM_FastInverseSquareRoot function With it's original comments. :) I won't mess too much with the coding style, because I don't fully understand it. It works, though. --- HandmadeMath.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/HandmadeMath.h b/HandmadeMath.h index 8db5f05..ba435b7 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -343,6 +343,24 @@ HMM_SquareRoot(float Float) return(Result); } +HINLINE float +HMM_FastInverseSquareRoot(float Number) +{ + long i; + float x2, y; + const float threehalfs = 1.5f; + + x2 = Number * 0.5f; + y = Number; + i = * ( long * ) &y; // evil floating point bit level hacking + i = 0x5f3759df - ( i >> 1 ); // what the fuck? + y = * ( float * ) &i; + + y = y * ( threehalfs - ( x2 * y * y ) ); + + return ( y ); +} + HINLINE float HMM_LengthSquareRoot(hmm_vec3 A) { From 6a1e42ed74998e83883c1e8badb1af90d8bbc72c Mon Sep 17 00:00:00 2001 From: Kyle De'Vir Date: Sun, 29 May 2016 03:58:21 +1000 Subject: [PATCH 2/3] Added missing HMM_FastInverseSquareRoot prototype --- HandmadeMath.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index ba435b7..3541e92 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -223,6 +223,7 @@ HMMDEF float HMM_ToRadians(float Degrees); HMMDEF float HMM_Inner(hmm_vec3 A, hmm_vec3 B); HMMDEF float HMM_SquareRoot(float Float); HMMDEF float HMM_LengthSquareRoot(hmm_vec3 A); +HMMDEF float HMM_FastInverseSquareRoot(float Number); HMMDEF float HMM_Length(hmm_vec3 A); HMMDEF float HMM_Power(float Base, int Exponent); HMMDEF float HMM_Clamp(float Min, float Value, float Max); @@ -343,6 +344,14 @@ HMM_SquareRoot(float Float) return(Result); } +HINLINE float +HMM_LengthSquareRoot(hmm_vec3 A) +{ + float Result = HMM_Inner(A, A); + + return (Result); +} + HINLINE float HMM_FastInverseSquareRoot(float Number) { @@ -361,14 +370,6 @@ HMM_FastInverseSquareRoot(float Number) return ( y ); } -HINLINE float -HMM_LengthSquareRoot(hmm_vec3 A) -{ - float Result = HMM_Inner(A, A); - - return (Result); -} - HINLINE float HMM_Length(hmm_vec3 A) { From 116e3bb41b186c9d7b57751a028fe66fde4ee69a Mon Sep 17 00:00:00 2001 From: Kyle De'Vir Date: Sun, 29 May 2016 04:04:16 +1000 Subject: [PATCH 3/3] HMM_FastInverseSquareRoot indentation adjustment --- HandmadeMath.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index 3541e92..eb72c85 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -355,19 +355,19 @@ HMM_LengthSquareRoot(hmm_vec3 A) HINLINE float HMM_FastInverseSquareRoot(float Number) { - long i; - float x2, y; - const float threehalfs = 1.5f; + long i; + float x2, y; + const float threehalfs = 1.5f; - x2 = Number * 0.5f; - y = Number; - i = * ( long * ) &y; // evil floating point bit level hacking - i = 0x5f3759df - ( i >> 1 ); // what the fuck? - y = * ( float * ) &i; + x2 = Number * 0.5f; + y = Number; + i = * ( long * ) &y; // evil floating point bit level hacking + i = 0x5f3759df - ( i >> 1 ); // what the fuck? + y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); - return ( y ); + return ( y ); } HINLINE float