mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-13 16:13:14 +02:00
make setting of rigid-body velocity controlled by an action argument
This commit is contained in:
parent
99be44f92d
commit
91f5a6fec6
4 changed files with 42 additions and 7 deletions
|
@ -81,18 +81,19 @@ void AvatarActionKinematicHold::updateActionWorker(float deltaTimeStep) {
|
|||
void* physicsInfo = ownerEntity->getPhysicsInfo();
|
||||
if (physicsInfo) {
|
||||
ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
|
||||
btRigidBody* rigidBody = motionState->getRigidBody();
|
||||
btRigidBody* rigidBody = motionState ? motionState->getRigidBody() : nullptr;
|
||||
if (!rigidBody) {
|
||||
qDebug() << "ObjectActionSpring::updateActionWorker no rigidBody";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_previousSet) {
|
||||
glm::vec3 positionalVelocity = (_positionalTarget - _previousPositionalTarget) / deltaTimeStep;
|
||||
rigidBody->setLinearVelocity(glmToBullet(positionalVelocity));
|
||||
|
||||
// back up along velocity a bit in order to smooth out a "vibrating" appearance
|
||||
_positionalTarget -= positionalVelocity * deltaTimeStep / 2.0f;
|
||||
if (_setVelocity) {
|
||||
if (_previousSet) {
|
||||
glm::vec3 positionalVelocity = (_positionalTarget - _previousPositionalTarget) / deltaTimeStep;
|
||||
rigidBody->setLinearVelocity(glmToBullet(positionalVelocity));
|
||||
// back up along velocity a bit in order to smooth out a "vibrating" appearance
|
||||
_positionalTarget -= positionalVelocity * deltaTimeStep / 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
btTransform worldTrans = rigidBody->getWorldTransform();
|
||||
|
@ -140,6 +141,13 @@ bool AvatarActionKinematicHold::updateArguments(QVariantMap arguments) {
|
|||
hand = _hand;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
int setVelocity =
|
||||
EntityActionInterface::extractIntegerArgument("kinematic-hold", arguments, "setVelocity", ok, false);
|
||||
if (!ok) {
|
||||
setVelocity = false;
|
||||
}
|
||||
|
||||
if (relativePosition != _relativePosition
|
||||
|| relativeRotation != _relativeRotation
|
||||
|| hand != _hand) {
|
||||
|
@ -147,6 +155,7 @@ bool AvatarActionKinematicHold::updateArguments(QVariantMap arguments) {
|
|||
_relativePosition = relativePosition;
|
||||
_relativeRotation = relativeRotation;
|
||||
_hand = hand;
|
||||
_setVelocity = setVelocity;
|
||||
|
||||
_mine = true;
|
||||
_active = true;
|
||||
|
|
|
@ -40,6 +40,8 @@ private:
|
|||
bool _previousSet = false;
|
||||
glm::vec3 _previousPositionalTarget;
|
||||
glm::quat _previousRotationalTarget;
|
||||
|
||||
bool _setVelocity = false;
|
||||
};
|
||||
|
||||
#endif // hifi_AvatarActionKinematicHold_h
|
||||
|
|
|
@ -249,6 +249,28 @@ float EntityActionInterface::extractFloatArgument(QString objectName, QVariantMa
|
|||
return v;
|
||||
}
|
||||
|
||||
int EntityActionInterface::extractIntegerArgument(QString objectName, QVariantMap arguments,
|
||||
QString argumentName, bool& ok, bool required) {
|
||||
if (!arguments.contains(argumentName)) {
|
||||
if (required) {
|
||||
qDebug() << objectName << "requires argument:" << argumentName;
|
||||
}
|
||||
ok = false;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
QVariant vV = arguments[argumentName];
|
||||
bool vOk = true;
|
||||
int v = vV.toInt(&vOk);
|
||||
|
||||
if (!vOk || v != v) {
|
||||
ok = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
QString EntityActionInterface::extractStringArgument(QString objectName, QVariantMap arguments,
|
||||
QString argumentName, bool& ok, bool required) {
|
||||
if (!arguments.contains(argumentName)) {
|
||||
|
|
|
@ -70,6 +70,8 @@ protected:
|
|||
QString argumentName, bool& ok, bool required = true);
|
||||
static float extractFloatArgument(QString objectName, QVariantMap arguments,
|
||||
QString argumentName, bool& ok, bool required = true);
|
||||
static int extractIntegerArgument(QString objectName, QVariantMap arguments,
|
||||
QString argumentName, bool& ok, bool required = true);
|
||||
static QString extractStringArgument(QString objectName, QVariantMap arguments,
|
||||
QString argumentName, bool& ok, bool required = true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue