mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 09:33:36 +02:00
improving the evalFromRawMatrix decomposition
This commit is contained in:
parent
dc748a85a3
commit
9d146e7ea3
4 changed files with 38 additions and 32 deletions
|
@ -59,20 +59,31 @@ Transform::Mat4& Transform::evalRelativeTransform( Mat4& result, const Vec3& ori
|
|||
return result;
|
||||
}
|
||||
|
||||
void Transform::evalRotationScale(const Mat3& rotationScaleMatrix) {
|
||||
Vec3 scale(glm::length(rotationScaleMatrix[0]), glm::length(rotationScaleMatrix[1]), glm::length(rotationScaleMatrix[2]));
|
||||
if (scale.x < 0.00001f) scale.x = 0.00001f;
|
||||
if (scale.y < 0.00001f) scale.y = 0.00001f;
|
||||
if (scale.z < 0.00001f) scale.z = 0.00001f;
|
||||
|
||||
Mat3 matRotScale(
|
||||
rotationScaleMatrix[0] / scale.x,
|
||||
rotationScaleMatrix[1] / scale.y,
|
||||
rotationScaleMatrix[2] / scale.z);
|
||||
setRotation(glm::quat_cast(matRotScale));
|
||||
|
||||
float determinant = glm::determinant(matRotScale);
|
||||
if (determinant < 0.f) {
|
||||
scale.x = -scale.x;
|
||||
}
|
||||
|
||||
setScale(scale);
|
||||
}
|
||||
|
||||
void Transform::evalFromRawMatrix(const Mat4& matrix) {
|
||||
if ((matrix[0][3] == 0) && (matrix[1][3] == 0) && (matrix[2][3] == 0) && (matrix[3][3] == 1.f)) {
|
||||
setTranslation(Vec3(matrix[3]));
|
||||
|
||||
Mat3 matRS = Mat3(matrix);
|
||||
|
||||
Vec3 scale(glm::length(matRS[0]), glm::length(matRS[1]), glm::length(matRS[2]));
|
||||
|
||||
matRS[0] *= 1/scale.x;
|
||||
matRS[1] *= 1/scale.y;
|
||||
matRS[2] *= 1/scale.z;
|
||||
|
||||
setRotation(glm::quat_cast(matRS));
|
||||
setScale(scale);
|
||||
evalRotationScale(Mat3(matrix));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,18 +102,9 @@ Transform& Transform::mult( Transform& result, const Transform& left, const Tran
|
|||
left.updateCache();
|
||||
|
||||
result.setTranslation(Vec3(left.getMatrix() * Vec4(right.getTranslation(), 1.f)));
|
||||
|
||||
|
||||
Mat4 mat = left.getMatrix() * right.getMatrix();
|
||||
Mat3 matRS = Mat3(mat);
|
||||
|
||||
Vec3 scale(glm::length(matRS[0]), glm::length(matRS[1]), glm::length(matRS[2]));
|
||||
|
||||
matRS[0] *= 1/scale.x;
|
||||
matRS[1] *= 1/scale.y;
|
||||
matRS[2] *= 1/scale.z;
|
||||
|
||||
result.setRotation(glm::quat_cast(matRS));
|
||||
result.setScale(scale);
|
||||
result.evalRotationScale(Mat3(mat));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
|
||||
Transform& evalInverseTranspose(Transform& result);
|
||||
void evalFromRawMatrix(const Mat4& matrix);
|
||||
void evalRotationScale(const Mat3& rotationScalematrix);
|
||||
|
||||
static Transform& mult( Transform& result, const Transform& left, const Transform& right);
|
||||
|
||||
|
@ -110,6 +111,7 @@ protected:
|
|||
};
|
||||
|
||||
typedef QSharedPointer< Transform > TransformPointer;
|
||||
typedef std::vector< TransformPointer > Transforms;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -554,14 +554,18 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
}
|
||||
|
||||
// Let's introduce a gpu::Batch to capture all the calls to the graphics api
|
||||
gpu::Batch batch;
|
||||
_renderBatch.clear();
|
||||
gpu::Batch& batch = _renderBatch;
|
||||
GLBATCH(glPushMatrix)();
|
||||
|
||||
// Capture the view matrix once for the rendering of this model
|
||||
gpu::TransformPointer viewTransform(new gpu::Transform(Application::getInstance()->getUntranslatedViewMatrix()));
|
||||
viewTransform->postTranslate(Application::getInstance()->getViewMatrixTranslation());
|
||||
if (_transforms.empty()) {
|
||||
_transforms.push_back(gpu::TransformPointer(new gpu::Transform()));
|
||||
}
|
||||
_transforms[0]->evalFromRawMatrix(Application::getInstance()->getUntranslatedViewMatrix());
|
||||
_transforms[0]->postTranslate(Application::getInstance()->getViewMatrixTranslation() + _translation);
|
||||
|
||||
batch.setViewTransform(viewTransform);
|
||||
batch.setViewTransform(_transforms[0]);
|
||||
|
||||
GLBATCH(glDisable)(GL_COLOR_MATERIAL);
|
||||
|
||||
|
@ -692,7 +696,6 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
{
|
||||
PROFILE_RANGE("render Batch");
|
||||
::gpu::GLBackend::renderBatch(batch);
|
||||
batch.clear();
|
||||
}
|
||||
|
||||
// restore all the default material settings
|
||||
|
@ -1875,13 +1878,11 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl
|
|||
(const float*)state.clusterMatrices.constData());
|
||||
|
||||
gpu::TransformPointer modelTransform(new gpu::Transform());
|
||||
modelTransform->preTranslate(_translation);
|
||||
batch.setModelTransform(modelTransform);
|
||||
} else {
|
||||
// GLBATCH(glMultMatrixf)((const GLfloat*)&state.clusterMatrices[0]);
|
||||
|
||||
gpu::TransformPointer modelTransform(new gpu::Transform(state.clusterMatrices[0]));
|
||||
modelTransform->preTranslate(_translation);
|
||||
batch.setModelTransform(modelTransform);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,10 @@ class ViewFrustum;
|
|||
typedef QSharedPointer<AnimationHandle> AnimationHandlePointer;
|
||||
typedef QWeakPointer<AnimationHandle> WeakAnimationHandlePointer;
|
||||
|
||||
namespace gpu {
|
||||
class Batch;
|
||||
}
|
||||
|
||||
#include "gpu/Stream.h"
|
||||
#include "gpu/Transform.h"
|
||||
#include "gpu/Batch.h"
|
||||
|
||||
/// A generic 3D model displaying geometry loaded from a URL.
|
||||
class Model : public QObject, public PhysicsEntity {
|
||||
|
@ -283,7 +282,9 @@ private:
|
|||
QUrl _url;
|
||||
|
||||
gpu::Buffers _blendedVertexBuffers;
|
||||
|
||||
gpu::Transforms _transforms;
|
||||
gpu::Batch _renderBatch;
|
||||
|
||||
QVector<QVector<QSharedPointer<Texture> > > _dilatedTextures;
|
||||
|
||||
QVector<Model*> _attachments;
|
||||
|
|
Loading…
Reference in a new issue