Use a single-precision PositionAttitudeTransform in speed critical places

openmw-38
scrawl 9 years ago
parent 34350ddeb1
commit 62169a7039

@ -3,11 +3,10 @@
#include <typeinfo>
#include <iostream>
#include <osg/PositionAttitudeTransform>
#include <components/esm/esmreader.hpp>
#include <components/esm/esmwriter.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwworld/class.hpp"

@ -21,7 +21,6 @@
#include <iostream>
#include <osg/PositionAttitudeTransform>
#include "movement.hpp"
#include "npcstats.hpp"
@ -33,6 +32,8 @@
#include <components/settings/settings.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwrender/animation.hpp"
#include "../mwbase/environment.hpp"

@ -1,9 +1,9 @@
#include "combat.hpp"
#include <osg/PositionAttitudeTransform>
#include <components/misc/rng.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/mechanicsmanager.hpp"

@ -2,13 +2,13 @@
#include <limits.h>
#include <osg/PositionAttitudeTransform>
#include <components/misc/rng.hpp>
#include <components/esm/esmwriter.hpp>
#include <components/esm/stolenitems.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwworld/inventorystore.hpp"

@ -1,11 +1,10 @@
#include "actor.hpp"
#include <osg/PositionAttitudeTransform>
#include <BulletCollision/CollisionShapes/btCylinderShape.h>
#include <BulletCollision/CollisionShapes/btBoxShape.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/resource/bulletshape.hpp>
#include "../mwworld/class.hpp"

@ -3,7 +3,6 @@
#include <stdexcept>
#include <osg/Group>
#include <osg/PositionAttitudeTransform>
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
#include <BulletCollision/CollisionShapes/btConeShape.h>
@ -22,6 +21,7 @@
#include <components/resource/bulletshapemanager.hpp>
#include <components/esm/loadgmst.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/nifosg/particle.hpp> // FindRecIndexVisitor

@ -32,6 +32,7 @@
#include <components/sceneutil/util.hpp>
#include <components/sceneutil/lightcontroller.hpp>
#include <components/sceneutil/skeleton.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"

@ -1,8 +1,9 @@
#include "camera.hpp"
#include <osg/PositionAttitudeTransform>
#include <osg/Camera>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
@ -378,7 +379,7 @@ namespace MWRender
else
{
mAnimation->setViewMode(NpcAnimation::VM_Normal);
osg::PositionAttitudeTransform* transform = mTrackingPtr.getRefData().getBaseNode();
SceneUtil::PositionAttitudeTransform* transform = mTrackingPtr.getRefData().getBaseNode();
mTrackingNode = transform;
if (transform)
mHeightScale = transform->getScale().z();

@ -4,6 +4,8 @@
#include <osg/ref_ptr>
#include <memory>
#include <osg/PositionAttitudeTransform>
#include <components/esm/loadnpc.hpp>
#include <components/resource/resourcesystem.hpp>

@ -2,12 +2,11 @@
#include <components/esm/loadcrea.hpp>
#include <osg/PositionAttitudeTransform>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/attach.hpp>
#include <components/sceneutil/visitor.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwbase/world.hpp"

@ -4,7 +4,6 @@
#include <osg/Group>
#include <osg/Geode>
#include <osg/PositionAttitudeTransform>
#include <osg/UserDataContainer>
#include <osg/Version>
@ -14,6 +13,7 @@
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/visitor.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwworld/ptr.hpp"
#include "../mwworld/class.hpp"
@ -116,7 +116,7 @@ void Objects::insertBegin(const MWWorld::Ptr& ptr)
else
cellnode = found->second;
osg::ref_ptr<osg::PositionAttitudeTransform> insert (new osg::PositionAttitudeTransform);
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> insert (new SceneUtil::PositionAttitudeTransform);
cellnode->addChild(insert);
insert->getOrCreateUserDataContainer()->addUserObject(new PtrHolder(ptr));

@ -8,7 +8,6 @@
#include <osg/Fog>
#include <osg/PolygonMode>
#include <osg/Group>
#include <osg/PositionAttitudeTransform>
#include <osg/UserDataContainer>
#include <osg/ComputeBoundsVisitor>
@ -26,6 +25,7 @@
#include <components/sceneutil/util.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/sceneutil/statesetupdater.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/terrain/terraingrid.hpp>
@ -706,7 +706,7 @@ namespace MWRender
{
if (!mPlayerNode)
{
mPlayerNode = new osg::PositionAttitudeTransform;
mPlayerNode = new SceneUtil::PositionAttitudeTransform;
mPlayerNode->setNodeMask(Mask_Player);
mLightRoot->addChild(mPlayerNode);
}

@ -186,7 +186,7 @@ namespace MWRender
std::auto_ptr<SkyManager> mSky;
std::auto_ptr<EffectManager> mEffectManager;
std::auto_ptr<NpcAnimation> mPlayerAnimation;
osg::ref_ptr<osg::PositionAttitudeTransform> mPlayerNode;
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
std::auto_ptr<Camera> mCamera;
osg::ref_ptr<StateUpdater> mStateUpdater;

@ -8,6 +8,7 @@
namespace osg
{
class Group;
class PositionAttitudeTransform;
}
namespace osgParticle

@ -1,6 +1,6 @@
#include <iostream>
#include <osg/PositionAttitudeTransform>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/esm/loadcell.hpp>

@ -4,6 +4,7 @@
#include <string>
#include <osg/ref_ptr>
#include <osg/PositionAttitudeTransform>
#include <components/esm/effectlist.hpp>

@ -108,12 +108,12 @@ namespace MWWorld
{}
}
void RefData::setBaseNode(osg::PositionAttitudeTransform *base)
void RefData::setBaseNode(SceneUtil::PositionAttitudeTransform *base)
{
mBaseNode = base;
}
osg::PositionAttitudeTransform* RefData::getBaseNode()
SceneUtil::PositionAttitudeTransform* RefData::getBaseNode()
{
return mBaseNode;
}

@ -7,7 +7,7 @@
#include <osg/Vec3f>
namespace osg
namespace SceneUtil
{
class PositionAttitudeTransform;
}
@ -26,7 +26,7 @@ namespace MWWorld
class RefData
{
osg::PositionAttitudeTransform* mBaseNode;
SceneUtil::PositionAttitudeTransform* mBaseNode;
MWScript::Locals mLocals;
@ -69,10 +69,10 @@ namespace MWWorld
RefData& operator= (const RefData& refData);
/// Return base node (can be a null pointer).
osg::PositionAttitudeTransform* getBaseNode();
SceneUtil::PositionAttitudeTransform* getBaseNode();
/// Set base node (can be a null pointer).
void setBaseNode (osg::PositionAttitudeTransform* base);
void setBaseNode (SceneUtil::PositionAttitudeTransform* base);
int getCount() const;

@ -10,7 +10,6 @@
#include <osg/Group>
#include <osg/ComputeBoundsVisitor>
#include <osg/PositionAttitudeTransform>
#include <components/esm/esmreader.hpp>
#include <components/esm/esmwriter.hpp>
@ -22,6 +21,8 @@
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"

@ -41,7 +41,7 @@ add_component_dir (resource
)
add_component_dir (sceneutil
clone attach lightmanager visitor util statesetupdater controller skeleton riggeometry lightcontroller
clone attach lightmanager visitor util statesetupdater controller skeleton riggeometry lightcontroller positionattitudetransform
# not used yet
#workqueue
)

@ -0,0 +1,51 @@
#include "positionattitudetransform.hpp"
#include <iostream>
namespace SceneUtil
{
PositionAttitudeTransform::PositionAttitudeTransform():
_scale(1.0,1.0,1.0)
{
}
bool PositionAttitudeTransform::computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_RF)
{
matrix.preMultTranslate(_position);
matrix.preMultRotate(_attitude);
matrix.preMultScale(_scale);
}
else // absolute
{
matrix.makeRotate(_attitude);
matrix.postMultTranslate(_position);
matrix.preMultScale(_scale);
}
return true;
}
bool PositionAttitudeTransform::computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor*) const
{
if (_scale.x() == 0.0 || _scale.y() == 0.0 || _scale.z() == 0.0)
return false;
if (_referenceFrame==RELATIVE_RF)
{
matrix.postMultTranslate(-_position);
matrix.postMultRotate(_attitude.inverse());
matrix.postMultScale(osg::Vec3f(1.0/_scale.x(), 1.0/_scale.y(), 1.0/_scale.z()));
}
else // absolute
{
matrix.makeRotate(_attitude.inverse());
matrix.preMultTranslate(-_position);
matrix.postMultScale(osg::Vec3f(1.0/_scale.x(), 1.0/_scale.y(), 1.0/_scale.z()));
}
return true;
}
}

@ -0,0 +1,53 @@
#ifndef OPENMW_COMPONENTS_POSITIONATTITUDE_TRANSFORM_H
#define OPENMW_COMPONENTS_POSITIONATTITUDE_TRANSFORM_H
#include <osg/Transform>
namespace SceneUtil
{
/// @brief A customized version of osg::PositionAttitudeTransform optimized for speed.
/// Uses single precision values. Also removed _pivotPoint which we don't need.
class PositionAttitudeTransform : public osg::Transform
{
public :
PositionAttitudeTransform();
PositionAttitudeTransform(const PositionAttitudeTransform& pat,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
Transform(pat,copyop),
_position(pat._position),
_attitude(pat._attitude),
_scale(pat._scale){}
META_Node(SceneUtil, PositionAttitudeTransform)
inline void setPosition(const osg::Vec3f& pos) { _position = pos; dirtyBound(); }
inline const osg::Vec3f& getPosition() const { return _position; }
inline void setAttitude(const osg::Quat& quat) { _attitude = quat; dirtyBound(); }
inline const osg::Quat& getAttitude() const { return _attitude; }
inline void setScale(const osg::Vec3f& scale) { _scale = scale; dirtyBound(); }
inline const osg::Vec3f& getScale() const { return _scale; }
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
protected :
virtual ~PositionAttitudeTransform() {}
osg::Vec3f _position;
osg::Quat _attitude;
osg::Vec3f _scale;
};
}
#endif

@ -6,10 +6,10 @@
#include <components/resource/texturemanager.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/esm/loadland.hpp>
#include <osg/PositionAttitudeTransform>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/KdTree>
@ -91,7 +91,7 @@ osg::ref_ptr<osg::Node> TerrainGrid::buildTerrain (osg::Group* parent, float chu
return NULL; // no terrain defined
osg::Vec2f worldCenter = chunkCenter*mStorage->getCellWorldSize();
osg::ref_ptr<osg::PositionAttitudeTransform> transform (new osg::PositionAttitudeTransform);
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> transform (new SceneUtil::PositionAttitudeTransform);
transform->setPosition(osg::Vec3f(worldCenter.x(), worldCenter.y(), 0.f));
if (parent)

Loading…
Cancel
Save