mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 22:45:17 +02:00
AvatarActionHold can ignore IK
This commit is contained in:
parent
8da8b4db8c
commit
d79221edd2
4 changed files with 54 additions and 41 deletions
|
@ -45,13 +45,14 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
|||
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
||||
|
||||
if (holdingAvatar) {
|
||||
bool isRightHand = (_hand == "right");
|
||||
glm::vec3 palmPosition;
|
||||
glm::quat palmRotation;
|
||||
|
||||
if (_ignoreIK && holdingAvatar->isMyAvatar()) {
|
||||
// We cannot ignore other avatars IK and this is not the point of this option
|
||||
// This is meant to make the grabbing behavior more reactive.
|
||||
if (_hand == "right") {
|
||||
if (isRightHand) {
|
||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition();
|
||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation();
|
||||
} else {
|
||||
|
@ -59,7 +60,7 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
|||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
|
||||
}
|
||||
} else {
|
||||
if (_hand == "right") {
|
||||
if (isRightHand) {
|
||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||
} else {
|
||||
|
@ -67,44 +68,26 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
|||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||
}
|
||||
}
|
||||
/*
|
||||
static const float CONTROLLER_LENGTH_OFFSET = 0.0762f; // three inches
|
||||
static const glm::vec3 CONTROLLER_OFFSET = glm::vec3(CONTROLLER_LENGTH_OFFSET / 2.0f,
|
||||
CONTROLLER_LENGTH_OFFSET / 2.0f,
|
||||
CONTROLLER_LENGTH_OFFSET * 2.0f);
|
||||
static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y);
|
||||
static const glm::quat quarterX = glm::angleAxis(PI_OVER_TWO, Vectors::UNIT_X);
|
||||
static const glm::quat viveToHand = yFlip * quarterX;
|
||||
|
||||
static const glm::quat leftQuaterZ = glm::angleAxis(-PI_OVER_TWO, Vectors::UNIT_Z);
|
||||
static const glm::quat rightQuaterZ = glm::angleAxis(PI_OVER_TWO, Vectors::UNIT_Z);
|
||||
static const glm::quat eighthX = glm::angleAxis(PI / 4.0f, Vectors::UNIT_X);
|
||||
|
||||
static const glm::quat leftRotationOffset = glm::inverse(leftQuaterZ * eighthX) * viveToHand;
|
||||
static const glm::quat rightRotationOffset = glm::inverse(rightQuaterZ * eighthX) * viveToHand;
|
||||
|
||||
static const glm::vec3 leftTranslationOffset = glm::vec3(-1.0f, 1.0f, 1.0f) * CONTROLLER_OFFSET;
|
||||
static const glm::vec3 rightTranslationOffset = CONTROLLER_OFFSET;
|
||||
|
||||
glm::quat relRot = glm::inverse(rightRotationOffset);
|
||||
glm::vec3 relPos = -rightTranslationOffset;
|
||||
relRot = palmRotation * relRot;
|
||||
relPos = palmPosition + relRot * relPos;
|
||||
|
||||
rotation = relRot * _relativeRotation;
|
||||
position = relPos + rotation * _relativePosition;
|
||||
glm::quat diffRot = glm::inverse(palmRotation) * rotation;
|
||||
glm::vec3 diffPos = glm::inverse(rotation) * (position - palmPosition);
|
||||
qDebug() << "diffRot =" << safeEulerAngles(diffRot);
|
||||
qDebug() << "diffPos =" << diffPos;
|
||||
*/
|
||||
//[11 / 09 17:40 : 14] [DEBUG] diffRot = { type = 'glm::vec3', x = 3.14159, y = 9.04283e-09, z = 0.785398 }
|
||||
//[11 / 09 17:40 : 14][DEBUG] diffPos = { type = 'glm::vec3', x = 1.0524, y = -0.0381001, z = -0.0380997 }
|
||||
//_relativeRotation = glm::quat(glm::vec3(3.14159f, 0.0f, 0.785398));
|
||||
//_relativePosition = glm::vec3(1.0524, -0.0381001, -0.0380997);
|
||||
|
||||
rotation = palmRotation * _relativeRotation;
|
||||
position = palmPosition + rotation * _relativePosition;
|
||||
if (isRightHand) {
|
||||
rotation = palmRotation * _perHandRelativeRotation;
|
||||
position = palmPosition + rotation * _perHandRelativePosition;
|
||||
} else {
|
||||
auto mirroredRotation = _perHandRelativeRotation;
|
||||
auto mirroredPosition = _perHandRelativePosition;
|
||||
|
||||
// Mirror along z axis
|
||||
mirroredRotation.z *= -1;
|
||||
mirroredRotation.w *= -1;
|
||||
|
||||
mirroredPosition.z *= -1;
|
||||
|
||||
rotation = palmRotation * mirroredRotation;
|
||||
position = palmPosition + rotation * mirroredPosition;
|
||||
}
|
||||
|
||||
rotation = rotation * _relativeRotation;
|
||||
position = position + rotation * _relativePosition;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -175,6 +158,8 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
|
|||
bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||
glm::vec3 relativePosition;
|
||||
glm::quat relativeRotation;
|
||||
glm::vec3 perHandRelativePosition;
|
||||
glm::quat perHandRelativeRotation;
|
||||
float timeScale;
|
||||
QString hand;
|
||||
QUuid holderID;
|
||||
|
@ -190,12 +175,26 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
if (!ok) {
|
||||
relativePosition = _relativePosition;
|
||||
}
|
||||
|
||||
|
||||
ok = true;
|
||||
relativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false);
|
||||
if (!ok) {
|
||||
relativeRotation = _relativeRotation;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
perHandRelativePosition = EntityActionInterface::extractVec3Argument("hold", arguments,
|
||||
"perHandRelativePosition", ok, false);
|
||||
if (!ok) {
|
||||
perHandRelativePosition = _perHandRelativePosition;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
perHandRelativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments,
|
||||
"perHandRelativeRotation", ok, false);
|
||||
if (!ok) {
|
||||
perHandRelativeRotation = _perHandRelativeRotation;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
timeScale = EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false);
|
||||
|
@ -235,6 +234,8 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
if (somethingChanged ||
|
||||
relativePosition != _relativePosition ||
|
||||
relativeRotation != _relativeRotation ||
|
||||
perHandRelativePosition != _perHandRelativePosition ||
|
||||
perHandRelativeRotation != _perHandRelativeRotation ||
|
||||
timeScale != _linearTimeScale ||
|
||||
hand != _hand ||
|
||||
holderID != _holderID ||
|
||||
|
@ -249,6 +250,8 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
withWriteLock([&] {
|
||||
_relativePosition = relativePosition;
|
||||
_relativeRotation = relativeRotation;
|
||||
_perHandRelativePosition = perHandRelativePosition;
|
||||
_perHandRelativeRotation = perHandRelativeRotation;
|
||||
const float MIN_TIMESCALE = 0.1f;
|
||||
_linearTimeScale = glm::max(MIN_TIMESCALE, timeScale);
|
||||
_angularTimeScale = _linearTimeScale;
|
||||
|
@ -276,6 +279,8 @@ QVariantMap AvatarActionHold::getArguments() {
|
|||
arguments["holderID"] = _holderID;
|
||||
arguments["relativePosition"] = glmToQMap(_relativePosition);
|
||||
arguments["relativeRotation"] = glmToQMap(_relativeRotation);
|
||||
arguments["perHandRelativePosition"] = glmToQMap(_perHandRelativePosition);
|
||||
arguments["perHandRelativeRotation"] = glmToQMap(_perHandRelativeRotation);
|
||||
arguments["timeScale"] = _linearTimeScale;
|
||||
arguments["hand"] = _hand;
|
||||
arguments["kinematic"] = _kinematic;
|
||||
|
@ -297,6 +302,8 @@ QByteArray AvatarActionHold::serialize() const {
|
|||
dataStream << _holderID;
|
||||
dataStream << _relativePosition;
|
||||
dataStream << _relativeRotation;
|
||||
dataStream << _perHandRelativePosition;
|
||||
dataStream << _perHandRelativeRotation;
|
||||
dataStream << _linearTimeScale;
|
||||
dataStream << _hand;
|
||||
|
||||
|
@ -330,6 +337,8 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
|||
dataStream >> _holderID;
|
||||
dataStream >> _relativePosition;
|
||||
dataStream >> _relativeRotation;
|
||||
dataStream >> _perHandRelativePosition;
|
||||
dataStream >> _perHandRelativeRotation;
|
||||
dataStream >> _linearTimeScale;
|
||||
_angularTimeScale = _linearTimeScale;
|
||||
dataStream >> _hand;
|
||||
|
|
|
@ -39,6 +39,9 @@ private:
|
|||
|
||||
glm::vec3 _relativePosition { 0.0f };
|
||||
glm::quat _relativeRotation;
|
||||
glm::vec3 _perHandRelativePosition { 0.0f };
|
||||
glm::quat _perHandRelativeRotation;
|
||||
|
||||
QString _hand { "right" };
|
||||
QUuid _holderID;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
case PacketType::EntityAdd:
|
||||
case PacketType::EntityEdit:
|
||||
case PacketType::EntityData:
|
||||
return VERSION_ENTITIES_PARTICLES_ADDITIVE_BLENDING;
|
||||
return VERSION_ENTITIES_ACTIONS_IGNORE_IK;
|
||||
case PacketType::AvatarData:
|
||||
case PacketType::BulkAvatarData:
|
||||
default:
|
||||
|
|
|
@ -146,5 +146,6 @@ const PacketVersion VERSION_ENTITIES_ANIMATION_PROPERTIES_GROUP = 46;
|
|||
const PacketVersion VERSION_ENTITIES_KEYLIGHT_PROPERTIES_GROUP = 47;
|
||||
const PacketVersion VERSION_ENTITIES_KEYLIGHT_PROPERTIES_GROUP_BIS = 48;
|
||||
const PacketVersion VERSION_ENTITIES_PARTICLES_ADDITIVE_BLENDING = 49;
|
||||
const PacketVersion VERSION_ENTITIES_ACTIONS_IGNORE_IK = 50;
|
||||
|
||||
#endif // hifi_PacketHeaders_h
|
||||
|
|
Loading…
Reference in a new issue