From 160b0ea7d90416e7704f314f5ee300f6f3b79ca8 Mon Sep 17 00:00:00 2001 From: frohlich Date: Mon, 20 Nov 2006 18:17:56 +0000 Subject: [PATCH] Modified Files: placementtrans.cxx placementtrans.hxx: Make use of that view information in the update visitor --- simgear/scene/model/placementtrans.cxx | 27 ++++++++++++++++++++++++++ simgear/scene/model/placementtrans.hxx | 7 +++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/simgear/scene/model/placementtrans.cxx b/simgear/scene/model/placementtrans.cxx index 960b37cc..73011b2f 100644 --- a/simgear/scene/model/placementtrans.cxx +++ b/simgear/scene/model/placementtrans.cxx @@ -32,6 +32,32 @@ #include "placementtrans.hxx" +#include + +class SGPlacementTransform::UpdateCallback : public osg::NodeCallback { +public: + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + { + // short circuit updates if the model we place with that branch + // out of sight. + // Note that the transform is still correct. + SGUpdateVisitor* updateVisitor = dynamic_cast(nv); + if (updateVisitor) { + SGPlacementTransform* placementTransform; + placementTransform = static_cast(node); + double dist2 = distSqr(updateVisitor->getGlobalEyePos(), + placementTransform->getGlobalPos()); + if (updateVisitor->getSqrVisibility() < dist2) + return; + } + // note, callback is responsible for scenegraph traversal so + // should always include call traverse(node,nv) to ensure + // that the rest of cullbacks and the scene graph are traversed. + traverse(node, nv); + } +}; + + SGPlacementTransform::SGPlacementTransform(void) : _placement_offset(0, 0, 0), _scenery_center(0, 0, 0), @@ -40,6 +66,7 @@ SGPlacementTransform::SGPlacementTransform(void) : 0, 0, 1, 0, 0, 0, 0, 1) { + setUpdateCallback(new UpdateCallback); } SGPlacementTransform::~SGPlacementTransform(void) diff --git a/simgear/scene/model/placementtrans.hxx b/simgear/scene/model/placementtrans.hxx index c72fbaba..93ca1080 100644 --- a/simgear/scene/model/placementtrans.hxx +++ b/simgear/scene/model/placementtrans.hxx @@ -40,8 +40,6 @@ public: SGPlacementTransform(void); virtual ~SGPlacementTransform(void); -public: - void setTransform(const SGVec3d& off) { _placement_offset = off; dirtyBound(); } void setTransform(const SGVec3d& off, const SGMatrixd& rot) @@ -49,11 +47,16 @@ public: void setSceneryCenter(const SGVec3d& center) { _scenery_center = center; dirtyBound(); } + const SGVec3d& getGlobalPos() const + { return _placement_offset; } + virtual bool computeLocalToWorldMatrix(osg::Matrix&,osg::NodeVisitor*) const; virtual bool computeWorldToLocalMatrix(osg::Matrix&,osg::NodeVisitor*) const; private: + class UpdateCallback; + ////////////////////////////////////////////////////////////////// // private data // ////////////////////////////////////////////////////////////////// -- 2.39.5