mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 15:10:08 +00:00
CLEANUP(rotatecontroller): Deduplicate rotate/scale checks into the main
callback function
This commit is contained in:
parent
cac5ae34a5
commit
fcc58f6db3
2 changed files with 14 additions and 29 deletions
|
@ -35,13 +35,25 @@ namespace MWRender
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
osg::Matrix matrix = node->getMatrix();
|
osg::Matrix matrix = node->getMatrix();
|
||||||
osg::Quat worldOrient = getWorldOrientation(node);
|
|
||||||
|
osg::Quat worldOrient;
|
||||||
|
osg::Vec3d worldScale(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
osg::NodePathList nodepaths = node->getParentalNodePaths(mRelativeTo);
|
||||||
|
|
||||||
|
if (!nodepaths.empty())
|
||||||
|
{
|
||||||
|
osg::Matrixf worldMat = osg::computeLocalToWorld(nodepaths[0]);
|
||||||
|
worldOrient = worldMat.getRotate();
|
||||||
|
worldScale = worldMat.getScale();
|
||||||
|
}
|
||||||
|
|
||||||
osg::Quat worldOrientInverse = worldOrient.inverse();
|
osg::Quat worldOrientInverse = worldOrient.inverse();
|
||||||
|
|
||||||
osg::Quat orient = worldOrient * mRotate * worldOrientInverse * matrix.getRotate();
|
osg::Quat orient = worldOrient * mRotate * worldOrientInverse * matrix.getRotate();
|
||||||
matrix.setRotate(orient);
|
matrix.setRotate(orient);
|
||||||
|
|
||||||
matrix *= osg::Matrix::scale(getParentScale(node));
|
matrix *= osg::Matrix::scale(worldScale);
|
||||||
|
|
||||||
node->setMatrix(matrix);
|
node->setMatrix(matrix);
|
||||||
|
|
||||||
|
@ -58,28 +70,4 @@ namespace MWRender
|
||||||
|
|
||||||
traverse(node, nv);
|
traverse(node, nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Quat RotateController::getWorldOrientation(osg::Node* node)
|
|
||||||
{
|
|
||||||
// this could be optimized later, we just need the world orientation, not the full matrix
|
|
||||||
osg::NodePathList nodepaths = node->getParentalNodePaths(mRelativeTo);
|
|
||||||
osg::Quat worldOrient;
|
|
||||||
if (!nodepaths.empty())
|
|
||||||
{
|
|
||||||
osg::Matrixf worldMat = osg::computeLocalToWorld(nodepaths[0]);
|
|
||||||
worldOrient = worldMat.getRotate();
|
|
||||||
}
|
|
||||||
return worldOrient;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Vec3d RotateController::getParentScale(osg::Node* node)
|
|
||||||
{
|
|
||||||
osg::NodePathList nodepaths = node->getParentalNodePaths(mRelativeTo);
|
|
||||||
if (!nodepaths.empty())
|
|
||||||
{
|
|
||||||
return osg::computeLocalToWorld(nodepaths[0]).getScale();
|
|
||||||
}
|
|
||||||
return osg::Vec3d(1.0, 1.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,6 @@ namespace MWRender
|
||||||
void operator()(osg::MatrixTransform* node, osg::NodeVisitor* nv);
|
void operator()(osg::MatrixTransform* node, osg::NodeVisitor* nv);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
osg::Quat getWorldOrientation(osg::Node* node);
|
|
||||||
osg::Vec3d getParentScale(osg::Node* node);
|
|
||||||
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
osg::Vec3f mOffset;
|
osg::Vec3f mOffset;
|
||||||
osg::Quat mRotate;
|
osg::Quat mRotate;
|
||||||
|
|
Loading…
Reference in a new issue