From 7800ffbf2eb6263923064bbe0bf700198e06b743 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 29 Jul 2014 15:55:47 -0700 Subject: [PATCH] Make _rotation extraction asynchronous by default in computeTransform --- interface/src/renderer/JointState.cpp | 32 ++++++++++++++++++++++++--- interface/src/renderer/JointState.h | 4 +++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/interface/src/renderer/JointState.cpp b/interface/src/renderer/JointState.cpp index bf28852d36..d4a589b657 100644 --- a/interface/src/renderer/JointState.cpp +++ b/interface/src/renderer/JointState.cpp @@ -11,8 +11,9 @@ #include +#include + #include -//#include #include #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); +} \ No newline at end of file diff --git a/interface/src/renderer/JointState.h b/interface/src/renderer/JointState.h index ea506a5db9..25333d730b 100644 --- a/interface/src/renderer/JointState.h +++ b/interface/src/renderer/JointState.h @@ -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; }