From 8fdc2a63b118f37fa0bad11be0104296556aa5b0 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 14:58:22 -0500 Subject: 3dmath.c: In normalize, calculate reciprocal only once, and use sqrtf This saves about 12ms per frame on yelena. --- 3dmath.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to '3dmath.c') diff --git a/3dmath.c b/3dmath.c index d5806b6..5b876f2 100644 --- a/3dmath.c +++ b/3dmath.c @@ -11,13 +11,11 @@ dot(const float x[3], const float y[3]) { void normalize(float x[3]) { - float len; - int i; - - len = sqrt(dot(x, x)); + float len = 1.0f / sqrtf(dot(x, x)); - for(i = 0; i < 3; ++i) - x[i] /= len; + x[0] *= len; + x[1] *= len; + x[2] *= len; } float -- cgit v1.2.3