3 * Copyright (C) 2008 Stuart Buchanan
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #ifndef CLOUD_SHADER_GEOMETRY_HXX
23 #define CLOUD_SHADER_GEOMETRY_HXX 1
27 #include <osg/BoundingBox>
29 #include <osg/Drawable>
30 #include <osg/Geometry>
31 #include <osg/RenderInfo>
35 #include <simgear/math/SGMath.hxx>
36 #include <simgear/math/sg_random.h>
42 class CloudShaderGeometry : public osg::Drawable
46 const static unsigned int USR_ATTR_1 = 10;
47 const static unsigned int USR_ATTR_2 = 11;
51 setUseDisplayList(false);
52 skip_info = new SkipInfo();
55 CloudShaderGeometry(int vx, int vy, float width, float height) :
56 varieties_x(vx), varieties_y(vy)
58 setUseDisplayList(false);
59 skip_info = new SkipInfo();
61 float z = height/2.0f;
62 _bbox.expandBy(-x, -x, -z);
63 _bbox.expandBy(x, x, z);
66 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
67 CloudShaderGeometry(const CloudShaderGeometry& CloudShaderGeometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
68 osg::Drawable(CloudShaderGeometry,copyop) {}
70 META_Object(flightgear, CloudShaderGeometry);
73 SkipInfo() : skip_count(0), skip_limit(1) {}
81 CloudSprite(SGVec3f& p, int tx, int ty, float w, float h, float s, float ch) :
82 position(p), texture_index_x(tx), texture_index_y(ty), width(w), height(h), shade(s), cloud_height(ch)
94 typedef std::vector<CloudSprite*> CloudSpriteList;
95 CloudSpriteList _cloudsprites;
97 void insert(CloudSprite* t)
98 { _cloudsprites.push_back(t); }
99 void insert(SGVec3f& p, int tx, int ty, float w, float h, float s, float ch)
100 { insert(new CloudSprite(p, tx, ty, w, h, s, ch)); }
102 unsigned getNumCloudSprite() const
103 { return _cloudsprites.size(); }
104 CloudSprite* getCloudSprite(unsigned i) const
105 { return _cloudsprites[i]; }
107 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
108 virtual osg::BoundingBox computeBound() const
113 void setGeometry(osg::Drawable* geometry)
115 _geometry = geometry;
118 void addSprite(SGVec3f& p, int tx, int ty, float w, float h, float s, float cull, float cloud_height)
120 // Only add the sprite if it is further than the cull distance to all other sprites
121 for (CloudShaderGeometry::CloudSpriteList::iterator iter = _cloudsprites.begin();
122 iter != _cloudsprites.end();
125 if (distSqr((*iter)->position, p) < cull)
127 // Too close - cull it
132 _cloudsprites.push_back(new CloudSprite(p, tx, ty, w, h, s, cloud_height));
135 osg::ref_ptr<osg::Drawable> _geometry;
140 // Bounding box extents.
141 osg::BoundingBox _bbox;
145 virtual ~CloudShaderGeometry() {
147 for (unsigned int i = 0; i < _cloudsprites.size(); i++)
149 delete _cloudsprites[i];