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 TEXTURE_INDEX_X = 11;
46 const static unsigned int TEXTURE_INDEX_Y = 12;
47 const static unsigned int WIDTH = 13;
48 const static unsigned int HEIGHT = 14;
49 const static unsigned int SHADE = 15;
53 setUseDisplayList(false);
56 CloudShaderGeometry(int vx, int vy) :
57 varieties_x(vx), varieties_y(vy)
59 setUseDisplayList(false);
62 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
63 CloudShaderGeometry(const CloudShaderGeometry& CloudShaderGeometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
64 osg::Drawable(CloudShaderGeometry,copyop) {}
66 META_Object(flightgear, CloudShaderGeometry);
69 CloudSprite(SGVec3f& p, int tx, int ty, float w, float h, float s) :
70 position(p), texture_index_x(tx), texture_index_y(ty), width(w), height(h), shade(s)
81 typedef std::vector<CloudSprite*> CloudSpriteList;
83 void insert(CloudSprite* t)
84 { _cloudsprites.push_back(t); }
85 void insert(SGVec3f& p, int tx, int ty, float w, float h, float s)
86 { insert(new CloudSprite(p, tx, ty, w, h, s)); }
88 unsigned getNumCloudSprite() const
89 { return _cloudsprites.size(); }
90 CloudSprite* getCloudSprite(unsigned i) const
91 { return _cloudsprites[i]; }
92 CloudSpriteList _cloudsprites;
94 typedef std::vector<osg::Vec4> PositionSizeList;
96 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
97 virtual osg::BoundingBox computeBound() const;
100 void setGeometry(osg::Drawable* geometry)
102 _geometry = geometry;
105 void addSprite(SGVec3f& p, int tx, int ty, float w, float h, float s, float cull)
107 // Only add the sprite if it is further than the cull distance to all other sprites
108 for (CloudShaderGeometry::CloudSpriteList::iterator iter = _cloudsprites.begin();
109 iter != _cloudsprites.end();
112 if (distSqr((*iter)->position, p) < cull)
114 // Too close - cull it
119 _cloudsprites.push_back(new CloudSprite(p, tx, ty, w, h, s));
122 osg::ref_ptr<osg::Drawable> _geometry;
129 virtual ~CloudShaderGeometry() {}