mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 02:45:32 +00:00
Bug #1417: Use fmod to wrap local rotations (more efficient and robust)
This commit is contained in:
parent
162549b7af
commit
ad3a78706e
1 changed files with 17 additions and 15 deletions
|
@ -54,6 +54,20 @@
|
||||||
|
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// Wraps a value to (-PI, PI]
|
||||||
|
void wrap(float& rad)
|
||||||
|
{
|
||||||
|
if (rad>0)
|
||||||
|
rad = std::fmod(rad+M_PI, 2.0*M_PI)-M_PI;
|
||||||
|
else
|
||||||
|
rad = std::fmod(rad-M_PI, 2.0*M_PI)+M_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
struct GameContentLoader : public ContentLoader
|
struct GameContentLoader : public ContentLoader
|
||||||
|
@ -1105,21 +1119,9 @@ namespace MWWorld
|
||||||
ptr.getRefData().getLocalRotation().rot[1]=Ogre::Degree(y).valueRadians();
|
ptr.getRefData().getLocalRotation().rot[1]=Ogre::Degree(y).valueRadians();
|
||||||
ptr.getRefData().getLocalRotation().rot[2]=Ogre::Degree(z).valueRadians();
|
ptr.getRefData().getLocalRotation().rot[2]=Ogre::Degree(z).valueRadians();
|
||||||
|
|
||||||
float fullRotateRad=Ogre::Degree(360).valueRadians();
|
wrap(ptr.getRefData().getLocalRotation().rot[0]);
|
||||||
|
wrap(ptr.getRefData().getLocalRotation().rot[1]);
|
||||||
while(ptr.getRefData().getLocalRotation().rot[0]>=fullRotateRad)
|
wrap(ptr.getRefData().getLocalRotation().rot[2]);
|
||||||
ptr.getRefData().getLocalRotation().rot[0]-=fullRotateRad;
|
|
||||||
while(ptr.getRefData().getLocalRotation().rot[1]>=fullRotateRad)
|
|
||||||
ptr.getRefData().getLocalRotation().rot[1]-=fullRotateRad;
|
|
||||||
while(ptr.getRefData().getLocalRotation().rot[2]>=fullRotateRad)
|
|
||||||
ptr.getRefData().getLocalRotation().rot[2]-=fullRotateRad;
|
|
||||||
|
|
||||||
while(ptr.getRefData().getLocalRotation().rot[0]<=-fullRotateRad)
|
|
||||||
ptr.getRefData().getLocalRotation().rot[0]+=fullRotateRad;
|
|
||||||
while(ptr.getRefData().getLocalRotation().rot[1]<=-fullRotateRad)
|
|
||||||
ptr.getRefData().getLocalRotation().rot[1]+=fullRotateRad;
|
|
||||||
while(ptr.getRefData().getLocalRotation().rot[2]<=-fullRotateRad)
|
|
||||||
ptr.getRefData().getLocalRotation().rot[2]+=fullRotateRad;
|
|
||||||
|
|
||||||
Ogre::Quaternion worldRotQuat(Ogre::Radian(ptr.getRefData().getPosition().rot[2]), Ogre::Vector3::NEGATIVE_UNIT_Z);
|
Ogre::Quaternion worldRotQuat(Ogre::Radian(ptr.getRefData().getPosition().rot[2]), Ogre::Vector3::NEGATIVE_UNIT_Z);
|
||||||
if (!ptr.getClass().isActor())
|
if (!ptr.getClass().isActor())
|
||||||
|
|
Loading…
Reference in a new issue