Implement getHalfExtents() for non-actor objects

pull/540/head
Andrei Kortunov 7 years ago
parent 088463ebe6
commit 8516aee6e0

@ -49,6 +49,7 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/class.hpp"
#include "../mwgui/loadingscreen.hpp" #include "../mwgui/loadingscreen.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
@ -1321,6 +1322,29 @@ namespace MWRender
} }
} }
osg::Vec3f RenderingManager::getHalfExtents(const MWWorld::ConstPtr& object) const
{
osg::Vec3f halfExtents(0, 0, 0);
std::string modelName = object.getClass().getModel(object);
if (modelName.empty())
return halfExtents;
osg::ref_ptr<const osg::Node> node = mResourceSystem->getSceneManager()->getTemplate(modelName);
osg::ComputeBoundsVisitor computeBoundsVisitor;
computeBoundsVisitor.setTraversalMask(~(MWRender::Mask_ParticleSystem|MWRender::Mask_Effect));
const_cast<osg::Node*>(node.get())->accept(computeBoundsVisitor);
osg::BoundingBox bounds = computeBoundsVisitor.getBoundingBox();
if (bounds.valid())
{
halfExtents[0] = std::abs(bounds.xMax() - bounds.xMin()) / 2.f;
halfExtents[1] = std::abs(bounds.yMax() - bounds.yMin()) / 2.f;
halfExtents[2] = std::abs(bounds.zMax() - bounds.zMin()) / 2.f;
}
return halfExtents;
}
void RenderingManager::resetFieldOfView() void RenderingManager::resetFieldOfView()
{ {
if (mFieldOfViewOverridden == true) if (mFieldOfViewOverridden == true)

@ -203,6 +203,8 @@ namespace MWRender
/// reset a previous overrideFieldOfView() call, i.e. revert to field of view specified in the settings file. /// reset a previous overrideFieldOfView() call, i.e. revert to field of view specified in the settings file.
void resetFieldOfView(); void resetFieldOfView();
osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& object) const;
void exportSceneGraph(const MWWorld::Ptr& ptr, const std::string& filename, const std::string& format); void exportSceneGraph(const MWWorld::Ptr& ptr, const std::string& filename, const std::string& format);
LandManager* getLandManager() const; LandManager* getLandManager() const;

@ -3339,12 +3339,16 @@ namespace MWWorld
return mRendering->getTerrainHeightAt(worldPos); return mRendering->getTerrainHeightAt(worldPos);
} }
osg::Vec3f World::getHalfExtents(const ConstPtr& actor, bool rendering) const osg::Vec3f World::getHalfExtents(const ConstPtr& object, bool rendering) const
{ {
if (!object.getClass().isActor())
return mRendering->getHalfExtents(object);
// Handle actors separately because of bodyparts
if (rendering) if (rendering)
return mPhysics->getRenderingHalfExtents(actor); return mPhysics->getRenderingHalfExtents(object);
else else
return mPhysics->getHalfExtents(actor); return mPhysics->getHalfExtents(object);
} }
std::string World::exportSceneGraph(const Ptr &ptr) std::string World::exportSceneGraph(const Ptr &ptr)

Loading…
Cancel
Save