mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:53:50 +00:00
Changes in head tracking and greetings for "smooth movement".
This commit is contained in:
parent
b838782557
commit
ad51a4be2e
3 changed files with 23 additions and 19 deletions
|
@ -426,7 +426,7 @@ namespace MWMechanics
|
|||
const osg::Vec3f actor2Pos(targetActor.getRefData().getPosition().asVec3());
|
||||
float sqrDist = (actor1Pos - actor2Pos).length2();
|
||||
|
||||
if (sqrDist > maxDistance*maxDistance)
|
||||
if (sqrDist > std::min(maxDistance * maxDistance, sqrHeadTrackDistance))
|
||||
return;
|
||||
|
||||
// stop tracking when target is behind the actor
|
||||
|
@ -434,10 +434,7 @@ namespace MWMechanics
|
|||
osg::Vec3f targetDirection(actor2Pos - actor1Pos);
|
||||
actorDirection.z() = 0;
|
||||
targetDirection.z() = 0;
|
||||
actorDirection.normalize();
|
||||
targetDirection.normalize();
|
||||
if (std::acos(actorDirection * targetDirection) < osg::DegreesToRadians(90.f)
|
||||
&& sqrDist <= sqrHeadTrackDistance
|
||||
if (actorDirection * targetDirection > 0
|
||||
&& MWBase::Environment::get().getWorld()->getLOS(actor, targetActor) // check LOS and awareness last as it's the most expensive function
|
||||
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(targetActor, actor))
|
||||
{
|
||||
|
@ -475,8 +472,7 @@ namespace MWMechanics
|
|||
|
||||
void Actors::updateMovementSpeed(const MWWorld::Ptr& actor)
|
||||
{
|
||||
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
|
||||
if (smoothMovement)
|
||||
if (mSmoothMovement)
|
||||
return;
|
||||
|
||||
CreatureStats &stats = actor.getClass().getCreatureStats(actor);
|
||||
|
@ -594,7 +590,10 @@ namespace MWMechanics
|
|||
|
||||
if (!actorState.isTurningToPlayer())
|
||||
{
|
||||
actorState.setAngleToPlayer(std::atan2(dir.x(), dir.y()));
|
||||
float angle = std::atan2(dir.x(), dir.y());
|
||||
actorState.setAngleToPlayer(angle);
|
||||
float deltaAngle = Misc::normalizeAngle(angle - actor.getRefData().getPosition().rot[2]);
|
||||
if (!mSmoothMovement || std::abs(deltaAngle) > osg::DegreesToRadians(60.f))
|
||||
actorState.setTurningToPlayer(true);
|
||||
}
|
||||
}
|
||||
|
@ -1467,7 +1466,7 @@ namespace MWMechanics
|
|||
}
|
||||
}
|
||||
|
||||
Actors::Actors()
|
||||
Actors::Actors() : mSmoothMovement(Settings::Manager::getBool("smooth movement", "Game"))
|
||||
{
|
||||
mTimerDisposeSummonsCorpses = 0.2f; // We should add a delay between summoned creature death and its corpse despawning
|
||||
|
||||
|
|
|
@ -211,6 +211,7 @@ namespace MWMechanics
|
|||
float mTimerDisposeSummonsCorpses;
|
||||
float mActorsProcessingRange;
|
||||
|
||||
bool mSmoothMovement;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -2038,6 +2038,8 @@ void CharacterController::update(float duration, bool animationOnly)
|
|||
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 2);
|
||||
else
|
||||
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 4);
|
||||
if (smoothMovement && !isPlayer && !inwater)
|
||||
mAnimation->setUpperBodyYawRadians(mAnimation->getUpperBodyYawRadians() + mAnimation->getHeadYaw() / 2);
|
||||
|
||||
speed = cls.getCurrentSpeed(mPtr);
|
||||
vec.x() *= speed;
|
||||
|
@ -2934,19 +2936,21 @@ void CharacterController::updateHeadTracking(float duration)
|
|||
return;
|
||||
const osg::Vec3f actorDirection = mPtr.getRefData().getBaseNode()->getAttitude() * osg::Vec3f(0,1,0);
|
||||
|
||||
zAngleRadians = std::atan2(direction.x(), direction.y()) - std::atan2(actorDirection.x(), actorDirection.y());
|
||||
xAngleRadians = -std::asin(direction.z());
|
||||
zAngleRadians = std::atan2(actorDirection.x(), actorDirection.y()) - std::atan2(direction.x(), direction.y());
|
||||
xAngleRadians = std::asin(direction.z());
|
||||
}
|
||||
|
||||
const double xLimit = osg::DegreesToRadians(40.0);
|
||||
const double zLimit = osg::DegreesToRadians(30.0);
|
||||
zAngleRadians = osg::clampBetween(Misc::normalizeAngle(zAngleRadians), -xLimit, xLimit);
|
||||
xAngleRadians = osg::clampBetween(Misc::normalizeAngle(xAngleRadians), -zLimit, zLimit);
|
||||
}
|
||||
double zLimitOffset = mAnimation->getUpperBodyYawRadians();
|
||||
xAngleRadians = osg::clampBetween(Misc::normalizeAngle(xAngleRadians), -xLimit, xLimit);
|
||||
zAngleRadians = osg::clampBetween(Misc::normalizeAngle(zAngleRadians),
|
||||
-zLimit + zLimitOffset, zLimit + zLimitOffset);
|
||||
|
||||
float factor = duration*5;
|
||||
factor = std::min(factor, 1.f);
|
||||
xAngleRadians = (1.f-factor) * mAnimation->getHeadPitch() + factor * (-xAngleRadians);
|
||||
zAngleRadians = (1.f-factor) * mAnimation->getHeadYaw() + factor * (-zAngleRadians);
|
||||
xAngleRadians = (1.f-factor) * mAnimation->getHeadPitch() + factor * xAngleRadians;
|
||||
zAngleRadians = (1.f-factor) * mAnimation->getHeadYaw() + factor * zAngleRadians;
|
||||
|
||||
mAnimation->setHeadPitch(xAngleRadians);
|
||||
mAnimation->setHeadYaw(zAngleRadians);
|
||||
|
|
Loading…
Reference in a new issue