mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 20:44:14 +02:00
change how hold action works
This commit is contained in:
parent
ef3775c44d
commit
7c52849740
8 changed files with 188 additions and 127 deletions
|
@ -56,6 +56,7 @@ const float DISPLAYNAME_FADE_TIME = 0.5f;
|
|||
const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME);
|
||||
const float DISPLAYNAME_ALPHA = 1.0f;
|
||||
const float DISPLAYNAME_BACKGROUND_ALPHA = 0.4f;
|
||||
const glm::vec3 HAND_TO_PALM_OFFSET(0.0f, 0.12f, 0.08f);
|
||||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const AvatarSharedPointer& avatar) {
|
||||
|
@ -1167,3 +1168,64 @@ void Avatar::rebuildSkeletonBody() {
|
|||
DependencyManager::get<AvatarManager>()->updateAvatarPhysicsShape(getSessionUUID());
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getLeftPalmPosition() {
|
||||
glm::vec3 leftHandPosition;
|
||||
getSkeletonModel().getLeftHandPosition(leftHandPosition);
|
||||
glm::quat leftRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||
leftHandPosition += HAND_TO_PALM_OFFSET * glm::inverse(leftRotation);
|
||||
return leftHandPosition;
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getLeftPalmVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(LEFT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getLeftPalmAngularVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(LEFT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getRawAngularVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::quat Avatar::getLeftPalmRotation() {
|
||||
glm::quat leftRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||
return leftRotation;
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getRightPalmPosition() {
|
||||
glm::vec3 rightHandPosition;
|
||||
getSkeletonModel().getRightHandPosition(rightHandPosition);
|
||||
glm::quat rightRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||
rightHandPosition += HAND_TO_PALM_OFFSET * glm::inverse(rightRotation);
|
||||
return rightHandPosition;
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getRightPalmVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(RIGHT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getRightPalmAngularVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(RIGHT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getRawAngularVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::quat Avatar::getRightPalmRotation() {
|
||||
glm::quat rightRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||
return rightRotation;
|
||||
}
|
||||
|
|
|
@ -174,6 +174,16 @@ public:
|
|||
void setMotionState(AvatarMotionState* motionState) { _motionState = motionState; }
|
||||
AvatarMotionState* getMotionState() { return _motionState; }
|
||||
|
||||
public slots:
|
||||
glm::vec3 getLeftPalmPosition();
|
||||
glm::vec3 getLeftPalmVelocity();
|
||||
glm::vec3 getLeftPalmAngularVelocity();
|
||||
glm::quat getLeftPalmRotation();
|
||||
glm::vec3 getRightPalmPosition();
|
||||
glm::vec3 getRightPalmVelocity();
|
||||
glm::vec3 getRightPalmAngularVelocity();
|
||||
glm::quat getRightPalmRotation();
|
||||
|
||||
protected:
|
||||
SkeletonModel _skeletonModel;
|
||||
glm::vec3 _skeletonOffset;
|
||||
|
|
|
@ -22,7 +22,7 @@ AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntit
|
|||
_relativePosition(glm::vec3(0.0f)),
|
||||
_relativeRotation(glm::quat()),
|
||||
_hand("right"),
|
||||
_mine(false)
|
||||
_holderID(QUuid())
|
||||
{
|
||||
_type = ACTION_TYPE_HOLD;
|
||||
#if WANT_DEBUG
|
||||
|
@ -37,48 +37,46 @@ AvatarActionHold::~AvatarActionHold() {
|
|||
}
|
||||
|
||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||
if (!_mine) {
|
||||
// if a local script isn't updating this, then we are just getting spring-action data over the wire.
|
||||
// let the super-class handle it.
|
||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||
return;
|
||||
}
|
||||
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
|
||||
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
|
||||
std::shared_ptr<Avatar> holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
||||
|
||||
glm::quat rotation;
|
||||
glm::vec3 position;
|
||||
glm::vec3 offset;
|
||||
bool gotLock = withTryReadLock([&]{
|
||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
glm::vec3 palmPosition;
|
||||
glm::quat palmRotation;
|
||||
if (_hand == "right") {
|
||||
palmPosition = myAvatar->getRightPalmPosition();
|
||||
palmRotation = myAvatar->getRightPalmRotation();
|
||||
} else {
|
||||
palmPosition = myAvatar->getLeftPalmPosition();
|
||||
palmRotation = myAvatar->getLeftPalmRotation();
|
||||
if (holdingAvatar) {
|
||||
glm::quat rotation;
|
||||
glm::vec3 position;
|
||||
glm::vec3 offset;
|
||||
bool gotLock = withTryReadLock([&]{
|
||||
glm::vec3 palmPosition;
|
||||
glm::quat palmRotation;
|
||||
if (_hand == "right") {
|
||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||
} else {
|
||||
palmPosition = holdingAvatar->getLeftPalmPosition();
|
||||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||
}
|
||||
|
||||
rotation = palmRotation * _relativeRotation;
|
||||
offset = rotation * _relativePosition;
|
||||
position = palmPosition + offset;
|
||||
});
|
||||
|
||||
if (gotLock) {
|
||||
gotLock = withTryWriteLock([&]{
|
||||
if (_positionalTarget != position || _rotationalTarget != rotation) {
|
||||
auto ownerEntity = _ownerEntity.lock();
|
||||
if (ownerEntity) {
|
||||
ownerEntity->setActionDataDirty(true);
|
||||
}
|
||||
_positionalTarget = position;
|
||||
_rotationalTarget = rotation;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
rotation = palmRotation * _relativeRotation;
|
||||
offset = rotation * _relativePosition;
|
||||
position = palmPosition + offset;
|
||||
});
|
||||
|
||||
if (gotLock) {
|
||||
gotLock = withTryWriteLock([&]{
|
||||
if (_positionalTarget != position || _rotationalTarget != rotation) {
|
||||
auto ownerEntity = _ownerEntity.lock();
|
||||
if (ownerEntity) {
|
||||
ownerEntity->setActionDataDirty(true);
|
||||
}
|
||||
_positionalTarget = position;
|
||||
_rotationalTarget = rotation;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (gotLock) {
|
||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||
if (gotLock) {
|
||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +98,7 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
if (!ok) {
|
||||
relativeRotation = _relativeRotation;
|
||||
}
|
||||
|
||||
|
||||
ok = true;
|
||||
float timeScale =
|
||||
EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false);
|
||||
|
@ -115,35 +113,46 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
hand = _hand;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
auto holderID = myAvatar->getSessionUUID();
|
||||
QString holderIDString =
|
||||
EntityActionInterface::extractStringArgument("hold", arguments, "hand", ok, false);
|
||||
if (ok) {
|
||||
holderID = QUuid(holderIDString);
|
||||
}
|
||||
|
||||
if (relativePosition != _relativePosition
|
||||
|| relativeRotation != _relativeRotation
|
||||
|| timeScale != _linearTimeScale
|
||||
|| hand != _hand) {
|
||||
|| hand != _hand
|
||||
|| holderID != _holderID) {
|
||||
withWriteLock([&] {
|
||||
_relativePosition = relativePosition;
|
||||
_relativeRotation = relativeRotation;
|
||||
const float MIN_TIMESCALE = 0.1f;
|
||||
_linearTimeScale = glm::min(MIN_TIMESCALE, timeScale);
|
||||
_linearTimeScale = glm::max(MIN_TIMESCALE, timeScale);
|
||||
_angularTimeScale = _linearTimeScale;
|
||||
_hand = hand;
|
||||
_holderID = holderID;
|
||||
|
||||
_mine = true;
|
||||
_active = true;
|
||||
activateBody();
|
||||
|
||||
auto ownerEntity = _ownerEntity.lock();
|
||||
if (ownerEntity) {
|
||||
ownerEntity->setActionDataDirty(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap AvatarActionHold::getArguments() {
|
||||
QVariantMap arguments = ObjectAction::getArguments();
|
||||
withReadLock([&]{
|
||||
if (!_mine) {
|
||||
arguments = ObjectActionSpring::getArguments();
|
||||
return;
|
||||
}
|
||||
|
||||
arguments["holderID"] = _holderID;
|
||||
arguments["relativePosition"] = glmToQMap(_relativePosition);
|
||||
arguments["relativeRotation"] = glmToQMap(_relativeRotation);
|
||||
arguments["timeScale"] = _linearTimeScale;
|
||||
|
@ -152,9 +161,52 @@ QVariantMap AvatarActionHold::getArguments() {
|
|||
return arguments;
|
||||
}
|
||||
|
||||
QByteArray AvatarActionHold::serialize() const {
|
||||
QByteArray serializedActionArguments;
|
||||
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
||||
|
||||
dataStream << ACTION_TYPE_SPRING;
|
||||
dataStream << getID();
|
||||
dataStream << AvatarActionHold::holdVersion;
|
||||
|
||||
dataStream << _holderID;
|
||||
dataStream << _relativePosition;
|
||||
dataStream << _relativeRotation;
|
||||
dataStream << _linearTimeScale;
|
||||
dataStream << _hand;
|
||||
|
||||
dataStream << _expires;
|
||||
dataStream << _tag;
|
||||
|
||||
return serializedActionArguments;
|
||||
}
|
||||
|
||||
void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
||||
if (!_mine) {
|
||||
ObjectActionSpring::deserialize(serializedArguments);
|
||||
QDataStream dataStream(serializedArguments);
|
||||
|
||||
EntityActionType type;
|
||||
dataStream >> type;
|
||||
assert(type == getType());
|
||||
|
||||
QUuid id;
|
||||
dataStream >> id;
|
||||
assert(id == getID());
|
||||
|
||||
uint16_t serializationVersion;
|
||||
dataStream >> serializationVersion;
|
||||
if (serializationVersion != AvatarActionHold::holdVersion) {
|
||||
return;
|
||||
}
|
||||
|
||||
dataStream >> _holderID;
|
||||
dataStream >> _relativePosition;
|
||||
dataStream >> _relativeRotation;
|
||||
dataStream >> _linearTimeScale;
|
||||
_angularTimeScale = _linearTimeScale;
|
||||
dataStream >> _hand;
|
||||
|
||||
dataStream >> _expires;
|
||||
dataStream >> _tag;
|
||||
|
||||
_active = true;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
|
||||
virtual void updateActionWorker(float deltaTimeStep);
|
||||
|
||||
QByteArray serialize() const;
|
||||
virtual void deserialize(QByteArray serializedArguments);
|
||||
|
||||
private:
|
||||
|
@ -35,7 +36,7 @@ private:
|
|||
glm::vec3 _relativePosition;
|
||||
glm::quat _relativeRotation;
|
||||
QString _hand;
|
||||
bool _mine = false;
|
||||
QUuid _holderID;
|
||||
};
|
||||
|
||||
#endif // hifi_AvatarActionHold_h
|
||||
|
|
|
@ -343,3 +343,11 @@ void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) {
|
||||
if (sessionID == _myAvatar->getSessionUUID()) {
|
||||
return std::static_pointer_cast<Avatar>(_myAvatar);
|
||||
}
|
||||
return getAvatarHash()[sessionID];
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ public:
|
|||
void init();
|
||||
|
||||
MyAvatar* getMyAvatar() { return _myAvatar.get(); }
|
||||
|
||||
AvatarSharedPointer getAvatarBySessionID(const QUuid& sessionID);
|
||||
|
||||
void updateMyAvatar(float deltaTime);
|
||||
void updateOtherAvatars(float deltaTime);
|
||||
|
||||
|
|
|
@ -493,70 +493,6 @@ void MyAvatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) {
|
|||
}
|
||||
}
|
||||
|
||||
const glm::vec3 HAND_TO_PALM_OFFSET(0.0f, 0.12f, 0.08f);
|
||||
|
||||
glm::vec3 MyAvatar::getLeftPalmPosition() {
|
||||
glm::vec3 leftHandPosition;
|
||||
getSkeletonModel().getLeftHandPosition(leftHandPosition);
|
||||
glm::quat leftRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||
leftHandPosition += HAND_TO_PALM_OFFSET * glm::inverse(leftRotation);
|
||||
return leftHandPosition;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getLeftPalmVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(LEFT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getLeftPalmAngularVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(LEFT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getRawAngularVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::quat MyAvatar::getLeftPalmRotation() {
|
||||
glm::quat leftRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||
return leftRotation;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getRightPalmPosition() {
|
||||
glm::vec3 rightHandPosition;
|
||||
getSkeletonModel().getRightHandPosition(rightHandPosition);
|
||||
glm::quat rightRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||
rightHandPosition += HAND_TO_PALM_OFFSET * glm::inverse(rightRotation);
|
||||
return rightHandPosition;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getRightPalmVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(RIGHT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getRightPalmAngularVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(RIGHT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getRawAngularVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::quat MyAvatar::getRightPalmRotation() {
|
||||
glm::quat rightRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||
return rightRotation;
|
||||
}
|
||||
|
||||
void MyAvatar::clearReferential() {
|
||||
changeReferential(NULL);
|
||||
}
|
||||
|
|
|
@ -199,15 +199,6 @@ public slots:
|
|||
|
||||
Q_INVOKABLE void updateMotionBehaviorFromMenu();
|
||||
|
||||
glm::vec3 getLeftPalmPosition();
|
||||
glm::vec3 getLeftPalmVelocity();
|
||||
glm::vec3 getLeftPalmAngularVelocity();
|
||||
glm::quat getLeftPalmRotation();
|
||||
glm::vec3 getRightPalmPosition();
|
||||
glm::vec3 getRightPalmVelocity();
|
||||
glm::vec3 getRightPalmAngularVelocity();
|
||||
glm::quat getRightPalmRotation();
|
||||
|
||||
void clearReferential();
|
||||
bool setModelReferential(const QUuid& id);
|
||||
bool setJointReferential(const QUuid& id, int jointIndex);
|
||||
|
|
Loading…
Reference in a new issue