diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-02-25 22:10:59 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-02-25 22:10:59 +0000 |
commit | 8bbaf323aef0c4f124b1a35680c323f833d2d58f (patch) | |
tree | 3f88cda9e58620e37c6d4c71cc420a9484a60d38 /src/utils | |
parent | 31d7d5eb18f849e09b950b167cad35f683d29eac (diff) | |
download | manaserv-8bbaf323aef0c4f124b1a35680c323f833d2d58f.tar.gz manaserv-8bbaf323aef0c4f124b1a35680c323f833d2d58f.tar.bz2 manaserv-8bbaf323aef0c4f124b1a35680c323f833d2d58f.tar.xz manaserv-8bbaf323aef0c4f124b1a35680c323f833d2d58f.zip |
Some speed optimizations at the collision detection suggested by Avaniel.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/fastsqrt.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/fastsqrt.h b/src/utils/fastsqrt.h new file mode 100644 index 00000000..8ba6f8ce --- /dev/null +++ b/src/utils/fastsqrt.h @@ -0,0 +1,23 @@ +/* A very fast function to calculate the approximate inverse square root of a
+ * floating point value and a helper function that uses it for getting the
+ * normal squareroot. For an explanation of the inverse squareroot function
+ * read:
+ * http://www.math.purdue.edu/~clomont/Math/Papers/2003/InvSqrt.pdf
+ *
+ * Unfortunately the original creator of this function seems to be unknown.
+ */
+
+float fastInvSqrt(float x)
+{
+ float xhalf = 0.5f*x;
+ int i = *(int*)&x;
+ i = 0x5f375a86- (i>>1);
+ x = *(float*)&i;
+ x = x*(1.5f-xhalf*x*x);
+ return x;
+}
+
+float fastSqrt(float x)
+{
+ return 1.0f/fastInvSqrt(x);
+}
|