mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +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());
|
const osg::Vec3f actor2Pos(targetActor.getRefData().getPosition().asVec3());
|
||||||
float sqrDist = (actor1Pos - actor2Pos).length2();
|
float sqrDist = (actor1Pos - actor2Pos).length2();
|
||||||
|
|
||||||
if (sqrDist > maxDistance*maxDistance)
|
if (sqrDist > std::min(maxDistance * maxDistance, sqrHeadTrackDistance))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// stop tracking when target is behind the actor
|
// stop tracking when target is behind the actor
|
||||||
|
@ -434,10 +434,7 @@ namespace MWMechanics
|
||||||
osg::Vec3f targetDirection(actor2Pos - actor1Pos);
|
osg::Vec3f targetDirection(actor2Pos - actor1Pos);
|
||||||
actorDirection.z() = 0;
|
actorDirection.z() = 0;
|
||||||
targetDirection.z() = 0;
|
targetDirection.z() = 0;
|
||||||
actorDirection.normalize();
|
if (actorDirection * targetDirection > 0
|
||||||
targetDirection.normalize();
|
|
||||||
if (std::acos(actorDirection * targetDirection) < osg::DegreesToRadians(90.f)
|
|
||||||
&& sqrDist <= sqrHeadTrackDistance
|
|
||||||
&& MWBase::Environment::get().getWorld()->getLOS(actor, targetActor) // check LOS and awareness last as it's the most expensive function
|
&& 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))
|
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(targetActor, actor))
|
||||||
{
|
{
|
||||||
|
@ -475,8 +472,7 @@ namespace MWMechanics
|
||||||
|
|
||||||
void Actors::updateMovementSpeed(const MWWorld::Ptr& actor)
|
void Actors::updateMovementSpeed(const MWWorld::Ptr& actor)
|
||||||
{
|
{
|
||||||
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
|
if (mSmoothMovement)
|
||||||
if (smoothMovement)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CreatureStats &stats = actor.getClass().getCreatureStats(actor);
|
CreatureStats &stats = actor.getClass().getCreatureStats(actor);
|
||||||
|
@ -594,8 +590,11 @@ namespace MWMechanics
|
||||||
|
|
||||||
if (!actorState.isTurningToPlayer())
|
if (!actorState.isTurningToPlayer())
|
||||||
{
|
{
|
||||||
actorState.setAngleToPlayer(std::atan2(dir.x(), dir.y()));
|
float angle = std::atan2(dir.x(), dir.y());
|
||||||
actorState.setTurningToPlayer(true);
|
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
|
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 mTimerDisposeSummonsCorpses;
|
||||||
float mActorsProcessingRange;
|
float mActorsProcessingRange;
|
||||||
|
|
||||||
|
bool mSmoothMovement;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2038,6 +2038,8 @@ void CharacterController::update(float duration, bool animationOnly)
|
||||||
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 2);
|
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 2);
|
||||||
else
|
else
|
||||||
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 4);
|
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 4);
|
||||||
|
if (smoothMovement && !isPlayer && !inwater)
|
||||||
|
mAnimation->setUpperBodyYawRadians(mAnimation->getUpperBodyYawRadians() + mAnimation->getHeadYaw() / 2);
|
||||||
|
|
||||||
speed = cls.getCurrentSpeed(mPtr);
|
speed = cls.getCurrentSpeed(mPtr);
|
||||||
vec.x() *= speed;
|
vec.x() *= speed;
|
||||||
|
@ -2934,19 +2936,21 @@ void CharacterController::updateHeadTracking(float duration)
|
||||||
return;
|
return;
|
||||||
const osg::Vec3f actorDirection = mPtr.getRefData().getBaseNode()->getAttitude() * osg::Vec3f(0,1,0);
|
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());
|
zAngleRadians = std::atan2(actorDirection.x(), actorDirection.y()) - std::atan2(direction.x(), direction.y());
|
||||||
xAngleRadians = -std::asin(direction.z());
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const double xLimit = osg::DegreesToRadians(40.0);
|
||||||
|
const double zLimit = osg::DegreesToRadians(30.0);
|
||||||
|
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;
|
float factor = duration*5;
|
||||||
factor = std::min(factor, 1.f);
|
factor = std::min(factor, 1.f);
|
||||||
xAngleRadians = (1.f-factor) * mAnimation->getHeadPitch() + factor * (-xAngleRadians);
|
xAngleRadians = (1.f-factor) * mAnimation->getHeadPitch() + factor * xAngleRadians;
|
||||||
zAngleRadians = (1.f-factor) * mAnimation->getHeadYaw() + factor * (-zAngleRadians);
|
zAngleRadians = (1.f-factor) * mAnimation->getHeadYaw() + factor * zAngleRadians;
|
||||||
|
|
||||||
mAnimation->setHeadPitch(xAngleRadians);
|
mAnimation->setHeadPitch(xAngleRadians);
|
||||||
mAnimation->setHeadYaw(zAngleRadians);
|
mAnimation->setHeadYaw(zAngleRadians);
|
||||||
|
|
Loading…
Reference in a new issue