Don't compute the world matrix multiple times

move
scrawl 9 years ago
parent 055d35a2b0
commit 8bd16e4d5a

@ -2140,10 +2140,10 @@ void CharacterController::updateHeadTracking(float duration)
if (!mHeadTrackTarget.isEmpty())
{
osg::MatrixList mats = head->getWorldMatrices();
if (mats.empty())
osg::NodePathList nodepaths = head->getParentalNodePaths();
if (nodepaths.empty())
return;
osg::Matrixf mat = mats[0];
osg::Matrixf mat = osg::computeLocalToWorld(nodepaths[0]);
osg::Vec3f headPos = mat.getTrans();
osg::Vec3f direction;
@ -2154,9 +2154,9 @@ void CharacterController::updateHeadTracking(float duration)
node = anim->getNode("Bip01 Head");
if (node != NULL)
{
osg::MatrixList mats = node->getWorldMatrices();
if (mats.size())
direction = mats[0].getTrans() - headPos;
osg::NodePathList nodepaths = node->getParentalNodePaths();
if (nodepaths.size())
direction = osg::computeLocalToWorld(nodepaths[0]).getTrans() - headPos;
}
else
// no head node to look at, fall back to look at center of collision box

@ -88,10 +88,10 @@ namespace MWRender
const osg::Node* trackNode = mTrackingNode;
if (!trackNode)
return osg::Vec3d();
osg::MatrixList mats = trackNode->getWorldMatrices();
if (!mats.size())
osg::NodePathList nodepaths = trackNode->getParentalNodePaths();
if (nodepaths.empty())
return osg::Vec3d();
const osg::Matrix& worldMat = mats[0];
osg::Matrix worldMat = osg::computeLocalToWorld(nodepaths[0]);
osg::Vec3d position = worldMat.getTrans();
if (!isFirstPerson())

@ -365,10 +365,10 @@ namespace MWRender
traverse(node, nv);
// Now update camera utilizing the updated head position
osg::MatrixList mats = mNodeToFollow->getWorldMatrices();
if (!mats.size())
osg::NodePathList nodepaths = mNodeToFollow->getParentalNodePaths();
if (!nodepaths.size())
return;
osg::Matrix worldMat = mats[0];
osg::Matrix worldMat = osg::computeLocalToWorld(nodepaths[0]);
osg::Vec3 headOffset = worldMat.getTrans();
cam->setViewMatrixAsLookAt(headOffset + mPosOffset, headOffset + mLookAtOffset, osg::Vec3(0,0,1));

@ -44,11 +44,11 @@ void RotateController::operator()(osg::Node *node, osg::NodeVisitor *nv)
osg::Quat RotateController::getWorldOrientation(osg::Node *node)
{
// this could be optimized later, we just need the world orientation, not the full matrix
osg::MatrixList worldMats = node->getWorldMatrices(mRelativeTo);
osg::NodePathList nodepaths = node->getParentalNodePaths(mRelativeTo);
osg::Quat worldOrient;
if (!worldMats.empty())
if (!nodepaths.empty())
{
osg::Matrixf worldMat = worldMats[0];
osg::Matrixf worldMat = osg::computeLocalToWorld(nodepaths[0]);
worldOrient = worldMat.getRotate();
}
return worldOrient;

@ -114,10 +114,10 @@ void WeaponAnimation::releaseArrow(MWWorld::Ptr actor, float attackStrength)
osg::Node* weaponNode = getWeaponNode();
if (!weaponNode)
return;
osg::MatrixList mats = weaponNode->getWorldMatrices();
if (mats.empty())
osg::NodePathList nodepaths = weaponNode->getParentalNodePaths();
if (nodepaths.empty())
return;
osg::Vec3f launchPos = mats[0].getTrans();
osg::Vec3f launchPos = osg::computeLocalToWorld(nodepaths[0]).getTrans();
float fThrownWeaponMinSpeed = gmst.find("fThrownWeaponMinSpeed")->getFloat();
float fThrownWeaponMaxSpeed = gmst.find("fThrownWeaponMaxSpeed")->getFloat();
@ -140,10 +140,10 @@ void WeaponAnimation::releaseArrow(MWWorld::Ptr actor, float attackStrength)
return;
osg::ref_ptr<osg::Node> ammoNode = mAmmunition->getNode();
osg::MatrixList mats = ammoNode->getWorldMatrices();
if (mats.empty())
osg::NodePathList nodepaths = ammoNode->getParentalNodePaths();
if (nodepaths.empty())
return;
osg::Vec3f launchPos = mats[0].getTrans();
osg::Vec3f launchPos = osg::computeLocalToWorld(nodepaths[0]).getTrans();
float fProjectileMinSpeed = gmst.find("fProjectileMinSpeed")->getFloat();
float fProjectileMaxSpeed = gmst.find("fProjectileMaxSpeed")->getFloat();

@ -1051,9 +1051,9 @@ namespace MWWorld
if(!node) node = anim->getNode("Bip01 Head");
if(node)
{
osg::MatrixList mats = node->getWorldMatrices();
if(!mats.empty())
return mats[0];
osg::NodePathList nodepaths = node->getParentalNodePaths();
if(!nodepaths.empty())
return osg::computeLocalToWorld(nodepaths[0]);
}
}
return osg::Matrixf::translate(actor.getRefData().getPosition().asVec3());

@ -261,10 +261,10 @@ void Emitter::emitParticles(double dt)
osg::Matrix worldToPs;
// maybe this could be optimized by halting at the lowest common ancestor of the particle and emitter nodes
osg::MatrixList worldMats = getParticleSystem()->getWorldMatrices();
if (!worldMats.empty())
osg::NodePathList partsysNodePaths = getParticleSystem()->getParentalNodePaths();
if (partsysNodePaths.size())
{
const osg::Matrix psToWorld = worldMats[0];
osg::Matrix psToWorld = osg::computeLocalToWorld(partsysNodePaths[0]);
worldToPs = osg::Matrix::inverse(psToWorld);
}

@ -69,10 +69,10 @@ namespace
void transformInitialParticles(osgParticle::ParticleSystem* partsys, osg::Node* node)
{
osg::MatrixList mats = node->getWorldMatrices();
if (mats.empty())
osg::NodePathList nodepaths = node->getParentalNodePaths();
if (nodepaths.empty())
return;
osg::Matrixf worldMat = mats[0];
osg::Matrixf worldMat = osg::computeLocalToWorld(nodepaths[0]);
worldMat.orthoNormalize(worldMat); // scale is already applied on the particle node
for (int i=0; i<partsys->numParticles(); ++i)
{

Loading…
Cancel
Save