mirror of
https://github.com/UberGames/ioef.git
synced 2024-12-01 00:21:19 +00:00
Optimise VectorNormalize functions, patch by Matt Turner
This commit is contained in:
parent
b003422d92
commit
01ed417ee1
1 changed files with 8 additions and 4 deletions
|
@ -787,10 +787,12 @@ vec_t VectorNormalize( vec3_t v ) {
|
|||
float length, ilength;
|
||||
|
||||
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
|
||||
length = sqrt (length);
|
||||
|
||||
if ( length ) {
|
||||
ilength = 1/length;
|
||||
/* writing it this way allows gcc to recognize that rsqrt can be used */
|
||||
ilength = 1/(float)sqrt (length);
|
||||
/* sqrt(length) = length * (1 / sqrt(length)) */
|
||||
length *= ilength;
|
||||
v[0] *= ilength;
|
||||
v[1] *= ilength;
|
||||
v[2] *= ilength;
|
||||
|
@ -803,11 +805,13 @@ vec_t VectorNormalize2( const vec3_t v, vec3_t out) {
|
|||
float length, ilength;
|
||||
|
||||
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
|
||||
length = sqrt (length);
|
||||
|
||||
if (length)
|
||||
{
|
||||
ilength = 1/length;
|
||||
/* writing it this way allows gcc to recognize that rsqrt can be used */
|
||||
ilength = 1/(float)sqrt (length);
|
||||
/* sqrt(length) = length * (1 / sqrt(length)) */
|
||||
length *= ilength;
|
||||
out[0] = v[0]*ilength;
|
||||
out[1] = v[1]*ilength;
|
||||
out[2] = v[2]*ilength;
|
||||
|
|
Loading…
Reference in a new issue