mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Pass correct position/velocity/orientation to Rig simulation.
This commit is contained in:
parent
185f6bef9f
commit
990f0d6d07
4 changed files with 21 additions and 23 deletions
|
@ -341,17 +341,16 @@ glm::mat4 Rig::getJointVisibleTransform(int jointIndex) const {
|
|||
return maybeCauterizeHead(jointIndex).getVisibleTransform();
|
||||
}
|
||||
|
||||
void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, 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;
|
||||
void Rig::simulateInternal(float deltaTime, glm::mat4 parentTransform, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) {
|
||||
|
||||
// Crude, until we have blending:
|
||||
const float EXPECTED_INTERVAL = 1.0f / 60.0f;
|
||||
if (deltaTime >= EXPECTED_INTERVAL) {
|
||||
if (_enableRig) {
|
||||
glm::vec3 front = worldRotation * IDENTITY_FRONT;
|
||||
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 = false; // FIXME
|
||||
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);
|
||||
if (!toStop.isEmpty()) {
|
||||
//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);
|
||||
if (!newRole.isEmpty()) {
|
||||
//startAnimationByRole(newRole);
|
||||
qCDebug(animation) << deltaTime << ":" /*<< _lastPosition << worldPosition << "=>" */<< delta << "." << front << "=> " << forwardSpeed << newRole;
|
||||
/*if (newRole == "idle") {
|
||||
qCDebug(animation) << deltaTime << ":" << _lastPosition << worldPosition << "=>" << delta;
|
||||
}*/
|
||||
startAnimationByRole(newRole);
|
||||
qCDebug(animation) << deltaTime << ":" << worldVelocity << "." << front << "=> " << forwardSpeed << newRole;
|
||||
}
|
||||
|
||||
_lastPosition = worldPosition;
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
void setJointTransform(int jointIndex, glm::mat4 newTransform);
|
||||
glm::mat4 getJointVisibleTransform(int jointIndex) const;
|
||||
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,
|
||||
int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority,
|
||||
const QVector<int>& freeLineage, glm::mat4 parentTransform);
|
||||
|
@ -132,6 +132,7 @@ public:
|
|||
virtual bool getIsFirstPerson() const { return _isFirstPerson; }
|
||||
|
||||
bool getJointsAreDirty() { return _jointsAreDirty; }
|
||||
bool setEnableRig(bool isEnabled) { _enableRig = isEnabled; }
|
||||
|
||||
protected:
|
||||
QVector<JointState> _jointStates;
|
||||
|
@ -146,6 +147,7 @@ public:
|
|||
bool _jointsAreDirty = false;
|
||||
int _neckJointIndex = -1;
|
||||
|
||||
bool _enableRig;
|
||||
bool _isWalking;
|
||||
bool _isTurning;
|
||||
bool _isIdle;
|
||||
|
|
|
@ -1316,7 +1316,7 @@ void Model::snapToRegistrationPoint() {
|
|||
_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__);
|
||||
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit)
|
||||
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint);
|
||||
|
@ -1337,16 +1337,16 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
|||
if (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint) {
|
||||
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
|
||||
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
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();
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ public:
|
|||
void setSnapModelToRegistrationPoint(bool snapModelToRegistrationPoint, const glm::vec3& registrationPoint);
|
||||
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.
|
||||
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
|
||||
|
@ -274,7 +274,7 @@ protected:
|
|||
void scaleToFit();
|
||||
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.
|
||||
virtual void updateJointState(int index);
|
||||
|
|
Loading…
Reference in a new issue