mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:24:24 +02:00
cleaned up to match coding standards
This commit is contained in:
parent
1ad6b041cd
commit
84619e7adc
6 changed files with 26 additions and 42 deletions
|
@ -2336,15 +2336,17 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float scaleSpeedByDirection(glm::vec2 velocityDirection, float forwardSpeed, float backwardSpeed) {
|
static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const float forwardSpeed, const float backwardSpeed) {
|
||||||
// for the elipse function --> (x^2)*(1/backwardSpeed*backwardSpeed) + y^2/(forwardSpeed*forwardSpeed) = 1, scale == y^2 when x is 0
|
// for the elipse function --> (x^2)/(backwardSpeed*backwardSpeed) + y^2/(forwardSpeed*forwardSpeed) = 1, scale == y^2 when x is 0
|
||||||
float fwdScale = forwardSpeed * forwardSpeed;
|
float fwdScale = forwardSpeed * forwardSpeed;
|
||||||
float backScale = 1.0f / (backwardSpeed * backwardSpeed);
|
float backScale = backwardSpeed * backwardSpeed;
|
||||||
float scaledX = velocityDirection.x * backwardSpeed;
|
float scaledX = velocityDirection.x * backwardSpeed;
|
||||||
float scaledSpeed = backwardSpeed;
|
float scaledSpeed = forwardSpeed;
|
||||||
if (velocityDirection.y < 0.0f) {
|
if (velocityDirection.y < 0.0f) {
|
||||||
float yValue = sqrtf(fwdScale * (1.0f - (scaledX * scaledX * backScale)));
|
if (backScale > 0.0f) {
|
||||||
scaledSpeed = sqrtf((scaledX * scaledX) + (yValue * yValue));
|
float yValue = sqrtf(fwdScale * (1.0f - ((scaledX * scaledX) / backScale)));
|
||||||
|
scaledSpeed = sqrtf((scaledX * scaledX) + (yValue * yValue));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scaledSpeed = backwardSpeed;
|
scaledSpeed = backwardSpeed;
|
||||||
}
|
}
|
||||||
|
@ -2414,6 +2416,7 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
// we're interacting with a floor --> simple horizontal speed and exponential decay
|
// we're interacting with a floor --> simple horizontal speed and exponential decay
|
||||||
const glm::vec2 currentVel = { direction.x, direction.z };
|
const glm::vec2 currentVel = { direction.x, direction.z };
|
||||||
float scaledSpeed = scaleSpeedByDirection(currentVel, _walkSpeed.get(), _walkBackwardSpeed.get());
|
float scaledSpeed = scaleSpeedByDirection(currentVel, _walkSpeed.get(), _walkBackwardSpeed.get());
|
||||||
|
// _walkSpeedScalar is a multiplier if we are in sprint mode, otherwise 1.0
|
||||||
_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction;
|
_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3444,8 +3447,8 @@ void MyAvatar::setWalkBackwardSpeed(float value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MyAvatar::setSprintSpeed(float speed) {
|
void MyAvatar::setSprintSpeed(float value) {
|
||||||
_sprintSpeed.set(speed);
|
_sprintSpeed.set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
float MyAvatar::getSprintSpeed() const {
|
float MyAvatar::getSprintSpeed() const {
|
||||||
|
|
|
@ -1080,7 +1080,7 @@ public:
|
||||||
float getWalkSpeed() const;
|
float getWalkSpeed() const;
|
||||||
void setWalkBackwardSpeed(float value);
|
void setWalkBackwardSpeed(float value);
|
||||||
float getWalkBackwardSpeed() const;
|
float getWalkBackwardSpeed() const;
|
||||||
void setSprintSpeed(float speed);
|
void setSprintSpeed(float value);
|
||||||
float getSprintSpeed() const;
|
float getSprintSpeed() const;
|
||||||
|
|
||||||
QVector<QString> getScriptUrls();
|
QVector<QString> getScriptUrls();
|
||||||
|
@ -1739,7 +1739,7 @@ private:
|
||||||
|
|
||||||
// max unscaled forward movement speed
|
// max unscaled forward movement speed
|
||||||
ThreadSafeValueCache<float> _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED };
|
ThreadSafeValueCache<float> _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED };
|
||||||
ThreadSafeValueCache<float> _walkBackwardSpeed{ 0.5 * DEFAULT_AVATAR_MAX_WALKING_SPEED };
|
ThreadSafeValueCache<float> _walkBackwardSpeed{ DEFAULT_AVATAR_MAX_WALKING_SPEED };
|
||||||
ThreadSafeValueCache<float> _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR };
|
ThreadSafeValueCache<float> _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR };
|
||||||
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
||||||
|
|
||||||
|
|
|
@ -191,13 +191,11 @@ void Stats::updateStats(bool force) {
|
||||||
|
|
||||||
// Third column, avatar stats
|
// Third column, avatar stats
|
||||||
auto myAvatar = avatarManager->getMyAvatar();
|
auto myAvatar = avatarManager->getMyAvatar();
|
||||||
auto rigCopy = myAvatar->getSkeletonModel();
|
auto animStack = myAvatar->getSkeletonModel()->getRig().getAnimStack();
|
||||||
auto animStack = rigCopy->getRig().getAnimStack();
|
|
||||||
|
|
||||||
//check to see if the anim stack has changed
|
|
||||||
_animStackNames.clear();
|
_animStackNames.clear();
|
||||||
for (auto animStackIterator = animStack.begin(); animStackIterator != animStack.end(); ++animStackIterator) {
|
for (auto animStackIterator = animStack.begin(); animStackIterator != animStack.end(); ++animStackIterator) {
|
||||||
_animStackNames << animStackIterator->first + ": " + QString::number(animStackIterator->second,'f',3);
|
_animStackNames << animStackIterator->first + ": " + QString::number(animStackIterator->second,'f',3);
|
||||||
}
|
}
|
||||||
emit animStackNamesChanged();
|
emit animStackNamesChanged();
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ protected:
|
||||||
std::weak_ptr<AnimNode> _parent;
|
std::weak_ptr<AnimNode> _parent;
|
||||||
std::vector<QString> _outputJointNames;
|
std::vector<QString> _outputJointNames;
|
||||||
|
|
||||||
//global available to Stats.h
|
// global available to Stats.h
|
||||||
static std::map<QString, float> _animStack;
|
static std::map<QString, float> _animStack;
|
||||||
|
|
||||||
// no copies
|
// no copies
|
||||||
|
|
|
@ -33,6 +33,7 @@ const AnimPoseVec& AnimStateMachine::evaluate(const AnimVariantMap& animVars, co
|
||||||
bool foundState = false;
|
bool foundState = false;
|
||||||
for (auto& state : _states) {
|
for (auto& state : _states) {
|
||||||
if (state->getID() == desiredStateID) {
|
if (state->getID() == desiredStateID) {
|
||||||
|
// parenthesis means previous state, which is a snapshot.
|
||||||
_previousStateID = "(" + _currentState->getID() + ")";
|
_previousStateID = "(" + _currentState->getID() + ")";
|
||||||
switchState(animVars, context, state);
|
switchState(animVars, context, state);
|
||||||
foundState = true;
|
foundState = true;
|
||||||
|
@ -47,7 +48,7 @@ const AnimPoseVec& AnimStateMachine::evaluate(const AnimVariantMap& animVars, co
|
||||||
// evaluate currentState transitions
|
// evaluate currentState transitions
|
||||||
auto desiredState = evaluateTransitions(animVars);
|
auto desiredState = evaluateTransitions(animVars);
|
||||||
if (desiredState != _currentState) {
|
if (desiredState != _currentState) {
|
||||||
//parenthesis means snapshot of this state.
|
// parenthesis means previous state, which is a snapshot.
|
||||||
_previousStateID = "(" + _currentState->getID() + ")";
|
_previousStateID = "(" + _currentState->getID() + ")";
|
||||||
switchState(animVars, context, desiredState);
|
switchState(animVars, context, desiredState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -641,10 +641,6 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
float lateralSpeed = glm::dot(localVel, IDENTITY_RIGHT);
|
float lateralSpeed = glm::dot(localVel, IDENTITY_RIGHT);
|
||||||
float turningSpeed = glm::orientedAngle(forward, _lastForward, IDENTITY_UP) / deltaTime;
|
float turningSpeed = glm::orientedAngle(forward, _lastForward, IDENTITY_UP) / deltaTime;
|
||||||
|
|
||||||
glm::vec3 lastVel = glm::inverse(worldRotation) * _lastVelocity;
|
|
||||||
float lastForwardSpeed = glm::dot(lastVel, IDENTITY_FORWARD);
|
|
||||||
float lastLateralSpeed = glm::dot(lastVel, IDENTITY_RIGHT);
|
|
||||||
|
|
||||||
// filter speeds using a simple moving average.
|
// filter speeds using a simple moving average.
|
||||||
_averageForwardSpeed.updateAverage(forwardSpeed);
|
_averageForwardSpeed.updateAverage(forwardSpeed);
|
||||||
_averageLateralSpeed.updateAverage(lateralSpeed);
|
_averageLateralSpeed.updateAverage(lateralSpeed);
|
||||||
|
@ -729,16 +725,11 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
|
|
||||||
_desiredStateAge += deltaTime;
|
_desiredStateAge += deltaTime;
|
||||||
|
|
||||||
bool resetVelocityAverage = false;
|
|
||||||
|
|
||||||
if (_state == RigRole::Move) {
|
if (_state == RigRole::Move) {
|
||||||
glm::vec3 horizontalVel = localVel - glm::vec3(0.0f, localVel.y, 0.0f);
|
glm::vec3 horizontalVel = localVel - glm::vec3(0.0f, localVel.y, 0.0f);
|
||||||
if (glm::length(horizontalVel) > MOVE_ENTER_SPEED_THRESHOLD) {
|
if (glm::length(horizontalVel) > MOVE_ENTER_SPEED_THRESHOLD) {
|
||||||
if (fabsf(forwardSpeed) > 0.5f * fabsf(lateralSpeed)) {
|
if (fabsf(forwardSpeed) > 0.5f * fabsf(lateralSpeed)) {
|
||||||
if (forwardSpeed > 0.0f) {
|
if (forwardSpeed > 0.0f) {
|
||||||
if (lastForwardSpeed < 0.0f) {
|
|
||||||
resetVelocityAverage = true;
|
|
||||||
}
|
|
||||||
// forward
|
// forward
|
||||||
_animVars.set("isMovingForward", true);
|
_animVars.set("isMovingForward", true);
|
||||||
_animVars.set("isMovingBackward", false);
|
_animVars.set("isMovingBackward", false);
|
||||||
|
@ -749,9 +740,6 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isNotMoving", false);
|
_animVars.set("isNotMoving", false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (lastForwardSpeed > 0.0f) {
|
|
||||||
resetVelocityAverage = true;
|
|
||||||
}
|
|
||||||
// backward
|
// backward
|
||||||
_animVars.set("isMovingBackward", true);
|
_animVars.set("isMovingBackward", true);
|
||||||
_animVars.set("isMovingForward", false);
|
_animVars.set("isMovingForward", false);
|
||||||
|
@ -763,9 +751,6 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (lateralSpeed > 0.0f) {
|
if (lateralSpeed > 0.0f) {
|
||||||
if (lastLateralSpeed < 0.0f) {
|
|
||||||
resetVelocityAverage = true;
|
|
||||||
}
|
|
||||||
// right
|
// right
|
||||||
if (!_headEnabled) {
|
if (!_headEnabled) {
|
||||||
_animVars.set("isMovingRight", true);
|
_animVars.set("isMovingRight", true);
|
||||||
|
@ -782,9 +767,6 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isMovingBackward", false);
|
_animVars.set("isMovingBackward", false);
|
||||||
_animVars.set("isNotMoving", false);
|
_animVars.set("isNotMoving", false);
|
||||||
} else {
|
} else {
|
||||||
if (lastLateralSpeed > 0.0f) {
|
|
||||||
resetVelocityAverage = true;
|
|
||||||
}
|
|
||||||
// left
|
// left
|
||||||
if (!_headEnabled) {
|
if (!_headEnabled) {
|
||||||
_animVars.set("isMovingRight", false);
|
_animVars.set("isMovingRight", false);
|
||||||
|
@ -803,8 +785,8 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_animVars.set("isTurningLeft", false);
|
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
_animVars.set("isFlying", false);
|
_animVars.set("isFlying", false);
|
||||||
_animVars.set("isNotFlying", true);
|
_animVars.set("isNotFlying", true);
|
||||||
|
@ -823,8 +805,8 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isNotTurning", false);
|
_animVars.set("isNotTurning", false);
|
||||||
} else {
|
} else {
|
||||||
// turning left
|
// turning left
|
||||||
_animVars.set("isTurningLeft", true);
|
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isTurningLeft", true);
|
||||||
_animVars.set("isNotTurning", false);
|
_animVars.set("isNotTurning", false);
|
||||||
}
|
}
|
||||||
_animVars.set("isMovingForward", false);
|
_animVars.set("isMovingForward", false);
|
||||||
|
@ -852,8 +834,8 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isMovingRightHmd", false);
|
_animVars.set("isMovingRightHmd", false);
|
||||||
_animVars.set("isMovingLeftHmd", false);
|
_animVars.set("isMovingLeftHmd", false);
|
||||||
_animVars.set("isNotMoving", true);
|
_animVars.set("isNotMoving", true);
|
||||||
_animVars.set("isTurningLeft", false);
|
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
_animVars.set("isFlying", false);
|
_animVars.set("isFlying", false);
|
||||||
_animVars.set("isNotFlying", true);
|
_animVars.set("isNotFlying", true);
|
||||||
|
@ -873,8 +855,8 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isMovingRightHmd", false);
|
_animVars.set("isMovingRightHmd", false);
|
||||||
_animVars.set("isMovingLeftHmd", false);
|
_animVars.set("isMovingLeftHmd", false);
|
||||||
_animVars.set("isNotMoving", true);
|
_animVars.set("isNotMoving", true);
|
||||||
_animVars.set("isTurningLeft", false);
|
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
_animVars.set("isFlying", true);
|
_animVars.set("isFlying", true);
|
||||||
_animVars.set("isNotFlying", false);
|
_animVars.set("isNotFlying", false);
|
||||||
|
@ -889,13 +871,13 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
// jumping in-air
|
// jumping in-air
|
||||||
_animVars.set("isMovingForward", false);
|
_animVars.set("isMovingForward", false);
|
||||||
_animVars.set("isMovingBackward", false);
|
_animVars.set("isMovingBackward", false);
|
||||||
_animVars.set("isMovingLeft", false);
|
|
||||||
_animVars.set("isMovingRight", false);
|
_animVars.set("isMovingRight", false);
|
||||||
|
_animVars.set("isMovingLeft", false);
|
||||||
_animVars.set("isMovingRightHmd", false);
|
_animVars.set("isMovingRightHmd", false);
|
||||||
_animVars.set("isMovingLeftHmd", false);
|
_animVars.set("isMovingLeftHmd", false);
|
||||||
_animVars.set("isNotMoving", true);
|
_animVars.set("isNotMoving", true);
|
||||||
_animVars.set("isTurningLeft", false);
|
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
_animVars.set("isFlying", false);
|
_animVars.set("isFlying", false);
|
||||||
_animVars.set("isNotFlying", true);
|
_animVars.set("isNotFlying", true);
|
||||||
|
@ -918,13 +900,13 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
// jumping in-air
|
// jumping in-air
|
||||||
_animVars.set("isMovingForward", false);
|
_animVars.set("isMovingForward", false);
|
||||||
_animVars.set("isMovingBackward", false);
|
_animVars.set("isMovingBackward", false);
|
||||||
_animVars.set("isMovingLeft", false);
|
|
||||||
_animVars.set("isMovingRight", false);
|
_animVars.set("isMovingRight", false);
|
||||||
|
_animVars.set("isMovingLeft", false);
|
||||||
_animVars.set("isMovingRightHmd", false);
|
_animVars.set("isMovingRightHmd", false);
|
||||||
_animVars.set("isMovingLeftHmd", false);
|
_animVars.set("isMovingLeftHmd", false);
|
||||||
_animVars.set("isNotMoving", true);
|
_animVars.set("isNotMoving", true);
|
||||||
_animVars.set("isTurningLeft", false);
|
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
_animVars.set("isFlying", false);
|
_animVars.set("isFlying", false);
|
||||||
_animVars.set("isNotFlying", true);
|
_animVars.set("isNotFlying", true);
|
||||||
|
|
Loading…
Reference in a new issue