diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-03-03 12:01:06 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-03-03 12:01:06 +0000 |
commit | c2f5092d183184370b62c8003759a5093df39aba (patch) | |
tree | 20cb457158503b1ccd48001b6df793b1660723c5 /src | |
parent | f9980c8854a94863b24be459d800ba57fd92037f (diff) | |
download | manaserv-c2f5092d183184370b62c8003759a5093df39aba.tar.gz manaserv-c2f5092d183184370b62c8003759a5093df39aba.tar.bz2 manaserv-c2f5092d183184370b62c8003759a5093df39aba.tar.xz manaserv-c2f5092d183184370b62c8003759a5093df39aba.zip |
Set native eol-style on recently added files.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/collisiondetection.cpp | 390 | ||||
-rw-r--r-- | src/game-server/collisiondetection.hpp | 104 | ||||
-rw-r--r-- | src/utils/mathutils.cpp | 198 | ||||
-rw-r--r-- | src/utils/mathutils.h | 108 |
4 files changed, 400 insertions, 400 deletions
diff --git a/src/game-server/collisiondetection.cpp b/src/game-server/collisiondetection.cpp index b6cf47ff..e40a556d 100644 --- a/src/game-server/collisiondetection.cpp +++ b/src/game-server/collisiondetection.cpp @@ -1,195 +1,195 @@ -/*
- * The Mana World Server
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or any later version.
- *
- * The Mana World is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with The Mana World; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: $
- */
-
-#include "collisiondetection.hpp"
-
-#include <cmath>
-
-#include "point.h"
-#include "utils/mathutils.h"
-
-bool
-Collision::circleWithCirclesector(const Point &circlePos, int circleRadius,
- const Point &secPos, int secRadius,
- float secAngle, float secSize)
-{
- float targetAngle;
-
- // Calculate distance
- int distX = circlePos.x - secPos.x;
- int distY = circlePos.y - secPos.y;
- float invDist = utils::math::fastInvSqrt(distX * distX + distY * distY);
- float dist = 1.0f / invDist;
-
- // If out of range we can't hit it
- if (dist > secRadius + circleRadius) {
- return false;
- }
- // If we are standing in it we hit it in any case
- if (dist < circleRadius) {
- return true;
- }
-
- // Calculate target angle
- if (distX > 0)
- {
- targetAngle = asin(-distY * invDist);
- } else {
- if (distY < 0)
- {
- targetAngle = M_PI - asin(-distY * invDist);
- } else {
- targetAngle = -M_PI - asin(-distY * invDist);
- }
-
- }
-
- // Calculate difference from segment angle
- float targetDiff = fabs(targetAngle - secAngle);
- if (targetDiff > M_PI)
- {
- targetDiff = fabs(targetDiff - M_PI * 2);
- }
-
-
- // Add hit circle
- secSize += asin(circleRadius * invDist) * 2;
-
- return (targetDiff < secSize * 0.5f);
-}
-
-/**
- * Collision of a Disk with a Circle-Sector
- *
- * For a detailled explanation of this function please see:
- * http://wiki.themanaworld.org/index.php/Collision_determination
- */
-bool
-Collision::diskWithCircleSector(const Point &diskCenter, int diskRadius,
- const Point §orCenter, int sectorRadius,
- int halfTopAngle, int placeAngle)
-{
- // Converting the radii to float
- float R = (float) sectorRadius;
- float Rp = (float) diskRadius;
-
- // Transform to the primary coordinate system
- float Px = diskCenter.x - sectorCenter.x;
- float Py = diskCenter.y - sectorCenter.y;
-
- // The values of the trigonomic functions (only have to be computed once)
- float sinAlpha = utils::math::cachedSin(halfTopAngle);
- float cosAlpha = utils::math::cachedCos(halfTopAngle);
- float sinBeta = utils::math::cachedSin(placeAngle);
- float cosBeta = utils::math::cachedCos(placeAngle);
-
- /**
- * This bounding circle implementation can be used up and until a
- * half-top-angle of +/- 85 degrees. The bounding circle becomes
- * infinitly large at 90 degrees. Above about 60 degrees a bounding
- * half-circle with radius R becomes more efficient.
- * (The additional check for a region 1 collision can then be scrapped.)
- */
-
- // Calculating the coordinates of the disk's center in coordinate system 4
- float Px1 = Px * cosBeta + Py * sinBeta;
- float Py1 = Py * cosBeta - Px * sinBeta;
-
- // Check for an intersection with the bounding circle
- // (>) : touching is accepted
- if ((cosAlpha * Px1 * Px1 + cosAlpha * Py1 * Py1 - Px1 * R)
- > (Rp * Rp * cosAlpha + Rp * R)) return false;
-
- // Check for a region 4 collision
- if ((Px*Px + Py*Py) <= (Rp*Rp)) return true;
-
- // Calculating the coordinates of the disk's center in coordinate system 1
- Px1 = Px * (cosAlpha * cosBeta + sinAlpha * sinBeta)
- + Py * (cosAlpha * sinBeta - sinAlpha * cosBeta);
- Py1 = Py * (cosAlpha * cosBeta + sinAlpha * sinBeta)
- - Px * (cosAlpha * sinBeta - sinAlpha * cosBeta);
-
- // Check if P is in region 5 (using coordinate system 1)
- if ((Px1 >= 0.0f) && (Px1 <= R) && (Py1 <= 0.0f))
- {
- // Return true on intersection, false otherwise
- // (>=) : touching is accepted
- return (Py1 >= -1.0f * Rp);
- }
-
- // Check if P is in region 3 (using coordinate system 1)
- if ((Px1 > R) && (Py1 <= 0.0f))
- {
- // Calculating the vector from point A to the disk center
- float distAx = Px - R * (cosAlpha * cosBeta + sinAlpha * sinBeta);
- float distAy = Py - R * (cosAlpha * sinBeta - sinAlpha * cosBeta);
-
- // Check for a region 3 collision
- return ((distAx * distAx + distAy * distAy) <= Rp * Rp);
- }
-
- // Discard, if P is in region 4 (was previously checked)
- if ((Px1 < 0.0f) && (Py1 <= 0.0f)) return false;
-
- float tan2Alpha = utils::math::cachedTan(2 * halfTopAngle);
-
- // Check if P is in region 1 (using coordinate system 1)
- if ((Px1 >= 0.0f) && (Py1 >= 0.0f) && (Py1 <= Px1 * tan2Alpha))
- {
- // Return true on intersection, false otherwise
- // (<=) : touching is accepted
- return ((Px * Px + Py * Py) <= (R * R + Rp * Rp + 2.0f * R * Rp));
- }
-
- // Calculating the coordinates of the disk's center in coordinate system 3
- Px1 = Px * (cosAlpha * cosBeta - sinAlpha * sinBeta)
- + Py * (sinAlpha * cosBeta + cosAlpha * sinBeta);
- Py1 = Py * (cosAlpha * cosBeta - sinAlpha * sinBeta)
- - Px * (sinAlpha * cosBeta + cosAlpha * sinBeta);
-
- // Discard, if P is in region 4 (was previously checked)
- if ((Px1 < 0.0f) && (Py1 >= 0.0f)) return false;
-
- // Check if P is in region 6 (using coordinate system 3)
- if ((Px1 >= 0.0f) && (Px1 <= R) && (Py1 >= 0.0f))
- {
- // Return true on intersection, false otherwise
- // (<=) : touching is accepted
- return (Py1 <= Rp);
- }
-
- // Check if P is in region 2 (using coordinate system 3)
- if ((Px1 > R) && (Py1 <= 0.0f))
- {
- // Calculating the vector from point B to the disk center
- float distBx = Px - R * (cosAlpha * cosBeta - sinAlpha * sinBeta);
- float distBy = Py - R * (cosAlpha * sinBeta + sinAlpha * cosBeta);
-
- // Check for a region 2 collision
- return ((distBx * distBx + distBy * distBy) <= (Rp * Rp));
- }
-
- // The intersection with the bounding circle is in region 4,
- // but the disk and circle sector don't intersect.
- return false;
-}
-
+/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. + * + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#include "collisiondetection.hpp" + +#include <cmath> + +#include "point.h" +#include "utils/mathutils.h" + +bool +Collision::circleWithCirclesector(const Point &circlePos, int circleRadius, + const Point &secPos, int secRadius, + float secAngle, float secSize) +{ + float targetAngle; + + // Calculate distance + int distX = circlePos.x - secPos.x; + int distY = circlePos.y - secPos.y; + float invDist = utils::math::fastInvSqrt(distX * distX + distY * distY); + float dist = 1.0f / invDist; + + // If out of range we can't hit it + if (dist > secRadius + circleRadius) { + return false; + } + // If we are standing in it we hit it in any case + if (dist < circleRadius) { + return true; + } + + // Calculate target angle + if (distX > 0) + { + targetAngle = asin(-distY * invDist); + } else { + if (distY < 0) + { + targetAngle = M_PI - asin(-distY * invDist); + } else { + targetAngle = -M_PI - asin(-distY * invDist); + } + + } + + // Calculate difference from segment angle + float targetDiff = fabs(targetAngle - secAngle); + if (targetDiff > M_PI) + { + targetDiff = fabs(targetDiff - M_PI * 2); + } + + + // Add hit circle + secSize += asin(circleRadius * invDist) * 2; + + return (targetDiff < secSize * 0.5f); +} + +/** + * Collision of a Disk with a Circle-Sector + * + * For a detailled explanation of this function please see: + * http://wiki.themanaworld.org/index.php/Collision_determination + */ +bool +Collision::diskWithCircleSector(const Point &diskCenter, int diskRadius, + const Point §orCenter, int sectorRadius, + int halfTopAngle, int placeAngle) +{ + // Converting the radii to float + float R = (float) sectorRadius; + float Rp = (float) diskRadius; + + // Transform to the primary coordinate system + float Px = diskCenter.x - sectorCenter.x; + float Py = diskCenter.y - sectorCenter.y; + + // The values of the trigonomic functions (only have to be computed once) + float sinAlpha = utils::math::cachedSin(halfTopAngle); + float cosAlpha = utils::math::cachedCos(halfTopAngle); + float sinBeta = utils::math::cachedSin(placeAngle); + float cosBeta = utils::math::cachedCos(placeAngle); + + /** + * This bounding circle implementation can be used up and until a + * half-top-angle of +/- 85 degrees. The bounding circle becomes + * infinitly large at 90 degrees. Above about 60 degrees a bounding + * half-circle with radius R becomes more efficient. + * (The additional check for a region 1 collision can then be scrapped.) + */ + + // Calculating the coordinates of the disk's center in coordinate system 4 + float Px1 = Px * cosBeta + Py * sinBeta; + float Py1 = Py * cosBeta - Px * sinBeta; + + // Check for an intersection with the bounding circle + // (>) : touching is accepted + if ((cosAlpha * Px1 * Px1 + cosAlpha * Py1 * Py1 - Px1 * R) + > (Rp * Rp * cosAlpha + Rp * R)) return false; + + // Check for a region 4 collision + if ((Px*Px + Py*Py) <= (Rp*Rp)) return true; + + // Calculating the coordinates of the disk's center in coordinate system 1 + Px1 = Px * (cosAlpha * cosBeta + sinAlpha * sinBeta) + + Py * (cosAlpha * sinBeta - sinAlpha * cosBeta); + Py1 = Py * (cosAlpha * cosBeta + sinAlpha * sinBeta) + - Px * (cosAlpha * sinBeta - sinAlpha * cosBeta); + + // Check if P is in region 5 (using coordinate system 1) + if ((Px1 >= 0.0f) && (Px1 <= R) && (Py1 <= 0.0f)) + { + // Return true on intersection, false otherwise + // (>=) : touching is accepted + return (Py1 >= -1.0f * Rp); + } + + // Check if P is in region 3 (using coordinate system 1) + if ((Px1 > R) && (Py1 <= 0.0f)) + { + // Calculating the vector from point A to the disk center + float distAx = Px - R * (cosAlpha * cosBeta + sinAlpha * sinBeta); + float distAy = Py - R * (cosAlpha * sinBeta - sinAlpha * cosBeta); + + // Check for a region 3 collision + return ((distAx * distAx + distAy * distAy) <= Rp * Rp); + } + + // Discard, if P is in region 4 (was previously checked) + if ((Px1 < 0.0f) && (Py1 <= 0.0f)) return false; + + float tan2Alpha = utils::math::cachedTan(2 * halfTopAngle); + + // Check if P is in region 1 (using coordinate system 1) + if ((Px1 >= 0.0f) && (Py1 >= 0.0f) && (Py1 <= Px1 * tan2Alpha)) + { + // Return true on intersection, false otherwise + // (<=) : touching is accepted + return ((Px * Px + Py * Py) <= (R * R + Rp * Rp + 2.0f * R * Rp)); + } + + // Calculating the coordinates of the disk's center in coordinate system 3 + Px1 = Px * (cosAlpha * cosBeta - sinAlpha * sinBeta) + + Py * (sinAlpha * cosBeta + cosAlpha * sinBeta); + Py1 = Py * (cosAlpha * cosBeta - sinAlpha * sinBeta) + - Px * (sinAlpha * cosBeta + cosAlpha * sinBeta); + + // Discard, if P is in region 4 (was previously checked) + if ((Px1 < 0.0f) && (Py1 >= 0.0f)) return false; + + // Check if P is in region 6 (using coordinate system 3) + if ((Px1 >= 0.0f) && (Px1 <= R) && (Py1 >= 0.0f)) + { + // Return true on intersection, false otherwise + // (<=) : touching is accepted + return (Py1 <= Rp); + } + + // Check if P is in region 2 (using coordinate system 3) + if ((Px1 > R) && (Py1 <= 0.0f)) + { + // Calculating the vector from point B to the disk center + float distBx = Px - R * (cosAlpha * cosBeta - sinAlpha * sinBeta); + float distBy = Py - R * (cosAlpha * sinBeta + sinAlpha * cosBeta); + + // Check for a region 2 collision + return ((distBx * distBx + distBy * distBy) <= (Rp * Rp)); + } + + // The intersection with the bounding circle is in region 4, + // but the disk and circle sector don't intersect. + return false; +} + diff --git a/src/game-server/collisiondetection.hpp b/src/game-server/collisiondetection.hpp index bfbab413..82169db0 100644 --- a/src/game-server/collisiondetection.hpp +++ b/src/game-server/collisiondetection.hpp @@ -1,52 +1,52 @@ -/*
- * The Mana World Server
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or any later version.
- *
- * The Mana World is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with The Mana World; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: $
- */
-
-#ifndef _TMW_COLLISIONDETECTION_H
-#define _TMW_COLLISIONDETECTION_H
-
-class Point;
-
-/**
- * This namespace collects all needed collision detection functions
- */
-namespace Collision
-{
-
- bool
- circleWithCirclesector(const Point &circlePos, int circleRadius,
- const Point &secPos, int secRadius,
- float secAngle, float secSize);
- /**
- * Checks if a disk and a circle-sector collide
- *
- * @param halfTopAngle
- * The half-top-angle of the circle sector in degrees (0,359).
- * @param placeAngle
- * The placement-angle of the circle sector in degrees (0,359).
- */
- bool
- diskWithCircleSector(const Point &diskCenter, int diskRadius,
- const Point §orCenter, int sectorRadius,
- int halfTopAngle, int placeAngle);
-}
-
-#endif
+/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. + * + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#ifndef _TMW_COLLISIONDETECTION_H +#define _TMW_COLLISIONDETECTION_H + +class Point; + +/** + * This namespace collects all needed collision detection functions + */ +namespace Collision +{ + + bool + circleWithCirclesector(const Point &circlePos, int circleRadius, + const Point &secPos, int secRadius, + float secAngle, float secSize); + /** + * Checks if a disk and a circle-sector collide + * + * @param halfTopAngle + * The half-top-angle of the circle sector in degrees (0,359). + * @param placeAngle + * The placement-angle of the circle sector in degrees (0,359). + */ + bool + diskWithCircleSector(const Point &diskCenter, int diskRadius, + const Point §orCenter, int sectorRadius, + int halfTopAngle, int placeAngle); +} + +#endif diff --git a/src/utils/mathutils.cpp b/src/utils/mathutils.cpp index 407bba7f..59e35a22 100644 --- a/src/utils/mathutils.cpp +++ b/src/utils/mathutils.cpp @@ -1,99 +1,99 @@ -/*
- * The Mana World Server
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or any later version.
- *
- * The Mana World is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with The Mana World; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: $
- */
-
-#include "mathutils.h"
-
-#include <cmath>
-#include <float.h>
-
-#define MATH_UTILS_MAX_ANGLE 360
-
-float sinList[MATH_UTILS_MAX_ANGLE];
-float cosList[MATH_UTILS_MAX_ANGLE];
-float tanList[MATH_UTILS_MAX_ANGLE];
-
-/*
- * A very fast function to calculate the approximate inverse square root of a
- * floating point value. 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.
- *
- * TODO: - Make this function run on 64-bit architectures
- * - Find out and fix why this function fails when compiled with the -O2
- * optimization flag on
- * gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9).
- */
-float utils::math::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 utils::math::fastSqrt(float x)
-{
- return 1.0f / utils::math::fastInvSqrt(x);
-}
-
-void utils::math::init()
-{
- // Constant for calculating an angle in radians out of an angle in degrees
- const float radianAngleRatio = M_PI_2 / 90.0f; // pi/2 / 90[deg]
-
- for (int i = 0; i < MATH_UTILS_MAX_ANGLE; i++)
- {
- sinList[i] = sin(radianAngleRatio * (float) i);
- cosList[i] = cos(radianAngleRatio * (float) i);
-
- if (i == 90)
- {
- tanList[i] = FLT_MAX; // approximately infinity
- continue;
- }
- if (i == 270)
- {
- tanList[i] = -FLT_MAX; // approximately infinity
- continue;
- }
- tanList[i] = tan(radianAngleRatio * (float) i);
- }
-}
-
-float utils::math::cachedSin(int angle)
-{
- return sinList[angle];
-}
-
-float utils::math::cachedCos(int angle)
-{
- return cosList[angle];
-}
-
-float utils::math::cachedTan(int angle)
-{
- return tanList[angle];
-}
+/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. + * + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#include "mathutils.h" + +#include <cmath> +#include <float.h> + +#define MATH_UTILS_MAX_ANGLE 360 + +float sinList[MATH_UTILS_MAX_ANGLE]; +float cosList[MATH_UTILS_MAX_ANGLE]; +float tanList[MATH_UTILS_MAX_ANGLE]; + +/* + * A very fast function to calculate the approximate inverse square root of a + * floating point value. 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. + * + * TODO: - Make this function run on 64-bit architectures + * - Find out and fix why this function fails when compiled with the -O2 + * optimization flag on + * gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9). + */ +float utils::math::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 utils::math::fastSqrt(float x) +{ + return 1.0f / utils::math::fastInvSqrt(x); +} + +void utils::math::init() +{ + // Constant for calculating an angle in radians out of an angle in degrees + const float radianAngleRatio = M_PI_2 / 90.0f; // pi/2 / 90[deg] + + for (int i = 0; i < MATH_UTILS_MAX_ANGLE; i++) + { + sinList[i] = sin(radianAngleRatio * (float) i); + cosList[i] = cos(radianAngleRatio * (float) i); + + if (i == 90) + { + tanList[i] = FLT_MAX; // approximately infinity + continue; + } + if (i == 270) + { + tanList[i] = -FLT_MAX; // approximately infinity + continue; + } + tanList[i] = tan(radianAngleRatio * (float) i); + } +} + +float utils::math::cachedSin(int angle) +{ + return sinList[angle]; +} + +float utils::math::cachedCos(int angle) +{ + return cosList[angle]; +} + +float utils::math::cachedTan(int angle) +{ + return tanList[angle]; +} diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h index 31f48805..222ccc15 100644 --- a/src/utils/mathutils.h +++ b/src/utils/mathutils.h @@ -1,54 +1,54 @@ -/*
- * The Mana World Server
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or any later version.
- *
- * The Mana World is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with The Mana World; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: $
- */
-
-#ifndef _TMWSERV_MATHUTILS_H_
-#define _TMWSERV_MATHUTILS_H_
-
-namespace utils
-{
- namespace math
- {
- /**
- * A very fast function to calculate the approximate inverse square
- * root of a floating point value.
- */
- float fastInvSqrt(float x);
-
- /**
- * A helper function that uses the fastInvSqrt for getting the
- * normal squareroot.
- */
- float fastSqrt(float x);
-
- float cachedSin(int angle);
-
- float cachedCos(int angle);
-
- float cachedTan(int angle);
-
- void init();
-
- } // namespace math
-
-} // namespace utils
-
-#endif
+/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. + * + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#ifndef _TMWSERV_MATHUTILS_H_ +#define _TMWSERV_MATHUTILS_H_ + +namespace utils +{ + namespace math + { + /** + * A very fast function to calculate the approximate inverse square + * root of a floating point value. + */ + float fastInvSqrt(float x); + + /** + * A helper function that uses the fastInvSqrt for getting the + * normal squareroot. + */ + float fastSqrt(float x); + + float cachedSin(int angle); + + float cachedCos(int angle); + + float cachedTan(int angle); + + void init(); + + } // namespace math + +} // namespace utils + +#endif |