Merge branch 'baseball-test' of github.com:Atlante45/hifi into baseball

This commit is contained in:
Atlante45 2015-12-01 15:16:05 -08:00
commit c4e43c4e0b
9 changed files with 96 additions and 143 deletions

View file

@ -51,10 +51,9 @@
var batUserData = { var batUserData = {
grabbableKey: { grabbableKey: {
spatialKey: { spatialKey: {
relativePosition: { x: 0.9, y: 0, z: 0 }, leftRelativePosition: { x: 0.9, y: 0.05, z: -0.05 },
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45), rightRelativePosition: { x: 0.9, y: 0.05, z: 0.05 },
perHandRelativePosition: { x: 0.0, y: -0.05, z: -0.04 }, relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45)
perHandRelativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
} }
} }
} }

View file

@ -200,6 +200,33 @@ function entityIsGrabbedByOther(entityID) {
return false; 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) { function MyController(hand) {
this.hand = hand; this.hand = hand;
@ -223,20 +250,11 @@ function MyController(hand) {
this.triggerValue = 0; // rolling average of trigger value this.triggerValue = 0; // rolling average of trigger value
this.rawTriggerValue = 0; this.rawTriggerValue = 0;
this.rawBumperValue = 0; this.rawBumperValue = 0;
this.overlayLine = null; this.overlayLine = null;
this.offsetPosition = { this.offsetPosition = Vec3.ZERO;
x: 0.0, this.offsetRotation = Quat.IDENTITY;
y: 0.0,
z: 0.0
};
this.offsetRotation = {
x: 0.0,
y: 0.0,
z: 0.0,
w: 1.0
};
var _this = this; var _this = this;
@ -815,12 +833,8 @@ function MyController(hand) {
if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) { if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) {
// if an object is "equipped" and has a spatialKey, use it. // if an object is "equipped" and has a spatialKey, use it.
if (grabbableData.spatialKey.relativePosition) { this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
this.offsetPosition = grabbableData.spatialKey.relativePosition; this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
}
if (grabbableData.spatialKey.relativeRotation) {
this.offsetRotation = grabbableData.spatialKey.relativeRotation;
}
} else { } else {
var objectRotation = grabbedProperties.rotation; var objectRotation = grabbedProperties.rotation;
this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); 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); 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 // use a spring to pull the object to where it will be when equipped
var relativeRotation = { var relativeRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
x: 0.0, var relativePosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
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 handRotation = this.getHandRotation(); var handRotation = this.getHandRotation();
var handPosition = this.getHandPosition(); var handPosition = this.getHandPosition();
var targetRotation = Quat.multiply(handRotation, relativeRotation); var targetRotation = Quat.multiply(handRotation, relativeRotation);

View file

@ -67,12 +67,17 @@
} }
var BOW_SPATIAL_KEY = { var BOW_SPATIAL_KEY = {
relativePosition: { leftRelativePosition: {
x: 0, x: 0.05,
y: 0.06, 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)
} }

View file

@ -48,12 +48,17 @@ var bow = Entities.addEntity({
grabbableKey: { grabbableKey: {
invertSolidWhileHeld: true, invertSolidWhileHeld: true,
spatialKey: { spatialKey: {
relativePosition: { leftRelativePosition: {
x: 0, x: 0.05,
y: 0.06, 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)
} }
} }
}) })

View file

@ -33,64 +33,45 @@ AvatarActionHold::~AvatarActionHold() {
} }
std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::vec3& position) { 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([&]{ withTryReadLock([&]{
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>(); bool isRightHand = (_hand == "right");
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID); glm::vec3 palmPosition { Vectors::ZERO };
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData); glm::quat palmRotation { Quaternions::IDENTITY };
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;
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) { if (isRightHand) {
rotation *= _perHandRelativeRotation; palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getPosition();
position += rotation * _perHandRelativePosition; palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::RightHand).getRotation();
} else { } else {
auto mirroredRotation = _perHandRelativeRotation; palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition();
auto mirroredPosition = _perHandRelativePosition; palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
}
// Mirror along z axis } else {
auto eulerAngles = safeEulerAngles(mirroredRotation); if (isRightHand) {
eulerAngles.x *= -1; palmPosition = holdingAvatar->getRightPalmPosition();
eulerAngles.y *= -1; palmRotation = holdingAvatar->getRightPalmRotation();
mirroredRotation = glm::quat(eulerAngles); } else {
palmPosition = holdingAvatar->getLeftPalmPosition();
mirroredPosition.z *= -1; palmRotation = holdingAvatar->getLeftPalmRotation();
rotation *= mirroredRotation;
position += rotation * mirroredPosition;
} }
} }
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; return holdingAvatar;
@ -196,8 +177,6 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
bool AvatarActionHold::updateArguments(QVariantMap arguments) { bool AvatarActionHold::updateArguments(QVariantMap arguments) {
glm::vec3 relativePosition; glm::vec3 relativePosition;
glm::quat relativeRotation; glm::quat relativeRotation;
glm::vec3 perHandRelativePosition;
glm::quat perHandRelativeRotation;
float timeScale; float timeScale;
QString hand; QString hand;
QUuid holderID; QUuid holderID;
@ -213,26 +192,12 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
if (!ok) { if (!ok) {
relativePosition = _relativePosition; relativePosition = _relativePosition;
} }
ok = true; ok = true;
relativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false); relativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false);
if (!ok) { if (!ok) {
relativeRotation = _relativeRotation; 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; ok = true;
timeScale = EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false); timeScale = EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false);
@ -255,25 +220,17 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
if (!ok) { if (!ok) {
_kinematic = false; _kinematic = false;
} }
ok = true; ok = true;
kinematicSetVelocity = EntityActionInterface::extractBooleanArgument("hold", arguments, kinematicSetVelocity = EntityActionInterface::extractBooleanArgument("hold", arguments,
"kinematicSetVelocity", ok, false); "kinematicSetVelocity", ok, false);
if (!ok) { if (!ok) {
_kinematicSetVelocity = false; _kinematicSetVelocity = false;
} }
ok = true;
ignoreIK = EntityActionInterface::extractBooleanArgument("hold", arguments, "ignoreIK", ok, false);
if (!ok) {
_ignoreIK = true;
}
if (somethingChanged || if (somethingChanged ||
relativePosition != _relativePosition || relativePosition != _relativePosition ||
relativeRotation != _relativeRotation || relativeRotation != _relativeRotation ||
perHandRelativePosition != _perHandRelativePosition ||
perHandRelativeRotation != _perHandRelativeRotation ||
timeScale != _linearTimeScale || timeScale != _linearTimeScale ||
hand != _hand || hand != _hand ||
holderID != _holderID || holderID != _holderID ||
@ -288,8 +245,6 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
withWriteLock([&] { withWriteLock([&] {
_relativePosition = relativePosition; _relativePosition = relativePosition;
_relativeRotation = relativeRotation; _relativeRotation = relativeRotation;
_perHandRelativePosition = perHandRelativePosition;
_perHandRelativeRotation = perHandRelativeRotation;
const float MIN_TIMESCALE = 0.1f; const float MIN_TIMESCALE = 0.1f;
_linearTimeScale = glm::max(MIN_TIMESCALE, timeScale); _linearTimeScale = glm::max(MIN_TIMESCALE, timeScale);
_angularTimeScale = _linearTimeScale; _angularTimeScale = _linearTimeScale;
@ -318,8 +273,6 @@ QVariantMap AvatarActionHold::getArguments() {
arguments["holderID"] = _holderID; arguments["holderID"] = _holderID;
arguments["relativePosition"] = glmToQMap(_relativePosition); arguments["relativePosition"] = glmToQMap(_relativePosition);
arguments["relativeRotation"] = glmToQMap(_relativeRotation); arguments["relativeRotation"] = glmToQMap(_relativeRotation);
arguments["perHandRelativePosition"] = glmToQMap(_perHandRelativePosition);
arguments["perHandRelativeRotation"] = glmToQMap(_perHandRelativeRotation);
arguments["timeScale"] = _linearTimeScale; arguments["timeScale"] = _linearTimeScale;
arguments["hand"] = _hand; arguments["hand"] = _hand;
arguments["kinematic"] = _kinematic; arguments["kinematic"] = _kinematic;
@ -341,8 +294,6 @@ QByteArray AvatarActionHold::serialize() const {
dataStream << _holderID; dataStream << _holderID;
dataStream << _relativePosition; dataStream << _relativePosition;
dataStream << _relativeRotation; dataStream << _relativeRotation;
dataStream << _perHandRelativePosition;
dataStream << _perHandRelativeRotation;
dataStream << _linearTimeScale; dataStream << _linearTimeScale;
dataStream << _hand; dataStream << _hand;
@ -376,8 +327,6 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) {
dataStream >> _holderID; dataStream >> _holderID;
dataStream >> _relativePosition; dataStream >> _relativePosition;
dataStream >> _relativeRotation; dataStream >> _relativeRotation;
dataStream >> _perHandRelativePosition;
dataStream >> _perHandRelativeRotation;
dataStream >> _linearTimeScale; dataStream >> _linearTimeScale;
_angularTimeScale = _linearTimeScale; _angularTimeScale = _linearTimeScale;
dataStream >> _hand; dataStream >> _hand;

View file

@ -38,15 +38,12 @@ public:
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position); std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position);
private: private:
void doKinematicUpdate(float deltaTimeStep);
static const uint16_t holdVersion; static const uint16_t holdVersion;
void doKinematicUpdate(float deltaTimeStep); glm::vec3 _relativePosition { Vectors::ZERO };
glm::quat _relativeRotation { Quaternions::IDENTITY };
glm::vec3 _relativePosition { 0.0f };
glm::quat _relativeRotation;
glm::vec3 _perHandRelativePosition { 0.0f };
glm::quat _perHandRelativeRotation;
QString _hand { "right" }; QString _hand { "right" };
QUuid _holderID; QUuid _holderID;

View file

@ -402,7 +402,7 @@ void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) {
AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) { AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) {
if (sessionID == _myAvatar->getSessionUUID()) { if (sessionID == _myAvatar->getSessionUUID()) {
return std::static_pointer_cast<Avatar>(_myAvatar); return _myAvatar;
} }
return findAvatar(sessionID); return findAvatar(sessionID);

View file

@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
case PacketType::EntityAdd: case PacketType::EntityAdd:
case PacketType::EntityEdit: case PacketType::EntityEdit:
case PacketType::EntityData: case PacketType::EntityData:
return VERSION_ENTITIES_ACTIONS_PER_HAND_OFFSET; return VERSION_ENTITIES_POLYLINE_TEXTURE;
case PacketType::AvatarData: case PacketType::AvatarData:
case PacketType::BulkAvatarData: case PacketType::BulkAvatarData:
default: default:

View file

@ -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_KEYLIGHT_PROPERTIES_GROUP_BIS = 48;
const PacketVersion VERSION_ENTITIES_PARTICLES_ADDITIVE_BLENDING = 49; const PacketVersion VERSION_ENTITIES_PARTICLES_ADDITIVE_BLENDING = 49;
const PacketVersion VERSION_ENTITIES_POLYLINE_TEXTURE = 50; const PacketVersion VERSION_ENTITIES_POLYLINE_TEXTURE = 50;
const PacketVersion VERSION_ENTITIES_ACTIONS_PER_HAND_OFFSET = 51;
#endif // hifi_PacketHeaders_h #endif // hifi_PacketHeaders_h