mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 13:44:36 +02:00
Merge pull request #14851 from AndrewMeadows/myAvatar-unmovable-until-floor
case 20048: don't allow MyAvatar to move until physics enabled
This commit is contained in:
commit
30a6f25b69
4 changed files with 42 additions and 36 deletions
|
@ -75,7 +75,6 @@ const float PITCH_SPEED_DEFAULT = 75.0f; // degrees/sec
|
||||||
|
|
||||||
const float MAX_BOOST_SPEED = 0.5f * DEFAULT_AVATAR_MAX_WALKING_SPEED; // action motor gets additive boost below this speed
|
const float MAX_BOOST_SPEED = 0.5f * DEFAULT_AVATAR_MAX_WALKING_SPEED; // action motor gets additive boost below this speed
|
||||||
const float MIN_AVATAR_SPEED = 0.05f;
|
const float MIN_AVATAR_SPEED = 0.05f;
|
||||||
const float MIN_AVATAR_SPEED_SQUARED = MIN_AVATAR_SPEED * MIN_AVATAR_SPEED; // speed is set to zero below this
|
|
||||||
|
|
||||||
float MIN_SCRIPTED_MOTOR_TIMESCALE = 0.005f;
|
float MIN_SCRIPTED_MOTOR_TIMESCALE = 0.005f;
|
||||||
float DEFAULT_SCRIPTED_MOTOR_TIMESCALE = 1.0e6f;
|
float DEFAULT_SCRIPTED_MOTOR_TIMESCALE = 1.0e6f;
|
||||||
|
@ -847,6 +846,7 @@ void MyAvatar::simulate(float deltaTime, bool inView) {
|
||||||
|
|
||||||
updateOrientation(deltaTime);
|
updateOrientation(deltaTime);
|
||||||
updatePosition(deltaTime);
|
updatePosition(deltaTime);
|
||||||
|
updateViewBoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update sensorToWorldMatrix for camera and hand controllers
|
// update sensorToWorldMatrix for camera and hand controllers
|
||||||
|
@ -3323,21 +3323,22 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
direction = Vectors::ZERO;
|
direction = Vectors::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float sensorToWorldScale = getSensorToWorldScale();
|
||||||
if (state == CharacterController::State::Hover) {
|
if (state == CharacterController::State::Hover) {
|
||||||
// we're flying --> complex acceleration curve that builds on top of current motor speed and caps at some max speed
|
// we're flying --> complex acceleration curve that builds on top of current motor speed and caps at some max speed
|
||||||
|
|
||||||
float motorSpeed = glm::length(_actionMotorVelocity);
|
float motorSpeed = glm::length(_actionMotorVelocity);
|
||||||
float finalMaxMotorSpeed = getSensorToWorldScale() * DEFAULT_AVATAR_MAX_FLYING_SPEED * _walkSpeedScalar;
|
float finalMaxMotorSpeed = sensorToWorldScale * DEFAULT_AVATAR_MAX_FLYING_SPEED * _walkSpeedScalar;
|
||||||
float speedGrowthTimescale = 2.0f;
|
float speedGrowthTimescale = 2.0f;
|
||||||
float speedIncreaseFactor = 1.8f * _walkSpeedScalar;
|
float speedIncreaseFactor = 1.8f * _walkSpeedScalar;
|
||||||
motorSpeed *= 1.0f + glm::clamp(deltaTime / speedGrowthTimescale, 0.0f, 1.0f) * speedIncreaseFactor;
|
motorSpeed *= 1.0f + glm::clamp(deltaTime / speedGrowthTimescale, 0.0f, 1.0f) * speedIncreaseFactor;
|
||||||
const float maxBoostSpeed = getSensorToWorldScale() * MAX_BOOST_SPEED;
|
const float maxBoostSpeed = sensorToWorldScale * MAX_BOOST_SPEED;
|
||||||
|
|
||||||
if (_isPushing) {
|
if (_isPushing) {
|
||||||
if (motorSpeed < maxBoostSpeed) {
|
if (motorSpeed < maxBoostSpeed) {
|
||||||
// an active action motor should never be slower than this
|
// an active action motor should never be slower than this
|
||||||
float boostCoefficient = (maxBoostSpeed - motorSpeed) / maxBoostSpeed;
|
float boostCoefficient = (maxBoostSpeed - motorSpeed) / maxBoostSpeed;
|
||||||
motorSpeed += getSensorToWorldScale() * MIN_AVATAR_SPEED * boostCoefficient;
|
motorSpeed += sensorToWorldScale * MIN_AVATAR_SPEED * boostCoefficient;
|
||||||
} else if (motorSpeed > finalMaxMotorSpeed) {
|
} else if (motorSpeed > finalMaxMotorSpeed) {
|
||||||
motorSpeed = finalMaxMotorSpeed;
|
motorSpeed = finalMaxMotorSpeed;
|
||||||
}
|
}
|
||||||
|
@ -3348,45 +3349,21 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
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
|
// _walkSpeedScalar is a multiplier if we are in sprint mode, otherwise 1.0
|
||||||
_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction;
|
_actionMotorVelocity = sensorToWorldScale * (scaledSpeed * _walkSpeedScalar) * direction;
|
||||||
}
|
|
||||||
|
|
||||||
float previousBoomLength = _boomLength;
|
|
||||||
float boomChange = getDriveKey(ZOOM);
|
|
||||||
_boomLength += 2.0f * _boomLength * boomChange + boomChange * boomChange;
|
|
||||||
_boomLength = glm::clamp<float>(_boomLength, ZOOM_MIN, ZOOM_MAX);
|
|
||||||
|
|
||||||
// May need to change view if boom length has changed
|
|
||||||
if (previousBoomLength != _boomLength) {
|
|
||||||
qApp->changeViewAsNeeded(_boomLength);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updatePosition(float deltaTime) {
|
void MyAvatar::updatePosition(float deltaTime) {
|
||||||
if (_motionBehaviors & AVATAR_MOTION_ACTION_MOTOR_ENABLED) {
|
if (_characterController.isEnabledAndReady()) {
|
||||||
updateActionMotor(deltaTime);
|
if (_motionBehaviors & AVATAR_MOTION_ACTION_MOTOR_ENABLED) {
|
||||||
}
|
updateActionMotor(deltaTime);
|
||||||
|
|
||||||
vec3 velocity = getWorldVelocity();
|
|
||||||
float sensorToWorldScale = getSensorToWorldScale();
|
|
||||||
float sensorToWorldScale2 = sensorToWorldScale * sensorToWorldScale;
|
|
||||||
const float MOVING_SPEED_THRESHOLD_SQUARED = 0.0001f; // 0.01 m/s
|
|
||||||
if (!_characterController.isEnabledAndReady()) {
|
|
||||||
// _characterController is not in physics simulation but it can still compute its target velocity
|
|
||||||
updateMotors();
|
|
||||||
_characterController.computeNewVelocity(deltaTime, velocity);
|
|
||||||
|
|
||||||
float speed2 = glm::length(velocity);
|
|
||||||
if (speed2 > sensorToWorldScale2 * MIN_AVATAR_SPEED_SQUARED) {
|
|
||||||
// update position ourselves
|
|
||||||
applyPositionDelta(deltaTime * velocity);
|
|
||||||
}
|
}
|
||||||
measureMotionDerivatives(deltaTime);
|
float sensorToWorldScale = getSensorToWorldScale();
|
||||||
_moving = speed2 > sensorToWorldScale2 * MOVING_SPEED_THRESHOLD_SQUARED;
|
float sensorToWorldScale2 = sensorToWorldScale * sensorToWorldScale;
|
||||||
} else {
|
vec3 velocity = getWorldVelocity();
|
||||||
float speed2 = glm::length2(velocity);
|
float speed2 = glm::length2(velocity);
|
||||||
|
const float MOVING_SPEED_THRESHOLD_SQUARED = 0.0001f; // 0.01 m/s
|
||||||
_moving = speed2 > sensorToWorldScale2 * MOVING_SPEED_THRESHOLD_SQUARED;
|
_moving = speed2 > sensorToWorldScale2 * MOVING_SPEED_THRESHOLD_SQUARED;
|
||||||
|
|
||||||
if (_moving) {
|
if (_moving) {
|
||||||
// scan for walkability
|
// scan for walkability
|
||||||
glm::vec3 position = getWorldPosition();
|
glm::vec3 position = getWorldPosition();
|
||||||
|
@ -3398,6 +3375,18 @@ void MyAvatar::updatePosition(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyAvatar::updateViewBoom() {
|
||||||
|
float previousBoomLength = _boomLength;
|
||||||
|
float boomChange = getDriveKey(ZOOM);
|
||||||
|
_boomLength += 2.0f * _boomLength * boomChange + boomChange * boomChange;
|
||||||
|
_boomLength = glm::clamp<float>(_boomLength, ZOOM_MIN, ZOOM_MAX);
|
||||||
|
|
||||||
|
// May need to change view if boom length has changed
|
||||||
|
if (previousBoomLength != _boomLength) {
|
||||||
|
qApp->changeViewAsNeeded(_boomLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::updateCollisionSound(const glm::vec3 &penetration, float deltaTime, float frequency) {
|
void MyAvatar::updateCollisionSound(const glm::vec3 &penetration, float deltaTime, float frequency) {
|
||||||
// COLLISION SOUND API in Audio has been removed
|
// COLLISION SOUND API in Audio has been removed
|
||||||
}
|
}
|
||||||
|
|
|
@ -1732,6 +1732,7 @@ private:
|
||||||
void updateOrientation(float deltaTime);
|
void updateOrientation(float deltaTime);
|
||||||
void updateActionMotor(float deltaTime);
|
void updateActionMotor(float deltaTime);
|
||||||
void updatePosition(float deltaTime);
|
void updatePosition(float deltaTime);
|
||||||
|
void updateViewBoom();
|
||||||
void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);
|
void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);
|
||||||
void initHeadBones();
|
void initHeadBones();
|
||||||
void initAnimGraph();
|
void initAnimGraph();
|
||||||
|
|
|
@ -11,6 +11,16 @@
|
||||||
|
|
||||||
#include "CrashHelpers.h"
|
#include "CrashHelpers.h"
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
// undefine NDEBUG so doAssert() works for all builds
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <assert.h>
|
||||||
|
#define NDEBUG
|
||||||
|
#else
|
||||||
|
#include <assert.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace crash {
|
namespace crash {
|
||||||
|
|
||||||
class B;
|
class B;
|
||||||
|
@ -34,6 +44,11 @@ A::~A() {
|
||||||
_b->virtualFunction();
|
_b->virtualFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only use doAssert() for debug purposes
|
||||||
|
void doAssert(bool value) {
|
||||||
|
assert(value);
|
||||||
|
}
|
||||||
|
|
||||||
void pureVirtualCall() {
|
void pureVirtualCall() {
|
||||||
qCDebug(shared) << "About to make a pure virtual call";
|
qCDebug(shared) << "About to make a pure virtual call";
|
||||||
B b;
|
B b;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
namespace crash {
|
namespace crash {
|
||||||
|
|
||||||
|
void doAssert(bool value); // works for Release
|
||||||
void pureVirtualCall();
|
void pureVirtualCall();
|
||||||
void doubleFree();
|
void doubleFree();
|
||||||
void nullDeref();
|
void nullDeref();
|
||||||
|
|
Loading…
Reference in a new issue