Pass correct position/velocity/orientation to Rig simulation.

This commit is contained in:
Howard Stearns 2015-07-27 12:57:39 -07:00
parent 185f6bef9f
commit 990f0d6d07
4 changed files with 21 additions and 23 deletions

View file

@ -341,17 +341,16 @@ glm::mat4 Rig::getJointVisibleTransform(int jointIndex) const {
return maybeCauterizeHead(jointIndex).getVisibleTransform(); return maybeCauterizeHead(jointIndex).getVisibleTransform();
} }
void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::quat& worldRotation) { void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) {
glm::vec3 front = worldRotation * IDENTITY_FRONT;
glm::vec3 delta = worldPosition - _lastPosition ;
float forwardSpeed = glm::dot(delta, front) / deltaTime;
float rotationalSpeed = glm::angle(front, _lastFront) / deltaTime;
bool isWalking = std::abs(forwardSpeed) > 0.01;
bool isTurning = std::abs(rotationalSpeed) > 0.5;
// Crude, until we have blending: if (_enableRig) {
const float EXPECTED_INTERVAL = 1.0f / 60.0f; glm::vec3 front = worldRotation * IDENTITY_FRONT;
if (deltaTime >= EXPECTED_INTERVAL) { float forwardSpeed = glm::dot(worldVelocity, front);
float rotationalSpeed = glm::angle(front, _lastFront) / deltaTime;
bool isWalking = std::abs(forwardSpeed) > 0.01;
bool isTurning = std::abs(rotationalSpeed) > 0.5;
// Crude, until we have blending:
isTurning = isTurning && !isWalking; // Only one of walk/turn, walk wins. isTurning = isTurning && !isWalking; // Only one of walk/turn, walk wins.
isTurning = false; // FIXME isTurning = false; // FIXME
bool isIdle = !isWalking && !isTurning; bool isIdle = !isWalking && !isTurning;
@ -361,15 +360,12 @@ void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm
QString toStop = singleRole(_isWalking && !isWalking, _isTurning && !isTurning, _isIdle && !isIdle); QString toStop = singleRole(_isWalking && !isWalking, _isTurning && !isTurning, _isIdle && !isIdle);
if (!toStop.isEmpty()) { if (!toStop.isEmpty()) {
//qCDebug(animation) << "isTurning" << isTurning << "fronts" << front << _lastFront << glm::angle(front, _lastFront) << rotationalSpeed; //qCDebug(animation) << "isTurning" << isTurning << "fronts" << front << _lastFront << glm::angle(front, _lastFront) << rotationalSpeed;
//stopAnimationByRole(toStop); stopAnimationByRole(toStop);
} }
QString newRole = singleRole(isWalking && !_isWalking, isTurning && !_isTurning, isIdle && !_isIdle); QString newRole = singleRole(isWalking && !_isWalking, isTurning && !_isTurning, isIdle && !_isIdle);
if (!newRole.isEmpty()) { if (!newRole.isEmpty()) {
//startAnimationByRole(newRole); startAnimationByRole(newRole);
qCDebug(animation) << deltaTime << ":" /*<< _lastPosition << worldPosition << "=>" */<< delta << "." << front << "=> " << forwardSpeed << newRole; qCDebug(animation) << deltaTime << ":" << worldVelocity << "." << front << "=> " << forwardSpeed << newRole;
/*if (newRole == "idle") {
qCDebug(animation) << deltaTime << ":" << _lastPosition << worldPosition << "=>" << delta;
}*/
} }
_lastPosition = worldPosition; _lastPosition = worldPosition;

View file

@ -108,7 +108,7 @@ public:
void setJointTransform(int jointIndex, glm::mat4 newTransform); void setJointTransform(int jointIndex, glm::mat4 newTransform);
glm::mat4 getJointVisibleTransform(int jointIndex) const; glm::mat4 getJointVisibleTransform(int jointIndex) const;
void setJointVisibleTransform(int jointIndex, glm::mat4 newTransform); void setJointVisibleTransform(int jointIndex, glm::mat4 newTransform);
void simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::quat& worldRotation); void simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation);
bool setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation, bool useRotation, bool setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation, bool useRotation,
int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority, int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority,
const QVector<int>& freeLineage, glm::mat4 parentTransform); const QVector<int>& freeLineage, glm::mat4 parentTransform);
@ -132,6 +132,7 @@ public:
virtual bool getIsFirstPerson() const { return _isFirstPerson; } virtual bool getIsFirstPerson() const { return _isFirstPerson; }
bool getJointsAreDirty() { return _jointsAreDirty; } bool getJointsAreDirty() { return _jointsAreDirty; }
bool setEnableRig(bool isEnabled) { _enableRig = isEnabled; }
protected: protected:
QVector<JointState> _jointStates; QVector<JointState> _jointStates;
@ -146,6 +147,7 @@ public:
bool _jointsAreDirty = false; bool _jointsAreDirty = false;
int _neckJointIndex = -1; int _neckJointIndex = -1;
bool _enableRig;
bool _isWalking; bool _isWalking;
bool _isTurning; bool _isTurning;
bool _isIdle; bool _isIdle;

View file

@ -1316,7 +1316,7 @@ void Model::snapToRegistrationPoint() {
_snappedToRegistrationPoint = true; _snappedToRegistrationPoint = true;
} }
void Model::simulate(float deltaTime, bool fullUpdate) { void Model::simulate(float deltaTime, bool fullUpdate, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) {
PROFILE_RANGE(__FUNCTION__); PROFILE_RANGE(__FUNCTION__);
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit) fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit)
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint); || (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint);
@ -1337,16 +1337,16 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
if (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint) { if (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint) {
snapToRegistrationPoint(); snapToRegistrationPoint();
} }
simulateInternal(deltaTime); simulateInternal(deltaTime, worldPosition, worldVelocity, worldRotation);
} }
} }
void Model::simulateInternal(float deltaTime) { void Model::simulateInternal(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) {
// update the world space transforms for all joints // update the world space transforms for all joints
const FBXGeometry& geometry = _geometry->getFBXGeometry(); const FBXGeometry& geometry = _geometry->getFBXGeometry();
glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset; glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
_rig->simulateInternal(deltaTime, parentTransform, getTranslation(), getRotation()); _rig->simulateInternal(deltaTime, parentTransform, worldPosition, worldVelocity, worldRotation);
_shapesAreDirty = !_shapes.isEmpty(); _shapesAreDirty = !_shapes.isEmpty();

View file

@ -117,7 +117,7 @@ public:
void setSnapModelToRegistrationPoint(bool snapModelToRegistrationPoint, const glm::vec3& registrationPoint); void setSnapModelToRegistrationPoint(bool snapModelToRegistrationPoint, const glm::vec3& registrationPoint);
bool getSnapModelToRegistrationPoint() { return _snapModelToRegistrationPoint; } bool getSnapModelToRegistrationPoint() { return _snapModelToRegistrationPoint; }
virtual void simulate(float deltaTime, bool fullUpdate = true); virtual void simulate(float deltaTime, bool fullUpdate = true, const glm::vec3& worldPosition = glm::vec3(), const glm::vec3& worldVelocity = glm::vec3(), const glm::quat& worldRotation = glm::quat());
/// Returns a reference to the shared geometry. /// Returns a reference to the shared geometry.
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; } const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
@ -274,7 +274,7 @@ protected:
void scaleToFit(); void scaleToFit();
void snapToRegistrationPoint(); void snapToRegistrationPoint();
void simulateInternal(float deltaTime); void simulateInternal(float deltaTime, const glm::vec3& worldPosition = glm::vec3(), const glm::vec3& worldVelocity = glm::vec3(), const glm::quat& worldRotation = glm::quat());
/// Updates the state of the joint at the specified index. /// Updates the state of the joint at the specified index.
virtual void updateJointState(int index); virtual void updateJointState(int index);