root/OpenSceneGraph/trunk/examples/osgdepthpartition/DistanceAccumulator.h
@
6941
| Revision 6941, 3.9 kB (checked in by robert, 6 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* -*-c++-*- |
| 2 | * |
| 3 | * OpenSceneGraph example, osgdepthpartion. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | * of this software and associated documentation files (the "Software"), to deal |
| 7 | * in the Software without restriction, including without limitation the rights |
| 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | * copies of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | * THE SOFTWARE. |
| 19 | */ |
| 20 | |
| 21 | #ifndef _OF_DISTANCEACCUMULATOR_ |
| 22 | #define _OF_DISTANCEACCUMULATOR_ |
| 23 | |
| 24 | #include <osg/Group> |
| 25 | #include <osg/NodeVisitor> |
| 26 | #include <osg/Polytope> |
| 27 | #include <osg/fast_back_stack> |
| 28 | |
| 29 | #define CURRENT_CLASS DistanceAccumulator |
| 30 | /********************************************************** |
| 31 | * Ravi Mathur |
| 32 | * OpenFrames API, class DistanceAccumulator |
| 33 | * Class that traverses the scene and computes the distance to each |
| 34 | * visible drawable, and splits up the scene if the drawables are |
| 35 | * too far away (in the z direction) from each other. |
| 36 | **********************************************************/ |
| 37 | class CURRENT_CLASS : public osg::NodeVisitor |
| 38 | { |
| 39 | public: |
| 40 | typedef std::pair<double, double> DistancePair; |
| 41 | typedef std::vector<DistancePair> PairList; |
| 42 | |
| 43 | CURRENT_CLASS(); |
| 44 | |
| 45 | virtual void apply(osg::Node &node); |
| 46 | virtual void apply(osg::Projection &proj); |
| 47 | virtual void apply(osg::Transform &transform); |
| 48 | virtual void apply(osg::Geode &geode); |
| 49 | |
| 50 | // Specify the modelview & projection matrices |
| 51 | void setMatrices(const osg::Matrix &modelview, |
| 52 | const osg::Matrix &projection); |
| 53 | |
| 54 | // Reset visitor before a new traversal |
| 55 | virtual void reset(); |
| 56 | |
| 57 | // Create a (near,far) distance pair for each camera of the specified |
| 58 | // distance pair list and distance limits. |
| 59 | void computeCameraPairs(); |
| 60 | |
| 61 | // Get info on the cameras that should be used for scene rendering |
| 62 | PairList& getCameraPairs() { return _cameraPairs; } |
| 63 | |
| 64 | // Get info on the computed distance pairs |
| 65 | PairList& getDistancePairs() { return _distancePairs; } |
| 66 | |
| 67 | // Get info on the computed nearest/farthest distances |
| 68 | DistancePair& getLimits() { return _limits; } |
| 69 | |
| 70 | // Set/get the desired near/far ratio |
| 71 | void setNearFarRatio(double ratio); |
| 72 | inline double getNearFarRatio() const { return _nearFarRatio; } |
| 73 | |
| 74 | inline void setMaxDepth(unsigned int depth) { _maxDepth = depth; } |
| 75 | inline unsigned int getMaxDepth() const { return _maxDepth; } |
| 76 | |
| 77 | protected: |
| 78 | virtual ~CURRENT_CLASS(); |
| 79 | |
| 80 | void pushLocalFrustum(); |
| 81 | void pushDistancePair(double zNear, double zFar); |
| 82 | bool shouldContinueTraversal(osg::Node &node); |
| 83 | |
| 84 | // Stack of matrices accumulated during traversal |
| 85 | osg::fast_back_stack<osg::Matrix> _viewMatrices; |
| 86 | osg::fast_back_stack<osg::Matrix> _projectionMatrices; |
| 87 | |
| 88 | // Main modelview/projection matrices |
| 89 | osg::Matrix _modelview, _projection; |
| 90 | |
| 91 | // The view frusta in local coordinate space |
| 92 | osg::fast_back_stack<osg::Polytope> _localFrusta; |
| 93 | |
| 94 | // Bounding box corners that should be used for cull computation |
| 95 | typedef std::pair<unsigned int, unsigned int> bbCornerPair; |
| 96 | osg::fast_back_stack<bbCornerPair> _bbCorners; |
| 97 | |
| 98 | // Nar/far planes that should be used for each camera |
| 99 | PairList _cameraPairs; |
| 100 | |
| 101 | // Accumulated pairs of min/max distances |
| 102 | PairList _distancePairs; |
| 103 | |
| 104 | // The closest & farthest distances found while traversing |
| 105 | DistancePair _limits; |
| 106 | |
| 107 | // Ratio of nearest/farthest clip plane for each section of the scene |
| 108 | double _nearFarRatio; |
| 109 | |
| 110 | // Maximum depth to traverse to |
| 111 | unsigned int _maxDepth, _currentDepth; |
| 112 | }; |
| 113 | #undef CURRENT_CLASS |
| 114 | |
| 115 | #endif |
Note: See TracBrowser
for help on using the browser.
