mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 12:09:45 +02:00
updated the elipes equation code for determining the forward speed of the avatar. We can now set the max forward == walkSpeed, max side and backwards == walkBackwardsSpeed and the sprint speed == sprintSpeed
This commit is contained in:
parent
f1990378fd
commit
1ad6b041cd
7 changed files with 53 additions and 49 deletions
|
@ -654,7 +654,7 @@
|
||||||
"interpDuration": 6,
|
"interpDuration": 6,
|
||||||
"interpType": "snapshotPrev",
|
"interpType": "snapshotPrev",
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "isNotMoving", "state": "idle" },
|
{ "var": "isNotMoving", "state": "idleSettle" },
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
|
@ -675,7 +675,7 @@
|
||||||
"interpDuration": 6,
|
"interpDuration": 6,
|
||||||
"interpType": "snapshotPrev",
|
"interpType": "snapshotPrev",
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "isNotMoving", "state": "idle" },
|
{ "var": "isNotMoving", "state": "idleSettle" },
|
||||||
{ "var": "isMovingForward", "state": "walkFwd" },
|
{ "var": "isMovingForward", "state": "walkFwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
|
@ -696,7 +696,7 @@
|
||||||
"interpDuration": 8,
|
"interpDuration": 8,
|
||||||
"interpType": "snapshotPrev",
|
"interpType": "snapshotPrev",
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "isNotMoving", "state": "idle" },
|
{ "var": "isNotMoving", "state": "idleSettle" },
|
||||||
{ "var": "isMovingForward", "state": "walkFwd" },
|
{ "var": "isMovingForward", "state": "walkFwd" },
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
|
@ -717,7 +717,7 @@
|
||||||
"interpDuration": 6,
|
"interpDuration": 6,
|
||||||
"interpType": "snapshotPrev",
|
"interpType": "snapshotPrev",
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "isNotMoving", "state": "idle" },
|
{ "var": "isNotMoving", "state": "idleSettle" },
|
||||||
{ "var": "isMovingForward", "state": "walkFwd" },
|
{ "var": "isMovingForward", "state": "walkFwd" },
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
|
@ -821,7 +821,7 @@
|
||||||
"interpTarget": 6,
|
"interpTarget": 6,
|
||||||
"interpDuration": 6,
|
"interpDuration": 6,
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "isNotFlying", "state": "idle" }
|
{ "var": "isNotFlying", "state": "idleSettle" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -2336,13 +2336,19 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float scaleSpeedByDirection(glm::vec2 velocityDirection, float speed) {
|
static float scaleSpeedByDirection(glm::vec2 velocityDirection, float forwardSpeed, float backwardSpeed) {
|
||||||
float scale = 1.0f;
|
// for the elipse function --> (x^2)*(1/backwardSpeed*backwardSpeed) + y^2/(forwardSpeed*forwardSpeed) = 1, scale == y^2 when x is 0
|
||||||
float x = sqrtf(1.0f - (velocityDirection.y * velocityDirection.y) / 3.0f);
|
float fwdScale = forwardSpeed * forwardSpeed;
|
||||||
if (velocityDirection.y > 0.0f) {
|
float backScale = 1.0f / (backwardSpeed * backwardSpeed);
|
||||||
scale = 0.5f;
|
float scaledX = velocityDirection.x * backwardSpeed;
|
||||||
|
float scaledSpeed = backwardSpeed;
|
||||||
|
if (velocityDirection.y < 0.0f) {
|
||||||
|
float yValue = sqrtf(fwdScale * (1.0f - (scaledX * scaledX * backScale)));
|
||||||
|
scaledSpeed = sqrtf((scaledX * scaledX) + (yValue * yValue));
|
||||||
|
} else {
|
||||||
|
scaledSpeed = backwardSpeed;
|
||||||
}
|
}
|
||||||
return scale * speed;
|
return scaledSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updateActionMotor(float deltaTime) {
|
void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
|
@ -2407,8 +2413,7 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
} else {
|
} else {
|
||||||
// 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 wspd = _walkSpeed.get();
|
float scaledSpeed = scaleSpeedByDirection(currentVel, _walkSpeed.get(), _walkBackwardSpeed.get());
|
||||||
float scaledSpeed = scaleSpeedByDirection(currentVel, wspd);
|
|
||||||
_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction;
|
_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3418,6 +3423,10 @@ float MyAvatar::getWalkSpeed() const {
|
||||||
return _walkSpeed.get() * _walkSpeedScalar;
|
return _walkSpeed.get() * _walkSpeedScalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float MyAvatar::getWalkBackwardSpeed() const {
|
||||||
|
return _walkSpeed.get() * _walkSpeedScalar;
|
||||||
|
}
|
||||||
|
|
||||||
bool MyAvatar::isReadyForPhysics() const {
|
bool MyAvatar::isReadyForPhysics() const {
|
||||||
return qApp->isServerlessMode() || _haveReceivedHeightLimitsFromDomain;
|
return qApp->isServerlessMode() || _haveReceivedHeightLimitsFromDomain;
|
||||||
}
|
}
|
||||||
|
@ -3430,6 +3439,11 @@ void MyAvatar::setWalkSpeed(float value) {
|
||||||
_walkSpeed.set(value);
|
_walkSpeed.set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyAvatar::setWalkBackwardSpeed(float value) {
|
||||||
|
_walkBackwardSpeed.set(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MyAvatar::setSprintSpeed(float speed) {
|
void MyAvatar::setSprintSpeed(float speed) {
|
||||||
_sprintSpeed.set(speed);
|
_sprintSpeed.set(speed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,7 @@ class MyAvatar : public Avatar {
|
||||||
* where MyAvatar.sessionUUID is not available (e.g., if not connected to a domain). Note: Likely to be deprecated.
|
* where MyAvatar.sessionUUID is not available (e.g., if not connected to a domain). Note: Likely to be deprecated.
|
||||||
* <em>Read-only.</em>
|
* <em>Read-only.</em>
|
||||||
* @property {number} walkSpeed
|
* @property {number} walkSpeed
|
||||||
|
* @property {number} walkBackwardSpeed
|
||||||
* @property {number} sprintSpeed
|
* @property {number} sprintSpeed
|
||||||
*
|
*
|
||||||
* @property {Vec3} skeletonOffset - Can be used to apply a translation offset between the avatar's position and the
|
* @property {Vec3} skeletonOffset - Can be used to apply a translation offset between the avatar's position and the
|
||||||
|
@ -234,6 +235,7 @@ class MyAvatar : public Avatar {
|
||||||
Q_PROPERTY(QUuid SELF_ID READ getSelfID CONSTANT)
|
Q_PROPERTY(QUuid SELF_ID READ getSelfID CONSTANT)
|
||||||
|
|
||||||
Q_PROPERTY(float walkSpeed READ getWalkSpeed WRITE setWalkSpeed);
|
Q_PROPERTY(float walkSpeed READ getWalkSpeed WRITE setWalkSpeed);
|
||||||
|
Q_PROPERTY(float walkBackwardSpeed READ getWalkBackwardSpeed WRITE setWalkBackwardSpeed);
|
||||||
Q_PROPERTY(float sprintSpeed READ getSprintSpeed WRITE setSprintSpeed);
|
Q_PROPERTY(float sprintSpeed READ getSprintSpeed WRITE setSprintSpeed);
|
||||||
|
|
||||||
const QString DOMINANT_LEFT_HAND = "left";
|
const QString DOMINANT_LEFT_HAND = "left";
|
||||||
|
@ -1076,6 +1078,8 @@ public:
|
||||||
|
|
||||||
void setWalkSpeed(float value);
|
void setWalkSpeed(float value);
|
||||||
float getWalkSpeed() const;
|
float getWalkSpeed() const;
|
||||||
|
void setWalkBackwardSpeed(float value);
|
||||||
|
float getWalkBackwardSpeed() const;
|
||||||
void setSprintSpeed(float speed);
|
void setSprintSpeed(float speed);
|
||||||
float getSprintSpeed() const;
|
float getSprintSpeed() const;
|
||||||
|
|
||||||
|
@ -1735,6 +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> _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR };
|
ThreadSafeValueCache<float> _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR };
|
||||||
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "SequenceNumberStats.h"
|
#include "SequenceNumberStats.h"
|
||||||
#include "StatTracker.h"
|
#include "StatTracker.h"
|
||||||
#include "InterfaceLogging.h"
|
|
||||||
|
|
||||||
|
|
||||||
HIFI_QML_DEF(Stats)
|
HIFI_QML_DEF(Stats)
|
||||||
|
@ -194,12 +193,10 @@ void Stats::updateStats(bool force) {
|
||||||
auto myAvatar = avatarManager->getMyAvatar();
|
auto myAvatar = avatarManager->getMyAvatar();
|
||||||
auto rigCopy = myAvatar->getSkeletonModel();
|
auto rigCopy = myAvatar->getSkeletonModel();
|
||||||
auto animStack = rigCopy->getRig().getAnimStack();
|
auto animStack = rigCopy->getRig().getAnimStack();
|
||||||
qCDebug(interfaceapp) << "Animation Stack Begin: ";
|
|
||||||
|
|
||||||
//check to see if the anim stack has changed
|
//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) {
|
||||||
qCDebug(interfaceapp) << "---" << animStackIterator->first << " " << animStackIterator->second;
|
|
||||||
_animStackNames << animStackIterator->first + ": " + QString::number(animStackIterator->second,'f',3);
|
_animStackNames << animStackIterator->first + ": " + QString::number(animStackIterator->second,'f',3);
|
||||||
}
|
}
|
||||||
emit animStackNamesChanged();
|
emit animStackNamesChanged();
|
||||||
|
|
|
@ -37,27 +37,24 @@ const AnimPoseVec& AnimBlendLinear::evaluate(const AnimVariantMap& animVars, con
|
||||||
_poses = _children[0]->evaluate(animVars, context, dt, triggersOut);
|
_poses = _children[0]->evaluate(animVars, context, dt, triggersOut);
|
||||||
_animStack[_children[0]->getID()] = parentAlpha;
|
_animStack[_children[0]->getID()] = parentAlpha;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
float clampedAlpha = glm::clamp(_alpha, 0.0f, (float)(_children.size() - 1));
|
float clampedAlpha = glm::clamp(_alpha, 0.0f, (float)(_children.size() - 1));
|
||||||
size_t prevPoseIndex = glm::floor(clampedAlpha);
|
size_t prevPoseIndex = glm::floor(clampedAlpha);
|
||||||
size_t nextPoseIndex = glm::ceil(clampedAlpha);
|
size_t nextPoseIndex = glm::ceil(clampedAlpha);
|
||||||
if (prevPoseIndex == nextPoseIndex) {
|
auto alpha = glm::fract(clampedAlpha);
|
||||||
if (nextPoseIndex == 0) {
|
|
||||||
nextPoseIndex = 1;
|
|
||||||
} else {
|
|
||||||
prevPoseIndex = (nextPoseIndex - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float alpha = clampedAlpha - (float)prevPoseIndex;
|
|
||||||
evaluateAndBlendChildren(animVars, context, triggersOut, alpha, prevPoseIndex, nextPoseIndex, dt);
|
evaluateAndBlendChildren(animVars, context, triggersOut, alpha, prevPoseIndex, nextPoseIndex, dt);
|
||||||
|
|
||||||
float weight2 = _alpha - (float)prevPoseIndex;
|
// weights are for animation stack debug purposes only.
|
||||||
float weight1 = 1.0f - weight2;
|
float weight1 = 0.0f;
|
||||||
_animStack[_children[prevPoseIndex]->getID()] = weight1 * parentAlpha;
|
float weight2 = 0.0f;
|
||||||
if (nextPoseIndex < _children.size()) {
|
if (prevPoseIndex == nextPoseIndex) {
|
||||||
|
weight2 = 1.0f;
|
||||||
|
_animStack[_children[nextPoseIndex]->getID()] = weight2 * parentAlpha;
|
||||||
|
} else {
|
||||||
|
weight2 = alpha;
|
||||||
|
weight1 = 1.0f - weight2;
|
||||||
|
_animStack[_children[prevPoseIndex]->getID()] = weight1 * parentAlpha;
|
||||||
_animStack[_children[nextPoseIndex]->getID()] = weight2 * parentAlpha;
|
_animStack[_children[nextPoseIndex]->getID()] = weight2 * parentAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
processOutputJoints(triggersOut);
|
processOutputJoints(triggersOut);
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,6 @@ const AnimPoseVec& AnimBlendLinearMove::evaluate(const AnimVariantMap& animVars,
|
||||||
|
|
||||||
_animStack["speed"] = speed;
|
_animStack["speed"] = speed;
|
||||||
|
|
||||||
qCDebug(animation) << "speed is now: " << speed;
|
|
||||||
|
|
||||||
if (_children.size() == 0) {
|
if (_children.size() == 0) {
|
||||||
for (auto&& pose : _poses) {
|
for (auto&& pose : _poses) {
|
||||||
pose = AnimPose::identity;
|
pose = AnimPose::identity;
|
||||||
|
@ -90,10 +88,16 @@ const AnimPoseVec& AnimBlendLinearMove::evaluate(const AnimVariantMap& animVars,
|
||||||
setFrameAndPhase(dt, alpha, prevPoseIndex, nextPoseIndex, &prevDeltaTime, &nextDeltaTime, triggersOut);
|
setFrameAndPhase(dt, alpha, prevPoseIndex, nextPoseIndex, &prevDeltaTime, &nextDeltaTime, triggersOut);
|
||||||
evaluateAndBlendChildren(animVars, context, triggersOut, alpha, prevPoseIndex, nextPoseIndex, prevDeltaTime, nextDeltaTime);
|
evaluateAndBlendChildren(animVars, context, triggersOut, alpha, prevPoseIndex, nextPoseIndex, prevDeltaTime, nextDeltaTime);
|
||||||
|
|
||||||
float weight2 = alpha;
|
// weights are for animation stack debug purposes only.
|
||||||
float weight1 = 1.0f - weight2;
|
float weight1 = 0.0f;
|
||||||
_animStack[_children[prevPoseIndex]->getID()] = weight1 * parentAlpha;
|
float weight2 = 0.0f;
|
||||||
if ((int)nextPoseIndex < _children.size()) {
|
if (prevPoseIndex == nextPoseIndex) {
|
||||||
|
weight2 = 1.0f;
|
||||||
|
_animStack[_children[nextPoseIndex]->getID()] = weight2 * parentAlpha;
|
||||||
|
} else {
|
||||||
|
weight2 = alpha;
|
||||||
|
weight1 = 1.0f - weight2;
|
||||||
|
_animStack[_children[prevPoseIndex]->getID()] = weight1 * parentAlpha;
|
||||||
_animStack[_children[nextPoseIndex]->getID()] = weight2 * parentAlpha;
|
_animStack[_children[nextPoseIndex]->getID()] = weight2 * parentAlpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -815,19 +815,6 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isInAirRun", false);
|
_animVars.set("isInAirRun", false);
|
||||||
_animVars.set("isNotInAir", true);
|
_animVars.set("isNotInAir", true);
|
||||||
|
|
||||||
if (false) {
|
|
||||||
// if we are changing anim states.
|
|
||||||
//reset the average speed to the current reading of speed
|
|
||||||
qCDebug(animation) << "reset the average movement speeds";
|
|
||||||
_averageForwardSpeed.reset();
|
|
||||||
_averageLateralSpeed.reset();
|
|
||||||
_averageForwardSpeed.updateAverage(forwardSpeed);
|
|
||||||
_averageLateralSpeed.updateAverage(lateralSpeed);
|
|
||||||
_animVars.set("moveForwardSpeed", _averageForwardSpeed.getAverage());
|
|
||||||
_animVars.set("moveBackwardSpeed", -_averageForwardSpeed.getAverage());
|
|
||||||
_animVars.set("moveLateralSpeed", fabsf(_averageLateralSpeed.getAverage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_state == RigRole::Turn) {
|
} else if (_state == RigRole::Turn) {
|
||||||
if (turningSpeed > 0.0f) {
|
if (turningSpeed > 0.0f) {
|
||||||
// turning right
|
// turning right
|
||||||
|
|
Loading…
Reference in a new issue