]> git.mxchange.org Git - simgear.git/commitdiff
Modified Files:
authorfrohlich <frohlich>
Mon, 20 Nov 2006 18:17:56 +0000 (18:17 +0000)
committerfrohlich <frohlich>
Mon, 20 Nov 2006 18:17:56 +0000 (18:17 +0000)
placementtrans.cxx placementtrans.hxx: Make use of that view
        information in the update visitor

simgear/scene/model/placementtrans.cxx
simgear/scene/model/placementtrans.hxx

index 960b37cc5fdfdd383531c8f14cd7512e291c1fe3..73011b2f8ac521a2887268610ed0128468a52054 100644 (file)
 
 #include "placementtrans.hxx"
 
+#include <simgear/scene/util/SGUpdateVisitor.hxx>
+
+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<SGUpdateVisitor*>(nv);
+    if (updateVisitor) {
+      SGPlacementTransform* placementTransform;
+      placementTransform = static_cast<SGPlacementTransform*>(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)
index c72fbaba6e92082e61c07aad0e9e979723c80673..93ca1080bb6e557c08b1c2350fd055eb84d028a0 100644 (file)
@@ -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                                                 //
   //////////////////////////////////////////////////////////////////