mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
fix up kinematic hold
This commit is contained in:
parent
cf8955a8c5
commit
89c848d8c8
4 changed files with 28 additions and 4 deletions
|
@ -444,7 +444,7 @@ function MyController(hand, triggerAction) {
|
||||||
var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset);
|
var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset);
|
||||||
|
|
||||||
this.actionID = NULL_ACTION_ID;
|
this.actionID = NULL_ACTION_ID;
|
||||||
this.actionID = Entities.addAction("hold", this.grabbedEntity, {
|
this.actionID = Entities.addAction("kinematic-hold", this.grabbedEntity, {
|
||||||
hand: this.hand === RIGHT_HAND ? "right" : "left",
|
hand: this.hand === RIGHT_HAND ? "right" : "left",
|
||||||
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
||||||
relativePosition: offsetPosition,
|
relativePosition: offsetPosition,
|
||||||
|
|
|
@ -22,7 +22,9 @@ AvatarActionKinematicHold::AvatarActionKinematicHold(const QUuid& id, EntityItem
|
||||||
_relativePosition(glm::vec3(0.0f)),
|
_relativePosition(glm::vec3(0.0f)),
|
||||||
_relativeRotation(glm::quat()),
|
_relativeRotation(glm::quat()),
|
||||||
_hand("right"),
|
_hand("right"),
|
||||||
_mine(false)
|
_mine(false),
|
||||||
|
_previousPositionalTarget(Vectors::ZERO),
|
||||||
|
_previousRotationalTarget(Quaternions::IDENTITY)
|
||||||
{
|
{
|
||||||
_type = ACTION_TYPE_HOLD;
|
_type = ACTION_TYPE_HOLD;
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
|
@ -44,6 +46,10 @@ void AvatarActionKinematicHold::updateActionWorker(float deltaTimeStep) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deltaTimeStep <= 0.0f) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 offset;
|
glm::vec3 offset;
|
||||||
|
@ -81,10 +87,24 @@ void AvatarActionKinematicHold::updateActionWorker(float deltaTimeStep) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
btTransform worldTrans;
|
btTransform worldTrans = rigidBody->getWorldTransform();
|
||||||
worldTrans.setOrigin(glmToBullet(_positionalTarget));
|
worldTrans.setOrigin(glmToBullet(_positionalTarget));
|
||||||
worldTrans.setRotation(glmToBullet(_rotationalTarget));
|
worldTrans.setRotation(glmToBullet(_rotationalTarget));
|
||||||
rigidBody->setWorldTransform(worldTrans);
|
rigidBody->setWorldTransform(worldTrans);
|
||||||
|
|
||||||
|
if (_previousSet) {
|
||||||
|
glm::vec3 positionalVelocity = (_positionalTarget - _previousPositionalTarget) / deltaTimeStep;
|
||||||
|
rigidBody->setLinearVelocity(glmToBullet(positionalVelocity));
|
||||||
|
|
||||||
|
glm::quat rotationalDelta = glm::inverse(_previousRotationalTarget) * _rotationalTarget;
|
||||||
|
glm::vec3 rotationalDeltaAxis = glm::axis(rotationalDelta);
|
||||||
|
float rotationalDeltaAngle = glm::angle(rotationalDelta);
|
||||||
|
glm::vec3 rotationalVelocity = glm::normalize(rotationalDeltaAxis) * rotationalDeltaAngle / deltaTimeStep;
|
||||||
|
rigidBody->setAngularVelocity(glmToBullet(rotationalVelocity));
|
||||||
|
}
|
||||||
|
_previousPositionalTarget = _positionalTarget;
|
||||||
|
_previousRotationalTarget = _rotationalTarget;
|
||||||
|
_previousSet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ private:
|
||||||
glm::quat _relativeRotation;
|
glm::quat _relativeRotation;
|
||||||
QString _hand;
|
QString _hand;
|
||||||
bool _mine = false;
|
bool _mine = false;
|
||||||
|
|
||||||
|
bool _previousSet = false;
|
||||||
|
glm::vec3 _previousPositionalTarget;
|
||||||
|
glm::quat _previousRotationalTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarActionKinematicHold_h
|
#endif // hifi_AvatarActionKinematicHold_h
|
||||||
|
|
|
@ -100,7 +100,7 @@ EntityActionType EntityActionInterface::actionTypeFromString(QString actionTypeS
|
||||||
if (normalizedActionTypeString == "hold") {
|
if (normalizedActionTypeString == "hold") {
|
||||||
return ACTION_TYPE_HOLD;
|
return ACTION_TYPE_HOLD;
|
||||||
}
|
}
|
||||||
if (normalizedActionTypeString == "kinematic-hold") {
|
if (normalizedActionTypeString == "kinematichold") {
|
||||||
return ACTION_TYPE_KINEMATIC_HOLD;
|
return ACTION_TYPE_KINEMATIC_HOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue