From 9195d60b719423b203d53d998e790d916a5e2c1b Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 6 Dec 2013 17:45:28 -0800 Subject: [PATCH 1/2] Fix to jerky avatar movement, fix for rotation broken --- interface/src/avatar/Avatar.cpp | 32 +++++++++++++++---------------- interface/src/avatar/Avatar.h | 1 - interface/src/avatar/MyAvatar.cpp | 32 ++++++++++++++++--------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index a9bd4e2f39..cab6e9f1df 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -205,16 +205,25 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { enableHandMovement &= (it->jointID != AVATAR_JOINT_RIGHT_WRIST); } - // update avatar skeleton - _skeleton.update(deltaTime, getOrientation(), _position); - - - // if this is not my avatar, then hand position comes from transmitted data - _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition; - //update the movement of the hand and process handshaking with other avatars... updateHandMovementAndTouching(deltaTime, enableHandMovement); + // use speed and angular velocity to determine walking vs. standing + if (_speed + fabs(_bodyYawDelta) > 0.2) { + _mode = AVATAR_MODE_WALKING; + } else { + _mode = AVATAR_MODE_INTERACTING; + } + + // update position by velocity, and subtract the change added earlier for gravity + _position += _velocity * deltaTime; + + // update avatar skeleton + _skeleton.update(deltaTime, getOrientation(), _position); + + // if this is not my avatar, then hand position comes from transmitted data + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition; + _hand.simulate(deltaTime, false); _skeletonModel.simulate(deltaTime); _head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); @@ -225,15 +234,6 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.simulate(deltaTime, false); - // use speed and angular velocity to determine walking vs. standing - if (_speed + fabs(_bodyYawDelta) > 0.2) { - _mode = AVATAR_MODE_WALKING; - } else { - _mode = AVATAR_MODE_INTERACTING; - } - - // update position by velocity, and subtract the change added earlier for gravity - _position += _velocity * deltaTime; // Zero thrust out now that we've added it to velocity in this frame _thrust = glm::vec3(0, 0, 0); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 2e3f9d001b..c435191a18 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -205,7 +205,6 @@ protected: SkeletonModel _skeletonModel; bool _ballSpringsInitialized; float _bodyYawDelta; - //AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ]; AvatarMode _mode; glm::vec3 _velocity; glm::vec3 _thrust; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 732ca58939..314a70c80f 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -136,10 +136,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { enableHandMovement &= (it->jointID != AVATAR_JOINT_RIGHT_WRIST); } - // update avatar skeleton - _skeleton.update(deltaTime, getOrientation(), _position); - - // update the movement of the hand and process handshaking with other avatars... updateHandMovementAndTouching(deltaTime, enableHandMovement); @@ -172,6 +168,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { _velocity += _thrust * deltaTime; // update body yaw by body yaw delta + printf("bodyYawDelta %.3f\n", _bodyYawDelta); orientation = orientation * glm::quat(glm::radians( glm::vec3(_bodyPitchDelta, _bodyYawDelta, _bodyRollDelta) * deltaTime)); // decay body rotation momentum @@ -209,7 +206,10 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { } else { applyDamping(deltaTime, _velocity, linearDamping, SQUARED_DAMPING_STRENGTH); } - + + // update the euler angles + setOrientation(orientation); + // Compute instantaneous acceleration float forwardAcceleration = glm::length(glm::dot(getBodyFrontDirection(), getVelocity() - oldVelocity)) / deltaTime; const float ACCELERATION_PITCH_DECAY = 0.4f; @@ -243,16 +243,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { } } - _hand.simulate(deltaTime, true); - _skeletonModel.simulate(deltaTime); - _head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); - glm::vec3 headPosition; - _skeletonModel.getHeadPosition(headPosition); - _head.setPosition(headPosition); - _head.setScale(_scale); - _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); - _head.simulate(deltaTime, true); - const float WALKING_SPEED_THRESHOLD = 0.2f; // use speed and angular velocity to determine walking vs. standing if (_speed + fabs(_bodyYawDelta) > WALKING_SPEED_THRESHOLD) { @@ -284,6 +274,18 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { _position += _velocity * deltaTime; + // update avatar skeleton and simulate hand and head + _skeleton.update(deltaTime, getOrientation(), _position); + _hand.simulate(deltaTime, true); + _skeletonModel.simulate(deltaTime); + _head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); + glm::vec3 headPosition; + _skeletonModel.getHeadPosition(headPosition); + _head.setPosition(headPosition); + _head.setScale(_scale); + _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); + _head.simulate(deltaTime, true); + // Zero thrust out now that we've added it to velocity in this frame _thrust = glm::vec3(0, 0, 0); From 4edb7decdf3f09f4c3601faa47c9e44b8576ea1c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 6 Dec 2013 17:47:01 -0800 Subject: [PATCH 2/2] removed printf --- interface/src/avatar/MyAvatar.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 314a70c80f..c65c6d50a3 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -168,7 +168,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { _velocity += _thrust * deltaTime; // update body yaw by body yaw delta - printf("bodyYawDelta %.3f\n", _bodyYawDelta); orientation = orientation * glm::quat(glm::radians( glm::vec3(_bodyPitchDelta, _bodyYawDelta, _bodyRollDelta) * deltaTime)); // decay body rotation momentum