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>
41 class CloudShaderGeometry : public osg::Drawable
45 const static unsigned int CLOUD_HEIGHT = 10;
46 const static unsigned int TEXTURE_INDEX_X = 11;
47 const static unsigned int TEXTURE_INDEX_Y = 12;
48 const static unsigned int WIDTH = 13;
49 const static unsigned int HEIGHT = 14;
50 const static unsigned int SHADE = 15;
54 setUseDisplayList(false);
55 skip_info = new SkipInfo();
58 CloudShaderGeometry(int vx, int vy, float width, float height) :
59 varieties_x(vx), varieties_y(vy)
61 setUseDisplayList(false);
62 skip_info = new SkipInfo();
64 float z = height/2.0f;
65 _bbox.expandBy(-x, -x, -z);
66 _bbox.expandBy(x, x, z);
69 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
70 CloudShaderGeometry(const CloudShaderGeometry& CloudShaderGeometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
71 osg::Drawable(CloudShaderGeometry,copyop) {}
73 META_Object(flightgear, CloudShaderGeometry);
76 SkipInfo() : skip_count(0), skip_limit(1) {}
84 CloudSprite(SGVec3f& p, int tx, int ty, float w, float h, float s, float ch) :
85 position(p), texture_index_x(tx), texture_index_y(ty), width(w), height(h), shade(s), cloud_height(ch)
97 typedef std::vector<CloudSprite*> CloudSpriteList;
99 void insert(CloudSprite* t)
100 { _cloudsprites.push_back(t); }
101 void insert(SGVec3f& p, int tx, int ty, float w, float h, float s, float ch)
102 { insert(new CloudSprite(p, tx, ty, w, h, s, ch)); }
104 unsigned getNumCloudSprite() const
105 { return _cloudsprites.size(); }
106 CloudSprite* getCloudSprite(unsigned i) const
107 { return _cloudsprites[i]; }
108 CloudSpriteList _cloudsprites;
110 typedef std::vector<osg::Vec4> PositionSizeList;
112 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
113 virtual osg::BoundingBox computeBound() const
118 void setGeometry(osg::Drawable* geometry)
120 _geometry = geometry;
123 void addSprite(SGVec3f& p, int tx, int ty, float w, float h, float s, float cull, float cloud_height)
125 // Only add the sprite if it is further than the cull distance to all other sprites
126 for (CloudShaderGeometry::CloudSpriteList::iterator iter = _cloudsprites.begin();
127 iter != _cloudsprites.end();
130 if (distSqr((*iter)->position, p) < cull)
132 // Too close - cull it
137 _cloudsprites.push_back(new CloudSprite(p, tx, ty, w, h, s, cloud_height));
140 osg::ref_ptr<osg::Drawable> _geometry;
145 // Bounding box extents.
146 osg::BoundingBox _bbox;
150 virtual ~CloudShaderGeometry() {
152 for (int i = 0; i < _cloudsprites.size(); i++)
154 delete _cloudsprites[i];