mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 09:33:29 +02:00
Merge branch 'baseball-test' of github.com:Atlante45/hifi into baseball
This commit is contained in:
commit
c4e43c4e0b
9 changed files with 96 additions and 143 deletions
|
@ -51,10 +51,9 @@
|
|||
var batUserData = {
|
||||
grabbableKey: {
|
||||
spatialKey: {
|
||||
relativePosition: { x: 0.9, y: 0, z: 0 },
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45),
|
||||
perHandRelativePosition: { x: 0.0, y: -0.05, z: -0.04 },
|
||||
perHandRelativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
|
||||
leftRelativePosition: { x: 0.9, y: 0.05, z: -0.05 },
|
||||
rightRelativePosition: { x: 0.9, y: 0.05, z: 0.05 },
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,6 +200,33 @@ function entityIsGrabbedByOther(entityID) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function getSpatialOffsetPosition(hand, spatialKey) {
|
||||
if (hand !== RIGHT_HAND && spatialKey.leftRelativePosition) {
|
||||
return spatialKey.leftRelativePosition;
|
||||
}
|
||||
if (hand === RIGHT_HAND && spatialKey.rightRelativePosition) {
|
||||
return spatialKey.rightRelativePosition;
|
||||
}
|
||||
if (spatialKey.relativePosition) {
|
||||
return spatialKey.relativePosition;
|
||||
}
|
||||
|
||||
return Vec3.ZERO;
|
||||
}
|
||||
|
||||
function getSpatialOffsetRotation(hand, spatialKey) {
|
||||
if (hand !== RIGHT_HAND && spatialKey.leftRelativeRotation) {
|
||||
return spatialKey.leftRelativeRotation;
|
||||
}
|
||||
if (hand === RIGHT_HAND && spatialKey.rightRelativeRotation) {
|
||||
return spatialKey.rightRelativeRotation;
|
||||
}
|
||||
if (spatialKey.relativeRotation) {
|
||||
return spatialKey.relativeRotation;
|
||||
}
|
||||
|
||||
return Quat.IDENTITY;
|
||||
}
|
||||
|
||||
function MyController(hand) {
|
||||
this.hand = hand;
|
||||
|
@ -223,20 +250,11 @@ function MyController(hand) {
|
|||
this.triggerValue = 0; // rolling average of trigger value
|
||||
this.rawTriggerValue = 0;
|
||||
this.rawBumperValue = 0;
|
||||
|
||||
|
||||
this.overlayLine = null;
|
||||
|
||||
this.offsetPosition = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0
|
||||
};
|
||||
this.offsetRotation = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
w: 1.0
|
||||
};
|
||||
|
||||
this.offsetPosition = Vec3.ZERO;
|
||||
this.offsetRotation = Quat.IDENTITY;
|
||||
|
||||
var _this = this;
|
||||
|
||||
|
@ -815,12 +833,8 @@ function MyController(hand) {
|
|||
|
||||
if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) {
|
||||
// if an object is "equipped" and has a spatialKey, use it.
|
||||
if (grabbableData.spatialKey.relativePosition) {
|
||||
this.offsetPosition = grabbableData.spatialKey.relativePosition;
|
||||
}
|
||||
if (grabbableData.spatialKey.relativeRotation) {
|
||||
this.offsetRotation = grabbableData.spatialKey.relativeRotation;
|
||||
}
|
||||
this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
|
||||
this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
|
||||
} else {
|
||||
var objectRotation = grabbedProperties.rotation;
|
||||
this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
||||
|
@ -946,23 +960,8 @@ function MyController(hand) {
|
|||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||
|
||||
// use a spring to pull the object to where it will be when equipped
|
||||
var relativeRotation = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
w: 1.0
|
||||
};
|
||||
var relativePosition = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0
|
||||
};
|
||||
if (grabbableData.spatialKey.relativePosition) {
|
||||
relativePosition = grabbableData.spatialKey.relativePosition;
|
||||
}
|
||||
if (grabbableData.spatialKey.relativeRotation) {
|
||||
relativeRotation = grabbableData.spatialKey.relativeRotation;
|
||||
}
|
||||
var relativeRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
|
||||
var relativePosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
|
||||
var handRotation = this.getHandRotation();
|
||||
var handPosition = this.getHandPosition();
|
||||
var targetRotation = Quat.multiply(handRotation, relativeRotation);
|
||||
|
|
|
@ -67,12 +67,17 @@
|
|||
}
|
||||
|
||||
var BOW_SPATIAL_KEY = {
|
||||
relativePosition: {
|
||||
x: 0,
|
||||
leftRelativePosition: {
|
||||
x: 0.05,
|
||||
y: 0.06,
|
||||
z: 0.11
|
||||
z: -0.05
|
||||
},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90)
|
||||
rightRelativePosition: {
|
||||
x: -0.05,
|
||||
y: 0.06,
|
||||
z: -0.05
|
||||
},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,12 +48,17 @@ var bow = Entities.addEntity({
|
|||
grabbableKey: {
|
||||
invertSolidWhileHeld: true,
|
||||
spatialKey: {
|
||||
relativePosition: {
|
||||
x: 0,
|
||||
leftRelativePosition: {
|
||||
x: 0.05,
|
||||
y: 0.06,
|
||||
z: 0.11
|
||||
z: -0.05
|
||||
},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90)
|
||||
rightRelativePosition: {
|
||||
x: -0.05,
|
||||
y: 0.06,
|
||||
z: -0.05
|
||||
},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -33,64 +33,45 @@ AvatarActionHold::~AvatarActionHold() {
|
|||
}
|
||||
|
||||
std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::vec3& position) {
|
||||
std::shared_ptr<Avatar> holdingAvatar = nullptr;
|
||||
auto avatarManager = DependencyManager::get<AvatarManager>();
|
||||
auto holdingAvatar = std::static_pointer_cast<Avatar>(avatarManager->getAvatarBySessionID(_holderID));
|
||||
|
||||
if (!holdingAvatar) {
|
||||
return holdingAvatar;
|
||||
}
|
||||
|
||||
withTryReadLock([&]{
|
||||
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
|
||||
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
|
||||
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
||||
|
||||
if (holdingAvatar) {
|
||||
bool isRightHand = (_hand == "right");
|
||||
glm::vec3 palmPosition { Vectors::ZERO };
|
||||
glm::quat palmRotation { Quaternions::IDENTITY };
|
||||
|
||||
|
||||
static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y);
|
||||
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 (isRightHand) {
|
||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition();
|
||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation();
|
||||
} else {
|
||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition();
|
||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
|
||||
palmRotation *= yFlip; // Match right hand frame of reference
|
||||
}
|
||||
} else {
|
||||
if (isRightHand) {
|
||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||
} else {
|
||||
palmPosition = holdingAvatar->getLeftPalmPosition();
|
||||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||
palmRotation *= yFlip; // Match right hand frame of reference
|
||||
}
|
||||
}
|
||||
|
||||
rotation = palmRotation * _relativeRotation;
|
||||
position = palmPosition + rotation * _relativePosition;
|
||||
bool isRightHand = (_hand == "right");
|
||||
glm::vec3 palmPosition { Vectors::ZERO };
|
||||
glm::quat palmRotation { Quaternions::IDENTITY };
|
||||
|
||||
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 (isRightHand) {
|
||||
rotation *= _perHandRelativeRotation;
|
||||
position += rotation * _perHandRelativePosition;
|
||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition();
|
||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation();
|
||||
} else {
|
||||
auto mirroredRotation = _perHandRelativeRotation;
|
||||
auto mirroredPosition = _perHandRelativePosition;
|
||||
|
||||
// Mirror along z axis
|
||||
auto eulerAngles = safeEulerAngles(mirroredRotation);
|
||||
eulerAngles.x *= -1;
|
||||
eulerAngles.y *= -1;
|
||||
mirroredRotation = glm::quat(eulerAngles);
|
||||
|
||||
mirroredPosition.z *= -1;
|
||||
|
||||
rotation *= mirroredRotation;
|
||||
position += rotation * mirroredPosition;
|
||||
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition();
|
||||
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
|
||||
}
|
||||
} else {
|
||||
if (isRightHand) {
|
||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||
} else {
|
||||
palmPosition = holdingAvatar->getLeftPalmPosition();
|
||||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isRightHand) {
|
||||
static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y);
|
||||
palmRotation *= yFlip; // Match right hand frame of reference
|
||||
}
|
||||
|
||||
rotation = palmRotation * _relativeRotation;
|
||||
position = palmPosition + rotation * _relativePosition;
|
||||
});
|
||||
|
||||
return holdingAvatar;
|
||||
|
@ -196,8 +177,6 @@ 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;
|
||||
|
@ -213,26 +192,12 @@ 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);
|
||||
|
@ -255,25 +220,17 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
|||
if (!ok) {
|
||||
_kinematic = false;
|
||||
}
|
||||
|
||||
|
||||
ok = true;
|
||||
kinematicSetVelocity = EntityActionInterface::extractBooleanArgument("hold", arguments,
|
||||
"kinematicSetVelocity", ok, false);
|
||||
if (!ok) {
|
||||
_kinematicSetVelocity = false;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
ignoreIK = EntityActionInterface::extractBooleanArgument("hold", arguments, "ignoreIK", ok, false);
|
||||
if (!ok) {
|
||||
_ignoreIK = true;
|
||||
}
|
||||
|
||||
if (somethingChanged ||
|
||||
relativePosition != _relativePosition ||
|
||||
relativeRotation != _relativeRotation ||
|
||||
perHandRelativePosition != _perHandRelativePosition ||
|
||||
perHandRelativeRotation != _perHandRelativeRotation ||
|
||||
timeScale != _linearTimeScale ||
|
||||
hand != _hand ||
|
||||
holderID != _holderID ||
|
||||
|
@ -288,8 +245,6 @@ 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;
|
||||
|
@ -318,8 +273,6 @@ 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;
|
||||
|
@ -341,8 +294,6 @@ QByteArray AvatarActionHold::serialize() const {
|
|||
dataStream << _holderID;
|
||||
dataStream << _relativePosition;
|
||||
dataStream << _relativeRotation;
|
||||
dataStream << _perHandRelativePosition;
|
||||
dataStream << _perHandRelativeRotation;
|
||||
dataStream << _linearTimeScale;
|
||||
dataStream << _hand;
|
||||
|
||||
|
@ -376,8 +327,6 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) {
|
|||
dataStream >> _holderID;
|
||||
dataStream >> _relativePosition;
|
||||
dataStream >> _relativeRotation;
|
||||
dataStream >> _perHandRelativePosition;
|
||||
dataStream >> _perHandRelativeRotation;
|
||||
dataStream >> _linearTimeScale;
|
||||
_angularTimeScale = _linearTimeScale;
|
||||
dataStream >> _hand;
|
||||
|
|
|
@ -38,15 +38,12 @@ public:
|
|||
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position);
|
||||
|
||||
private:
|
||||
void doKinematicUpdate(float deltaTimeStep);
|
||||
|
||||
static const uint16_t holdVersion;
|
||||
|
||||
void doKinematicUpdate(float deltaTimeStep);
|
||||
|
||||
glm::vec3 _relativePosition { 0.0f };
|
||||
glm::quat _relativeRotation;
|
||||
glm::vec3 _perHandRelativePosition { 0.0f };
|
||||
glm::quat _perHandRelativeRotation;
|
||||
|
||||
glm::vec3 _relativePosition { Vectors::ZERO };
|
||||
glm::quat _relativeRotation { Quaternions::IDENTITY };
|
||||
QString _hand { "right" };
|
||||
QUuid _holderID;
|
||||
|
||||
|
|
|
@ -402,7 +402,7 @@ void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) {
|
|||
|
||||
AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) {
|
||||
if (sessionID == _myAvatar->getSessionUUID()) {
|
||||
return std::static_pointer_cast<Avatar>(_myAvatar);
|
||||
return _myAvatar;
|
||||
}
|
||||
|
||||
return findAvatar(sessionID);
|
||||
|
|
|
@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
case PacketType::EntityAdd:
|
||||
case PacketType::EntityEdit:
|
||||
case PacketType::EntityData:
|
||||
return VERSION_ENTITIES_ACTIONS_PER_HAND_OFFSET;
|
||||
return VERSION_ENTITIES_POLYLINE_TEXTURE;
|
||||
case PacketType::AvatarData:
|
||||
case PacketType::BulkAvatarData:
|
||||
default:
|
||||
|
|
|
@ -160,6 +160,5 @@ 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_POLYLINE_TEXTURE = 50;
|
||||
const PacketVersion VERSION_ENTITIES_ACTIONS_PER_HAND_OFFSET = 51;
|
||||
|
||||
#endif // hifi_PacketHeaders_h
|
||||
|
|
Loading…
Reference in a new issue