mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:00:18 +02:00
MyAvatar is unmovable until physics is enabled
This commit is contained in:
parent
5a4960b300
commit
e50892b3d2
2 changed files with 26 additions and 35 deletions
|
@ -847,6 +847,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 +3324,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 +3350,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 +3376,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();
|
||||||
|
|
Loading…
Reference in a new issue