diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index 203951edd..a4db2cba3 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -119,23 +119,48 @@ void KeyframeController::operator() (osg::Node* node, osg::NodeVisitor* nv) if (hasInput()) { NifOsg::MatrixTransform* trans = static_cast(node); + osg::Matrix mat = trans->getMatrix(); float time = getInputValue(nv); - if (!mRotations.empty()) - trans->updateRotation(mRotations.interpKey(time)); + Nif::Matrix3& rot = trans->mRotationScale; + + bool setRot = false; + if(!mRotations.empty()) + { + mat.setRotate(mRotations.interpKey(time)); + setRot = true; + } else if (!mXRotations.empty() || !mYRotations.empty() || !mZRotations.empty()) - trans->updateRotation(getXYZRotation(time)); - else // no rotation specified, use the previous value - trans->applyCurrentRotation(); + { + mat.setRotate(getXYZRotation(time)); + setRot = true; + } + else + { + // no rotation specified, use the previous value + for (int i=0;i<3;++i) + for (int j=0;j<3;++j) + mat(j,i) = rot.mValues[i][j]; // NB column/row major difference + } - if (!mScales.empty()) - trans->updateScale(mScales.interpKey(time)); - else // no scale specified, use the previous value - trans->applyCurrentScale(); + if (setRot) // copy the new values back + for (int i=0;i<3;++i) + for (int j=0;j<3;++j) + rot.mValues[i][j] = mat(j,i); // NB column/row major difference - if (!mTranslations.empty()) - trans->setTranslation(mTranslations.interpKey(time)); + float& scale = trans->mScale; + if(!mScales.empty()) + scale = mScales.interpKey(time); + + for (int i=0;i<3;++i) + for (int j=0;j<3;++j) + mat(i,j) *= scale; + + if(!mTranslations.empty()) + mat.setTrans(mTranslations.interpKey(time)); + + trans->setMatrix(mat); } traverse(node, nv); diff --git a/components/nifosg/matrixtransform.cpp b/components/nifosg/matrixtransform.cpp index 72e12ecf8..bc461b9c1 100644 --- a/components/nifosg/matrixtransform.cpp +++ b/components/nifosg/matrixtransform.cpp @@ -20,37 +20,4 @@ namespace NifOsg , mRotationScale(copy.mRotationScale) { } - - void MatrixTransform::applyCurrentRotation() - { - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 3; ++j) - _matrix(j,i) = mRotationScale.mValues[i][j]; // NB column/row major difference - } - - void MatrixTransform::applyCurrentScale() - { - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 3; ++j) - _matrix(i,j) *= mScale; - } - - void MatrixTransform::updateRotation(const osg::Quat& rotation) - { - _matrix.setRotate(rotation); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 3; ++j) - mRotationScale.mValues[i][j] = _matrix(j,i); // NB column/row major difference - } - - void MatrixTransform::updateScale(const float scale) - { - mScale = scale; - applyCurrentScale(); - } - - void MatrixTransform::setTranslation(const osg::Vec3f& translation) - { - _matrix.setTrans(translation); - } } diff --git a/components/nifosg/matrixtransform.hpp b/components/nifosg/matrixtransform.hpp index ac2fbb57a..975f71c62 100644 --- a/components/nifosg/matrixtransform.hpp +++ b/components/nifosg/matrixtransform.hpp @@ -17,19 +17,6 @@ namespace NifOsg META_Node(NifOsg, MatrixTransform) - // Apply the current NIF rotation or scale to OSG matrix. - void applyCurrentRotation(); - void applyCurrentScale(); - - // Apply the given rotation to OSG matrix directly and update NIF rotation matrix. - void updateRotation(const osg::Quat& rotation); - // Update current NIF scale and apply it to OSG matrix. - void updateScale(const float scale); - - // Apply the given translation to OSG matrix. - void setTranslation(const osg::Vec3f& translation); - - private: // Hack: account for Transform differences between OSG and NIFs. // OSG uses a 4x4 matrix, NIF's use a 3x3 rotationScale, float scale, and vec3 position. // Decomposing the original components from the 4x4 matrix isn't possible, which causes