From a418129bea79b5f7cb2e0724305377d7db067258 Mon Sep 17 00:00:00 2001 From: David Back Date: Fri, 23 Feb 2018 15:00:23 -0800 Subject: [PATCH] simplify to just changing timescales --- interface/src/avatar/MyAvatar.cpp | 44 +++++++++++-------------------- interface/src/avatar/MyAvatar.h | 4 +-- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index d5d85b3365..4a58af9378 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1626,7 +1626,6 @@ controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action act void MyAvatar::updateMotors() { _characterController.clearMotors(); glm::quat motorRotation; - glm::quat avatarOrientation = getWorldOrientation(); const float FLYING_MOTOR_TIMESCALE = 0.05f; const float WALKING_MOTOR_TIMESCALE = 0.2f; @@ -1654,10 +1653,11 @@ void MyAvatar::updateMotors() { // we decompose camera's rotation and store the twist part in motorRotation // however, we need to perform the decomposition in the avatar-frame // using the local UP axis and then transform back into world-frame - glm::quat headOrientation = glm::inverse(avatarOrientation) * getMyHead()->getHeadOrientation(); // avatar-frame + glm::quat orientation = getWorldOrientation(); + glm::quat headOrientation = glm::inverse(orientation) * getMyHead()->getHeadOrientation(); // avatar-frame glm::quat liftRotation; swingTwistDecomposition(headOrientation, Vectors::UNIT_Y, liftRotation, motorRotation); - motorRotation = avatarOrientation * motorRotation; + motorRotation = orientation * motorRotation; } if (_isPushing || _isBraking || !_isBeingPushed) { @@ -1669,35 +1669,21 @@ void MyAvatar::updateMotors() { } } if (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED) { + if (_scriptedMotorFrame == SCRIPTED_MOTOR_CAMERA_FRAME) { + motorRotation = getMyHead()->getHeadOrientation() * glm::angleAxis(PI, Vectors::UNIT_Y); + } + else if (_scriptedMotorFrame == SCRIPTED_MOTOR_AVATAR_FRAME) { + motorRotation = getWorldOrientation() * glm::angleAxis(PI, Vectors::UNIT_Y); + } + else { + // world-frame + motorRotation = glm::quat(); + } if (_scriptedMotorMode == SCRIPTED_MOTOR_SIMPLE_MODE) { - if (_scriptedMotorFrame == SCRIPTED_MOTOR_CAMERA_FRAME) { - motorRotation = getMyHead()->getHeadOrientation() * glm::angleAxis(PI, Vectors::UNIT_Y); - } - else if (_scriptedMotorFrame == SCRIPTED_MOTOR_AVATAR_FRAME) { - motorRotation = avatarOrientation * glm::angleAxis(PI, Vectors::UNIT_Y); - } - else { - // world-frame - motorRotation = glm::quat(); - } _characterController.addMotor(_scriptedMotorVelocity, motorRotation, _scriptedMotorTimescale); - } else { + } else { // dynamic mode - glm::vec3 avatarFrameVelocity; - if (_scriptedMotorFrame == SCRIPTED_MOTOR_CAMERA_FRAME) { - // convert camera frame velocity to avatar frame - glm::quat cameraOrientation = qApp->getCamera().getOrientation(); - avatarFrameVelocity = glm::inverse(avatarOrientation) * cameraOrientation * _scriptedMotorVelocity; - } else if (_scriptedMotorFrame == SCRIPTED_MOTOR_WORLD_FRAME) { - // convert world frame velocity to avatar frame - avatarFrameVelocity = glm::inverse(avatarOrientation) * _scriptedMotorVelocity; - } else { - // avatar frame - avatarFrameVelocity = _scriptedMotorVelocity; - } - // dynamic mode for scripted motor uses avatar frame and piggybacks off of the default action motor's timescales - motorRotation = avatarOrientation * glm::angleAxis(PI, Vectors::UNIT_Y); - _characterController.addMotor(avatarFrameVelocity, motorRotation, horizontalMotorTimescale, verticalMotorTimescale); + _characterController.addMotor(_scriptedMotorVelocity, motorRotation, horizontalMotorTimescale, verticalMotorTimescale); } } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 464d94bce7..fa5206e128 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -69,7 +69,7 @@ class MyAvatar : public Avatar { * @property motorTimescale {float} Specifies how quickly the avatar should accelerate to meet the motorVelocity, * smaller values will result in higher acceleration. * @property motorReferenceFrame {string} Reference frame of the motorVelocity, must be one of the following: "avatar", "camera", "world" - * @property motorMode {string} Type of scripted motor behavior, "simple" = unmodified legacy behavior and "dynamic" = same as default motor + * @property motorMode {string} Type of scripted motor behavior, "simple" = use motorTimescale property (default mode) and "dynamic" = use action motor's timescales * @property collisionSoundURL {string} Specifies the sound to play when the avatar experiences a collision. * You can provide a mono or stereo 16-bit WAV file running at either 24 Khz or 48 Khz. * The latter is downsampled by the audio mixer, so all audio effectively plays back at a 24 Khz sample rate. @@ -668,7 +668,7 @@ private: void setScriptedMotorVelocity(const glm::vec3& velocity); void setScriptedMotorTimescale(float timescale); void setScriptedMotorFrame(QString frame); - void setScriptedMotorMode(QString frame); + void setScriptedMotorMode(QString mode); virtual void attach(const QString& modelURL, const QString& jointName = QString(), const glm::vec3& translation = glm::vec3(), const glm::quat& rotation = glm::quat(), float scale = 1.0f, bool isSoft = false,