From 1e10afe762d6d0ce8685de69a00b9d5c2ed27ac2 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 22 Jan 2019 14:14:54 -0800 Subject: [PATCH] Add function for calculating direction in MyAvatar. --- interface/src/avatar/MyAvatar.cpp | 46 ++++++++++++++++++------------- interface/src/avatar/MyAvatar.h | 1 + 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index ef0d16f9f0..5242d52431 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3278,21 +3278,7 @@ static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const floa return scaledSpeed; } -void MyAvatar::updateActionMotor(float deltaTime) { - bool thrustIsPushing = (glm::length2(_thrust) > EPSILON); - bool scriptedMotorIsPushing = (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED) - && _scriptedMotorTimescale < MAX_CHARACTER_MOTOR_TIMESCALE; - _isBeingPushed = thrustIsPushing || scriptedMotorIsPushing; - if (_isPushing || _isBeingPushed) { - // we don't want the motor to brake if a script is pushing the avatar around - // (we assume the avatar is driving itself via script) - _isBraking = false; - } else { - float speed = glm::length(_actionMotorVelocity); - const float MIN_ACTION_BRAKE_SPEED = 0.1f; - _isBraking = _wasPushing || (_isBraking && speed > MIN_ACTION_BRAKE_SPEED); - } - +glm::vec3 MyAvatar::calculateScaledDirection(){ CharacterController::State state = _characterController.getState(); // compute action input @@ -3313,11 +3299,12 @@ void MyAvatar::updateActionMotor(float deltaTime) { } glm::vec3 direction = forward + right; - + // RKNOTE: This may need to be changed later... if (state == CharacterController::State::Hover || - _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { + _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP; + up /= glm::length(up); direction += up; } @@ -3325,13 +3312,34 @@ void MyAvatar::updateActionMotor(float deltaTime) { float directionLength = glm::length(direction); _isPushing = directionLength > EPSILON; - // normalize direction if (_isPushing) { - direction /= directionLength; + direction; } else { direction = Vectors::ZERO; } + return direction; +} + +void MyAvatar::updateActionMotor(float deltaTime) { + bool thrustIsPushing = (glm::length2(_thrust) > EPSILON); + bool scriptedMotorIsPushing = (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED) + && _scriptedMotorTimescale < MAX_CHARACTER_MOTOR_TIMESCALE; + _isBeingPushed = thrustIsPushing || scriptedMotorIsPushing; + if (_isPushing || _isBeingPushed) { + // we don't want the motor to brake if a script is pushing the avatar around + // (we assume the avatar is driving itself via script) + _isBraking = false; + } else { + float speed = glm::length(_actionMotorVelocity); + const float MIN_ACTION_BRAKE_SPEED = 0.1f; + _isBraking = _wasPushing || (_isBraking && speed > MIN_ACTION_BRAKE_SPEED); + } + + CharacterController::State state = _characterController.getState(); + + glm::vec3 direction = calculateScaledDirection(); + 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 diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 16df224aa5..9520fb7cc4 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1772,6 +1772,7 @@ private: // private methods void updateOrientation(float deltaTime); + glm::vec3 calculateScaledDirection(); void updateActionMotor(float deltaTime); void updatePosition(float deltaTime); void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);