Fast square root function (C++)

It doesn't actually seem to be any faster :S. carrying out around 12000 square roots in my code per frame and theres no difference in framerate between that and the library function.

I'll use it anyway because its sexy :)
 
tried the newton-raphson method and the reciprocal method and decided to go with the newton raphson as it worked better.

when i tried using x*(invsqrt(x)) instead of dividing by 1, i got some very strange results.

oh and i haven't a clue about assembly :P
 
Well I've written the algorithm right now in a step by step manner (I will change this of course, it just makes it easier to read while coding) so it does infact use the inverse square root but the way i have it right now is it uses the square root then is divided etc.. So can get around the problem of dividing by 1 when it comes to compressing the code.

It just takes the viewing point, the point of a partilce and the particles normal vector, creates 2 vectors from these and works out the angle between them (on 2 axis):

so the acute angle in radians = invCos{(a.b)/(|a|x|b|)}

where |x| is sqrt(xi^2 + xj^2 + xk^2)

so therefore the cos(anlge) is given by (a.b)x(invsqrt(ai^2 + aj^2 + ak^2))x(invsqrt(bi^2 + bj^2 + bk^2))

lol i think i typed all that ok.. those of you who get the jist will know it all anyway.. obviously to get the anlges on 2 axis' some values can be negated and not included in the calculations (because it effectively becomes 2 2D calculations and the same normal can be used)

Now... fast collision detection algorithms anyone? hehe.
 
Back
Top Bottom