From dd758f8fd10226239ea58b3ff07d04cffff2a774 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sat, 11 Jun 2022 05:44:35 +0300 Subject: [PATCH] Always update the current matrix in KeyframeController --- components/nifosg/controller.cpp | 3 +++ components/nifosg/matrixtransform.cpp | 26 +++++++++++++++++++------- components/nifosg/matrixtransform.hpp | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index 3f9262797b..beb47ddd76 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -171,9 +171,12 @@ void KeyframeController::operator() (NifOsg::MatrixTransform* node, osg::NodeVis node->setRotation(mRotations.interpKey(time)); else if (!mXRotations.empty() || !mYRotations.empty() || !mZRotations.empty()) node->setRotation(getXYZRotation(time)); + else + node->setRotation(node->mRotationScale); if (!mScales.empty()) node->setScale(mScales.interpKey(time)); + if (!mTranslations.empty()) node->setTranslation(mTranslations.interpKey(time)); } diff --git a/components/nifosg/matrixtransform.cpp b/components/nifosg/matrixtransform.cpp index fcbea337b1..2170c84e5c 100644 --- a/components/nifosg/matrixtransform.cpp +++ b/components/nifosg/matrixtransform.cpp @@ -18,16 +18,13 @@ namespace NifOsg void MatrixTransform::setScale(float scale) { - if (mScale == scale) - return; + // Update the decomposed scale. + mScale = scale; - // Rescale the node using the known decomposed rotation. + // Rescale the node using the known components. for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) - _matrix(i,j) = mRotationScale.mValues[j][i] * scale; // NB: column/row major difference - - // Update the current decomposed scale. - mScale = scale; + _matrix(i,j) = mRotationScale.mValues[j][i] * mScale; // NB: column/row major difference _inverseDirty = true; dirtyBound(); @@ -37,6 +34,7 @@ namespace NifOsg { // First override the rotation ignoring the scale. _matrix.setRotate(rotation); + for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) @@ -51,6 +49,20 @@ namespace NifOsg dirtyBound(); } + void MatrixTransform::setRotation(const Nif::Matrix3 &rotation) + { + // Update the decomposed rotation. + mRotationScale = rotation; + + // Reorient the node using the known components. + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 3; ++j) + _matrix(i,j) = mRotationScale.mValues[j][i] * mScale; // NB: column/row major difference + + _inverseDirty = true; + dirtyBound(); + } + void MatrixTransform::setTranslation(const osg::Vec3f &translation) { // The translation is independent from the rotation and scale so we can apply it directly. diff --git a/components/nifosg/matrixtransform.hpp b/components/nifosg/matrixtransform.hpp index 24d24ba3fa..ffb3c1c37d 100644 --- a/components/nifosg/matrixtransform.hpp +++ b/components/nifosg/matrixtransform.hpp @@ -30,6 +30,7 @@ namespace NifOsg // unless you're sure you know what you are doing. void setScale(float scale); void setRotation(const osg::Quat &rotation); + void setRotation(const Nif::Matrix3 &rotation); void setTranslation(const osg::Vec3f &translation); };