mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
Don't encapsulate NIF transformation changes
Currently that causes issues
This commit is contained in:
parent
72b63ed140
commit
3d31d21bc2
@ -119,23 +119,48 @@ void KeyframeController::operator() (osg::Node* node, osg::NodeVisitor* nv)
|
||||
if (hasInput())
|
||||
{
|
||||
NifOsg::MatrixTransform* trans = static_cast<NifOsg::MatrixTransform*>(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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user