mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Use Ogre's asin/acos functions which will protect against NaNs
This commit is contained in:
parent
48a08c4c4d
commit
90b55c8d4b
@ -12,13 +12,13 @@
|
|||||||
#include "creaturestats.hpp"
|
#include "creaturestats.hpp"
|
||||||
#include "npcstats.hpp"
|
#include "npcstats.hpp"
|
||||||
|
|
||||||
#include "OgreMath.h"
|
#include <OgreMath.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static float sgn(float a)
|
static float sgn(Ogre::Radian a)
|
||||||
{
|
{
|
||||||
if(a > 0)
|
if(a.valueDegrees() > 0)
|
||||||
return 1.0;
|
return 1.0;
|
||||||
return -1.0;
|
return -1.0;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ namespace MWMechanics
|
|||||||
float directionY = dest.mY - start.mY;
|
float directionY = dest.mY - start.mY;
|
||||||
float directionResult = sqrt(directionX * directionX + directionY * directionY);
|
float directionResult = sqrt(directionX * directionX + directionY * directionY);
|
||||||
|
|
||||||
zAngle = Ogre::Radian( acos(directionY / directionResult) * sgn(asin(directionX / directionResult)) ).valueDegrees();
|
zAngle = Ogre::Radian( Ogre::Math::ACos(directionY / directionResult) * sgn(Ogre::Math::ASin(directionX / directionResult)) ).valueDegrees();
|
||||||
// TODO: use movement settings instead of rotating directly
|
// TODO: use movement settings instead of rotating directly
|
||||||
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
||||||
|
|
||||||
|
@ -53,9 +53,9 @@ namespace
|
|||||||
return sqrt(x * x + y * y + z * z);
|
return sqrt(x * x + y * y + z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float sgn(float a)
|
static float sgn(Ogre::Radian a)
|
||||||
{
|
{
|
||||||
if(a > 0)
|
if(a.valueRadians() > 0)
|
||||||
return 1.0;
|
return 1.0;
|
||||||
return -1.0;
|
return -1.0;
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ namespace MWMechanics
|
|||||||
float directionY = nextPoint.mY - y;
|
float directionY = nextPoint.mY - y;
|
||||||
float directionResult = sqrt(directionX * directionX + directionY * directionY);
|
float directionResult = sqrt(directionX * directionX + directionY * directionY);
|
||||||
|
|
||||||
return Ogre::Radian(acos(directionY / directionResult) * sgn(asin(directionX / directionResult))).valueDegrees();
|
return Ogre::Radian(Ogre::Math::ACos(directionY / directionResult) * sgn(Ogre::Math::ASin(directionX / directionResult))).valueDegrees();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PathFinder::checkWaypoint(float x, float y, float z)
|
bool PathFinder::checkWaypoint(float x, float y, float z)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user