- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgParticle/PrecipitationEffect
r11018 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 29 29 { 30 30 public: 31 31 32 32 PrecipitationEffect(); 33 33 PrecipitationEffect(const PrecipitationEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); … … 39 39 40 40 virtual void traverse(osg::NodeVisitor& nv); 41 42 41 42 43 43 /** Set all the parameters to create an rain effect of specified intensity.*/ 44 44 void rain(float intensity); 45 45 46 46 /** Set all the parameters to create an snow effect of specified intensity.*/ 47 47 void snow(float intensity); 48 48 49 49 void setMaximumParticleDensity(float density) { if (_maximumParticleDensity==density) return; _maximumParticleDensity = density; _dirty = true;} 50 50 float getMaximumParticleDensity() const { return _maximumParticleDensity; } … … 52 52 void setWind(const osg::Vec3& wind) { _wind = wind; } 53 53 const osg::Vec3& getWind() const { return _wind; } 54 54 55 55 void setPosition(const osg::Vec3& position) { _origin = position; } 56 56 const osg::Vec3& getPosition() const { return _origin; } 57 57 58 58 void setCellSize(const osg::Vec3& cellSize) { if (_cellSize==cellSize) return; _cellSize = cellSize; _dirty = true; } 59 59 const osg::Vec3& getCellSize() const { return _cellSize; } 60 60 61 61 void setParticleSpeed(float particleSpeed) { if (_particleSpeed==particleSpeed) return; _particleSpeed = particleSpeed; _dirty = true; } 62 62 float getParticleSpeed() const { return _particleSpeed; } … … 64 64 void setParticleSize(float particleSize) { if (_particleSize==particleSize) return; _particleSize = particleSize; _dirty = true;} 65 65 float getParticleSize() const { return _particleSize; } 66 66 67 67 void setParticleColor(const osg::Vec4& color) { if (_particleColor==color) return; _particleColor = color; _dirty = true;} 68 68 const osg::Vec4& getParticleColor() const { return _particleColor; } 69 69 70 70 void setNearTransition(float nearTransition) { _nearTransition = nearTransition; } 71 71 float getNearTransition() const { return _nearTransition; } … … 73 73 void setFarTransition(float farTransition) { _farTransition = farTransition; } 74 74 float getFarTransition() const { return _farTransition; } 75 75 76 76 void setUseFarLineSegments(bool useFarLineSegments) { _useFarLineSegments = useFarLineSegments; } 77 77 bool getUseFarLineSegments() const { return _useFarLineSegments; } … … 80 80 osg::Fog* getFog() { return _fog.get(); } 81 81 const osg::Fog* getFog() const { return _fog.get(); } 82 82 83 83 osg::Geometry* getQuadGeometry() { return _quadGeometry.get(); } 84 84 osg::StateSet* getQuadStateSet() { return _quadStateSet.get(); } 85 85 86 86 osg::Geometry* getLineGeometry() { return _lineGeometry.get(); } 87 87 osg::StateSet* getLineStateSet() { return _lineStateSet.get(); } 88 88 89 89 osg::Geometry* getPointGeometry() { return _pointGeometry.get(); } 90 90 osg::StateSet* getPointStateSet() { return _pointStateSet.get(); } … … 111 111 osg::Geometry* getGeometry() { return _geometry.get(); } 112 112 const osg::Geometry* getGeometry() const { return _geometry.get(); } 113 113 114 114 void setDrawType(GLenum type) { _drawType = type; } 115 115 GLenum getDrawType() const { return _drawType; } 116 116 117 117 void setNumberOfVertices(unsigned int numVertices) { _numberOfVertices = numVertices; } 118 118 unsigned int getNumberOfVertices() const { return _numberOfVertices; } … … 140 140 int k; 141 141 }; 142 142 143 143 struct DepthMatrixStartTime 144 144 { … … 147 147 return depth < rhs.depth; 148 148 } 149 149 150 150 float depth; 151 151 float startTime; … … 155 155 typedef std::map< Cell, DepthMatrixStartTime > CellMatrixMap; 156 156 157 struct LessFunctor 157 struct LessFunctor 158 158 { 159 159 inline bool operator () (const CellMatrixMap::value_type* lhs,const CellMatrixMap::value_type* rhs) const 160 160 { 161 return (*lhs).second<(*rhs).second; 161 return (*lhs).second<(*rhs).second; 162 162 } 163 163 }; … … 183 183 mutable CellMatrixMap _currentCellMatrixMap; 184 184 mutable CellMatrixMap _previousCellMatrixMap; 185 185 186 186 GLenum _drawType; 187 187 unsigned int _numberOfVertices; … … 190 190 191 191 protected: 192 192 193 193 virtual ~PrecipitationEffect() {} 194 194 195 195 void compileGLObjects(osg::RenderInfo& renderInfo) const; 196 196 197 197 void update(); 198 199 void createGeometry(unsigned int numParticles, 200 osg::Geometry* quad_geometry, 198 199 void createGeometry(unsigned int numParticles, 200 osg::Geometry* quad_geometry, 201 201 osg::Geometry* line_geometry, 202 202 osg::Geometry* point_geometry); 203 203 204 204 void setUpGeometries(unsigned int numParticles); 205 205 … … 211 211 osg::ref_ptr<PrecipitationDrawable> _pointPrecipitationDrawable; 212 212 }; 213 213 214 214 void cull(PrecipitationDrawableSet& pds, osgUtil::CullVisitor* cv) const; 215 215 bool build(const osg::Vec3 eyeLocal, int i, int j, int k, float startTime, PrecipitationDrawableSet& pds, osg::Polytope& frustum, osgUtil::CullVisitor* cv) const; … … 237 237 OpenThreads::Mutex _mutex; 238 238 ViewDrawableMap _viewDrawableMap; 239 239 240 240 osg::ref_ptr<osg::Geometry> _quadGeometry; 241 241 osg::ref_ptr<osg::StateSet> _quadStateSet;
