mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 08:15:35 +00:00
Don't encapsulate NIF transformation changes
Currently that causes issues
This commit is contained in:
parent
72b63ed140
commit
3d31d21bc2
3 changed files with 36 additions and 57 deletions
|
@ -119,23 +119,48 @@ void KeyframeController::operator() (osg::Node* node, osg::NodeVisitor* nv)
|
||||||
if (hasInput())
|
if (hasInput())
|
||||||
{
|
{
|
||||||
NifOsg::MatrixTransform* trans = static_cast<NifOsg::MatrixTransform*>(node);
|
NifOsg::MatrixTransform* trans = static_cast<NifOsg::MatrixTransform*>(node);
|
||||||
|
osg::Matrix mat = trans->getMatrix();
|
||||||
|
|
||||||
float time = getInputValue(nv);
|
float time = getInputValue(nv);
|
||||||
|
|
||||||
if (!mRotations.empty())
|
Nif::Matrix3& rot = trans->mRotationScale;
|
||||||
trans->updateRotation(mRotations.interpKey(time));
|
|
||||||
|
bool setRot = false;
|
||||||
|
if(!mRotations.empty())
|
||||||
|
{
|
||||||
|
mat.setRotate(mRotations.interpKey(time));
|
||||||
|
setRot = true;
|
||||||
|
}
|
||||||
else if (!mXRotations.empty() || !mYRotations.empty() || !mZRotations.empty())
|
else if (!mXRotations.empty() || !mYRotations.empty() || !mZRotations.empty())
|
||||||
trans->updateRotation(getXYZRotation(time));
|
{
|
||||||
else // no rotation specified, use the previous value
|
mat.setRotate(getXYZRotation(time));
|
||||||
trans->applyCurrentRotation();
|
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())
|
if (setRot) // copy the new values back
|
||||||
trans->updateScale(mScales.interpKey(time));
|
for (int i=0;i<3;++i)
|
||||||
else // no scale specified, use the previous value
|
for (int j=0;j<3;++j)
|
||||||
trans->applyCurrentScale();
|
rot.mValues[i][j] = mat(j,i); // NB column/row major difference
|
||||||
|
|
||||||
if (!mTranslations.empty())
|
float& scale = trans->mScale;
|
||||||
trans->setTranslation(mTranslations.interpKey(time));
|
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);
|
traverse(node, nv);
|
||||||
|
|
|
@ -20,37 +20,4 @@ namespace NifOsg
|
||||||
, mRotationScale(copy.mRotationScale)
|
, 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)
|
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.
|
// 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.
|
// 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
|
// Decomposing the original components from the 4x4 matrix isn't possible, which causes
|
||||||
|
|
Loading…
Reference in a new issue