root/OpenSceneGraph/trunk/examples/osgdepthpartition/DepthPartitionNode.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_DEPTHPARTITIONNODE_ |
| 22 | #define _OF_DEPTHPARTITIONNODE_ |
| 23 | |
| 24 | #include "DistanceAccumulator.h" |
| 25 | #include <osg/Camera> |
| 26 | |
| 27 | #define CURRENT_CLASS DepthPartitionNode |
| 28 | /********************************************************** |
| 29 | * Ravi Mathur |
| 30 | * OpenFrames API, class DepthPartitionNode |
| 31 | * A type of osg::Group that analyzes a scene, then partitions it into |
| 32 | * several segments that can be rendered separately. Each segment |
| 33 | * is small enough in the z-direction to avoid depth buffer problems |
| 34 | * for very large scenes. |
| 35 | **********************************************************/ |
| 36 | class CURRENT_CLASS : public osg::Group |
| 37 | { |
| 38 | public: |
| 39 | CURRENT_CLASS(); |
| 40 | CURRENT_CLASS(const CURRENT_CLASS& dpn, |
| 41 | const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); |
| 42 | |
| 43 | META_Node( OpenFrames, CURRENT_CLASS ); // Common Node functions |
| 44 | |
| 45 | /** Set the active state. If not active, this node will simply add the |
| 46 | specified scene as it's child, without analyzing it at all. */ |
| 47 | void setActive(bool active); |
| 48 | inline bool getActive() const { return _active; } |
| 49 | |
| 50 | /** Specify whether the color buffer should be cleared before the first |
| 51 | Camera draws it's scene. */ |
| 52 | void setClearColorBuffer(bool clear); |
| 53 | inline bool getClearColorBuffer() const { return _clearColorBuffer; } |
| 54 | |
| 55 | /** Specify the render order for each Camera */ |
| 56 | void setRenderOrder(osg::Camera::RenderOrder order); |
| 57 | inline osg::Camera::RenderOrder getRenderOrder() const |
| 58 | { return _renderOrder; } |
| 59 | |
| 60 | /** Set/get the maximum depth that the scene will be traversed to. |
| 61 | Defaults to UINT_MAX. */ |
| 62 | void setMaxTraversalDepth(unsigned int depth) |
| 63 | { _distAccumulator->setMaxDepth(depth); } |
| 64 | |
| 65 | inline unsigned int getMaxTraversalDepth() const |
| 66 | { return _distAccumulator->getMaxDepth(); } |
| 67 | |
| 68 | /** Override update and cull traversals */ |
| 69 | virtual void traverse(osg::NodeVisitor &nv); |
| 70 | |
| 71 | /** Catch child management functions so the Cameras can be informed |
| 72 | of added or removed children. */ |
| 73 | virtual bool addChild(osg::Node *child); |
| 74 | virtual bool insertChild(unsigned int index, osg::Node *child); |
| 75 | virtual bool removeChildren(unsigned int pos, unsigned int numRemove = 1); |
| 76 | virtual bool setChild(unsigned int i, osg::Node *node); |
| 77 | |
| 78 | protected: |
| 79 | typedef std::vector< osg::ref_ptr<osg::Camera> > CameraList; |
| 80 | |
| 81 | ~CURRENT_CLASS(); |
| 82 | |
| 83 | void init(); |
| 84 | |
| 85 | // Creates a new Camera object with default settings |
| 86 | osg::Camera* createOrReuseCamera(const osg::Matrix& proj, |
| 87 | double znear, double zfar, |
| 88 | const unsigned int &camNum); |
| 89 | |
| 90 | bool _active; // Whether partitioning is active on the scene |
| 91 | |
| 92 | // The NodeVisitor that computes cameras for the scene |
| 93 | osg::ref_ptr<DistanceAccumulator> _distAccumulator; |
| 94 | |
| 95 | osg::Camera::RenderOrder _renderOrder; |
| 96 | bool _clearColorBuffer; |
| 97 | |
| 98 | // Cameras that should be used to draw the scene. These cameras |
| 99 | // will be reused on every frame in order to save time and memory. |
| 100 | CameraList _cameraList; |
| 101 | unsigned int _numCameras; // Number of Cameras actually being used |
| 102 | }; |
| 103 | #undef CURRENT_CLASS |
| 104 | |
| 105 | #endif |
Note: See TracBrowser
for help on using the browser.
