mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
An attempt at making turning animation smoother. Copied some code from AiCombat for rotation.
This commit is contained in:
parent
3d26702f5e
commit
000afa48b7
@ -34,6 +34,9 @@ namespace MWMechanics
|
|||||||
, mGreetDistanceMultiplier(0)
|
, mGreetDistanceMultiplier(0)
|
||||||
, mGreetDistanceReset(0)
|
, mGreetDistanceReset(0)
|
||||||
, mChance(0)
|
, mChance(0)
|
||||||
|
, mRotate(false)
|
||||||
|
, mTargetAngle(0)
|
||||||
|
, mOriginalAngle(0)
|
||||||
, mSaidGreeting(false)
|
, mSaidGreeting(false)
|
||||||
{
|
{
|
||||||
for(unsigned short counter = 0; counter < mIdle.size(); counter++)
|
for(unsigned short counter = 0; counter < mIdle.size(); counter++)
|
||||||
@ -204,6 +207,12 @@ namespace MWMechanics
|
|||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mRotate)
|
||||||
|
{
|
||||||
|
if (zTurn(actor, Ogre::Degree(mTargetAngle)))
|
||||||
|
mRotate = false;
|
||||||
|
}
|
||||||
|
|
||||||
mReaction += duration;
|
mReaction += duration;
|
||||||
if(mReaction > 0.25f) // FIXME: hard coded constant
|
if(mReaction > 0.25f) // FIXME: hard coded constant
|
||||||
{
|
{
|
||||||
@ -385,11 +394,28 @@ namespace MWMechanics
|
|||||||
mWalking = false;
|
mWalking = false;
|
||||||
mObstacleCheck.clear();
|
mObstacleCheck.clear();
|
||||||
}
|
}
|
||||||
Ogre::Vector3 dir = playerPos - actorPos;
|
|
||||||
float length = dir.length();
|
|
||||||
|
|
||||||
// FIXME: horrible hack, and does not turn smoothly
|
if(!mRotate)
|
||||||
zTurn(actor, Ogre::Degree(Ogre::Radian(Ogre::Math::ACos(dir.y / length) * ((Ogre::Math::ASin(dir.x / length).valueRadians()>0)?1.0:-1.0)).valueDegrees()));
|
{
|
||||||
|
Ogre::Vector3 dir = playerPos - actorPos;
|
||||||
|
float length = dir.length();
|
||||||
|
|
||||||
|
// FIXME: horrible hack
|
||||||
|
float faceAngle = Ogre::Radian(Ogre::Math::ACos(dir.y / length) *
|
||||||
|
((Ogre::Math::ASin(dir.x / length).valueRadians()>0)?1.0:-1.0)).valueDegrees();
|
||||||
|
// an attempt at reducing the turning animation glitch
|
||||||
|
// TODO: doesn't seem to work very well
|
||||||
|
if(abs(faceAngle) > 10)
|
||||||
|
{
|
||||||
|
mTargetAngle = faceAngle;
|
||||||
|
mRotate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!mDistance) // FIXME: stationary actors go back to their normal position
|
||||||
|
{
|
||||||
|
//mTargetAngle = mOriginalAngle;
|
||||||
|
//mRotate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mSaidGreeting)
|
if (!mSaidGreeting)
|
||||||
|
@ -73,6 +73,11 @@ namespace MWMechanics
|
|||||||
float mDoorCheckDuration;
|
float mDoorCheckDuration;
|
||||||
int mStuckCount;
|
int mStuckCount;
|
||||||
|
|
||||||
|
// the z rotation angle (degrees) we want to reach
|
||||||
|
// used every frame when mRotate is true
|
||||||
|
float mTargetAngle;
|
||||||
|
float mOriginalAngle;
|
||||||
|
bool mRotate;
|
||||||
float mReaction; // update some actions infrequently
|
float mReaction; // update some actions infrequently
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user