mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 05:43:36 +02:00
fix activation of object when action changes
This commit is contained in:
parent
9cb7e86877
commit
9ce9c541de
9 changed files with 25 additions and 22 deletions
|
@ -127,7 +127,7 @@ bool AvatarActionHold::updateArguments(QVariantMap arguments) {
|
||||||
|
|
||||||
_mine = true;
|
_mine = true;
|
||||||
_active = true;
|
_active = true;
|
||||||
_needsActivation = true;
|
activateBody();
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1496,7 +1496,7 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act
|
||||||
|
|
||||||
bool result = addActionInternal(simulation, action);
|
bool result = addActionInternal(simulation, action);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
removeAction(simulation, action->getID());
|
removeActionInternal(action->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -1520,6 +1520,7 @@ bool EntityItem::addActionInternal(EntitySimulation* simulation, EntityActionPoi
|
||||||
QByteArray newDataCache = serializeActions(success);
|
QByteArray newDataCache = serializeActions(success);
|
||||||
if (success) {
|
if (success) {
|
||||||
_allActionsDataCache = newDataCache;
|
_allActionsDataCache = newDataCache;
|
||||||
|
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -1537,6 +1538,7 @@ bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionI
|
||||||
bool success = action->updateArguments(arguments);
|
bool success = action->updateArguments(arguments);
|
||||||
if (success) {
|
if (success) {
|
||||||
_allActionsDataCache = serializeActions(success);
|
_allActionsDataCache = serializeActions(success);
|
||||||
|
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "EntityItem::updateAction failed";
|
qDebug() << "EntityItem::updateAction failed";
|
||||||
}
|
}
|
||||||
|
@ -1572,6 +1574,7 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulation* s
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
_allActionsDataCache = serializeActions(success);
|
_allActionsDataCache = serializeActions(success);
|
||||||
|
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1590,6 +1593,7 @@ bool EntityItem::clearActions(EntitySimulation* simulation) {
|
||||||
// empty _serializedActions means no actions for the EntityItem
|
// empty _serializedActions means no actions for the EntityItem
|
||||||
_actionsToRemove.clear();
|
_actionsToRemove.clear();
|
||||||
_allActionsDataCache.clear();
|
_allActionsDataCache.clear();
|
||||||
|
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION;
|
||||||
unlock();
|
unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,6 +543,9 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = actor(simulation, entity);
|
bool success = actor(simulation, entity);
|
||||||
|
if (success) {
|
||||||
|
_entityTree->entityChanged(entity);
|
||||||
|
}
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
|
|
||||||
// transmit the change
|
// transmit the change
|
||||||
|
|
|
@ -129,3 +129,10 @@ void ObjectAction::setAngularVelocity(glm::vec3 angularVelocity) {
|
||||||
rigidBody->activate();
|
rigidBody->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectAction::activateBody() {
|
||||||
|
auto rigidBody = getRigidBody();
|
||||||
|
if (rigidBody) {
|
||||||
|
rigidBody->activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ protected:
|
||||||
virtual void setLinearVelocity(glm::vec3 linearVelocity);
|
virtual void setLinearVelocity(glm::vec3 linearVelocity);
|
||||||
virtual glm::vec3 getAngularVelocity();
|
virtual glm::vec3 getAngularVelocity();
|
||||||
virtual void setAngularVelocity(glm::vec3 angularVelocity);
|
virtual void setAngularVelocity(glm::vec3 angularVelocity);
|
||||||
|
virtual void activateBody();
|
||||||
|
|
||||||
void lockForRead() { _lock.lockForRead(); }
|
void lockForRead() { _lock.lockForRead(); }
|
||||||
bool tryLockForRead() { return _lock.tryLockForRead(); }
|
bool tryLockForRead() { return _lock.tryLockForRead(); }
|
||||||
|
|
|
@ -59,10 +59,6 @@ void ObjectActionOffset::updateActionWorker(btScalar deltaTimeStep) {
|
||||||
|
|
||||||
const float MAX_LINEAR_TIMESCALE = 600.0f; // 10 minutes is a long time
|
const float MAX_LINEAR_TIMESCALE = 600.0f; // 10 minutes is a long time
|
||||||
if (_positionalTargetSet && _linearTimeScale < MAX_LINEAR_TIMESCALE) {
|
if (_positionalTargetSet && _linearTimeScale < MAX_LINEAR_TIMESCALE) {
|
||||||
if (_needsActivation) {
|
|
||||||
rigidBody->activate();
|
|
||||||
_needsActivation = false;
|
|
||||||
}
|
|
||||||
glm::vec3 objectPosition = bulletToGLM(rigidBody->getCenterOfMassPosition());
|
glm::vec3 objectPosition = bulletToGLM(rigidBody->getCenterOfMassPosition());
|
||||||
glm::vec3 springAxis = objectPosition - _pointToOffsetFrom; // from anchor to object
|
glm::vec3 springAxis = objectPosition - _pointToOffsetFrom; // from anchor to object
|
||||||
float distance = glm::length(springAxis);
|
float distance = glm::length(springAxis);
|
||||||
|
@ -122,7 +118,7 @@ bool ObjectActionOffset::updateArguments(QVariantMap arguments) {
|
||||||
_linearDistance = linearDistance;
|
_linearDistance = linearDistance;
|
||||||
_positionalTargetSet = true;
|
_positionalTargetSet = true;
|
||||||
_active = true;
|
_active = true;
|
||||||
_needsActivation = true;
|
activateBody();
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -36,7 +36,6 @@ public:
|
||||||
float _linearDistance;
|
float _linearDistance;
|
||||||
float _linearTimeScale;
|
float _linearTimeScale;
|
||||||
bool _positionalTargetSet;
|
bool _positionalTargetSet;
|
||||||
bool _needsActivation = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ObjectActionOffset_h
|
#endif // hifi_ObjectActionOffset_h
|
||||||
|
|
|
@ -25,8 +25,7 @@ ObjectActionSpring::ObjectActionSpring(const QUuid& id, EntityItemPointer ownerE
|
||||||
_positionalTargetSet(true),
|
_positionalTargetSet(true),
|
||||||
_rotationalTarget(glm::quat()),
|
_rotationalTarget(glm::quat()),
|
||||||
_angularTimeScale(FLT_MAX),
|
_angularTimeScale(FLT_MAX),
|
||||||
_rotationalTargetSet(true),
|
_rotationalTargetSet(true) {
|
||||||
_needsActivation(true) {
|
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "ObjectActionSpring::ObjectActionSpring";
|
qDebug() << "ObjectActionSpring::ObjectActionSpring";
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,10 +66,10 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) {
|
||||||
if (_linearTimeScale < MAX_TIMESCALE) {
|
if (_linearTimeScale < MAX_TIMESCALE) {
|
||||||
btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);
|
btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);
|
||||||
float offsetLength = offset.length();
|
float offsetLength = offset.length();
|
||||||
//float blend = glm::min(1.0f, deltaTimeStep / _linearTimeScale);
|
|
||||||
float blend = 1.0f;
|
|
||||||
float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f;
|
float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f;
|
||||||
rigidBody->setLinearVelocity((1.0f - blend) * rigidBody->getLinearVelocity() - (blend * speed / (offsetLength * _linearTimeScale)) * offset);
|
|
||||||
|
// this action is aggresively critically damped and defeats the current velocity
|
||||||
|
rigidBody->setLinearVelocity((- speed / offsetLength) * offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_angularTimeScale < MAX_TIMESCALE) {
|
if (_angularTimeScale < MAX_TIMESCALE) {
|
||||||
|
@ -98,13 +97,8 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) {
|
||||||
targetVelocity = (angle / _angularTimeScale) * deltaQ.getAxis();
|
targetVelocity = (angle / _angularTimeScale) * deltaQ.getAxis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//float blend = glm::min(1.0f, deltaTimeStep / _angularTimeScale);
|
// this action is aggresively critically damped and defeats the current velocity
|
||||||
float blend = 1.0f;
|
rigidBody->setAngularVelocity(targetVelocity);
|
||||||
rigidBody->setAngularVelocity((1.0f - blend) * rigidBody->getAngularVelocity() + blend * targetVelocity);
|
|
||||||
}
|
|
||||||
if (_needsActivation) {
|
|
||||||
rigidBody->activate();
|
|
||||||
_needsActivation = false;
|
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
@ -151,7 +145,7 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) {
|
||||||
_rotationalTarget = rotationalTarget;
|
_rotationalTarget = rotationalTarget;
|
||||||
_angularTimeScale = glm::max(MIN_TIMESCALE, glm::abs(angularTimeScale));
|
_angularTimeScale = glm::max(MIN_TIMESCALE, glm::abs(angularTimeScale));
|
||||||
_active = true;
|
_active = true;
|
||||||
_needsActivation = true;
|
activateBody();
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -37,7 +37,6 @@ protected:
|
||||||
glm::quat _rotationalTarget;
|
glm::quat _rotationalTarget;
|
||||||
float _angularTimeScale;
|
float _angularTimeScale;
|
||||||
bool _rotationalTargetSet;
|
bool _rotationalTargetSet;
|
||||||
bool _needsActivation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ObjectActionSpring_h
|
#endif // hifi_ObjectActionSpring_h
|
||||||
|
|
Loading…
Reference in a new issue