Make _rotation extraction asynchronous by default in computeTransform

This commit is contained in:
Atlante45 2014-07-29 15:55:47 -07:00
parent 897481d557
commit 7800ffbf2e
2 changed files with 32 additions and 4 deletions

View file

@ -11,8 +11,9 @@
#include <glm/gtx/norm.hpp>
#include <QThreadPool>
#include <AngularConstraint.h>
//#include <GeometryUtil.h>
#include <SharedUtil.h>
#include "JointState.h"
@ -93,7 +94,7 @@ void JointState::initTransform(const glm::mat4& parentTransform) {
_distanceToParent = glm::length(_positionInParentFrame);
}
void JointState::computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged) {
void JointState::computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged, bool synchronousRotationCompute) {
if (!parentTransformChanged && !_transformChanged) {
return;
}
@ -104,7 +105,11 @@ void JointState::computeTransform(const glm::mat4& parentTransform, bool parentT
if (newTransform != _transform) {
_transform = newTransform;
_rotation = extractRotation(_transform);
if (synchronousRotationCompute) {
_rotation = extractRotation(_transform);
} else {
QThreadPool::globalInstance()->start(new RotationExtractor(_transform, _rotation));
}
_transformChanged = true;
}
}
@ -253,3 +258,24 @@ void JointState::slaveVisibleTransform() {
_visibleRotation = _rotation;
_visibleRotationInConstrainedFrame = _rotationInConstrainedFrame;
}
class RotationExtractor : public QRunnable {
public:
RotationExtractor(glm::mat4 transform, glm::quat& rotation);
virtual void run();
private:
glm::mat4 _transform;
glm::quat _rotation;
};
RotationExtractor::RotationExtractor(glm::mat4 transform, glm::quat& rotation) {
_transform = transform;
_rotation = rotation;
}
void RotationExtractor::run() {
_rotation = extractRotation(_transform);
}

View file

@ -33,7 +33,9 @@ public:
void copyState(const JointState& state);
void initTransform(const glm::mat4& parentTransform);
void computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged = true);
// if synchronousRotationCompute is true, then _transform is still computed synchronously,
// but _rotation will be asynchronously extracted
void computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged = true, bool synchronousRotationCompute = false);
void computeVisibleTransform(const glm::mat4& parentTransform);
const glm::mat4& getVisibleTransform() const { return _visibleTransform; }