From 8bd16e4d5ab92035974b629349c6d8f3f5bbe977 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 22 Feb 2016 18:58:19 +0100 Subject: [PATCH] Don't compute the world matrix multiple times --- apps/openmw/mwmechanics/character.cpp | 12 ++++++------ apps/openmw/mwrender/camera.cpp | 6 +++--- apps/openmw/mwrender/characterpreview.cpp | 6 +++--- apps/openmw/mwrender/rotatecontroller.cpp | 6 +++--- apps/openmw/mwrender/weaponanimation.cpp | 12 ++++++------ apps/openmw/mwworld/worldimp.cpp | 6 +++--- components/nifosg/particle.cpp | 6 +++--- components/resource/scenemanager.cpp | 6 +++--- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 67707d028..2f024838d 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -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 diff --git a/apps/openmw/mwrender/camera.cpp b/apps/openmw/mwrender/camera.cpp index 88934414f..5a3f2bea3 100644 --- a/apps/openmw/mwrender/camera.cpp +++ b/apps/openmw/mwrender/camera.cpp @@ -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()) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index b9f20f4ea..201124447 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -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)); diff --git a/apps/openmw/mwrender/rotatecontroller.cpp b/apps/openmw/mwrender/rotatecontroller.cpp index 11f5b943d..534cc7490 100644 --- a/apps/openmw/mwrender/rotatecontroller.cpp +++ b/apps/openmw/mwrender/rotatecontroller.cpp @@ -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; diff --git a/apps/openmw/mwrender/weaponanimation.cpp b/apps/openmw/mwrender/weaponanimation.cpp index 8fd294ccd..2627d3fc6 100644 --- a/apps/openmw/mwrender/weaponanimation.cpp +++ b/apps/openmw/mwrender/weaponanimation.cpp @@ -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 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(); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 98517f543..f3d80ee67 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -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()); diff --git a/components/nifosg/particle.cpp b/components/nifosg/particle.cpp index 500339722..be2e708fb 100644 --- a/components/nifosg/particle.cpp +++ b/components/nifosg/particle.cpp @@ -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); } diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 9965e7767..113406ef6 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -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; inumParticles(); ++i) {