I'm developing a physics engine based somewhat on Flade and the Tony Pa Vector tutorials (they Google well so I don't think I need to link them).
I've ported the engine to Java and found an inverse square root method that was originally written for Quake 3 and optimised by Chris Lomont. This allows you to calculate vector normals much faster.
Here's my Java version:
Code:
// Original C code by Chris Lomont <http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf>
static float invSqrt(float x){
float xhalf = 0.5f*x;
int i = Float.floatToIntBits(x); // get bits for floating value
i = 0x5f375a86- (i>>1); // gives initial guess y0
x = Float.intBitsToFloat(i); // convert bits back to float
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return x;
}
My trouble here is before I can test it for speed in Flash I need a method for getting the floating point value of x in and out of integer bit format. Can anyone help?