Merge pull request #6528 from hyperlogic/tony/non-uniform-scale-model-entity-fix

Fix for model entities with non-uniform scaled mesh
This commit is contained in:
Andrew Meadows 2015-12-02 15:14:38 -08:00
commit 144983d345
3 changed files with 8 additions and 10 deletions

View file

@ -11,6 +11,7 @@
#include "AnimPose.h"
#include <GLMHelpers.h>
#include <algorithm>
#include <glm/gtc/matrix_transform.hpp>
const AnimPose AnimPose::identity = AnimPose(glm::vec3(1.0f),
glm::quat(),
@ -18,7 +19,9 @@ const AnimPose AnimPose::identity = AnimPose(glm::vec3(1.0f),
AnimPose::AnimPose(const glm::mat4& mat) {
scale = extractScale(mat);
rot = glmExtractRotation(mat);
// quat_cast doesn't work so well with scaled matrices, so cancel it out.
glm::mat4 tmp = glm::scale(mat, 1.0f / scale);
rot = glm::normalize(glm::quat_cast(tmp));
trans = extractTranslation(mat);
}

View file

@ -928,7 +928,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
//virtual
void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
_needsUpdateClusterMatrices = true;
_rig->updateAnimations(deltaTime, parentTransform);
_rig->updateAnimations(deltaTime, parentTransform);
}
void Model::simulateInternal(float deltaTime) {
// update the world space transforms for all joints

View file

@ -279,14 +279,9 @@ glm::quat extractRotation(const glm::mat4& matrix, bool assumeOrthogonal) {
glm::quat glmExtractRotation(const glm::mat4& matrix) {
glm::vec3 scale = extractScale(matrix);
float maxScale = std::max(std::max(scale.x, scale.y), scale.z);
if (maxScale > 1.01f || maxScale <= 0.99f) {
// quat_cast doesn't work so well with scaled matrices, so cancel it out.
glm::mat4 tmp = glm::scale(matrix, 1.0f / scale);
return glm::normalize(glm::quat_cast(tmp));
} else {
return glm::normalize(glm::quat_cast(matrix));
}
// quat_cast doesn't work so well with scaled matrices, so cancel it out.
glm::mat4 tmp = glm::scale(matrix, 1.0f / scale);
return glm::normalize(glm::quat_cast(tmp));
}
glm::vec3 extractScale(const glm::mat4& matrix) {