cleanup of precipitation contribution
Reindent everything to Stroustrup style and make member variable style consistent. Remove unused header files. SGPrecipitation is now a subclass of osg::Referenced. Initialize snow and ice intensity to 0 directly. The methods that set the intensities change the value slowly and so don't work when the initial value is garbage.
This commit is contained in:
@@ -22,50 +22,21 @@
|
|||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @par CVS
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precipitation.hxx"
|
#include "precipitation.hxx"
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/math/SGMath.hxx>
|
|
||||||
#include <simgear/math/point3d.hxx>
|
|
||||||
#include <simgear/scene/model/placement.hxx>
|
|
||||||
#include <simgear/misc/sg_path.hxx>
|
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
|
||||||
#include <simgear/structure/SGReferenced.hxx>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SG_USING_STD(string);
|
|
||||||
SG_USING_STD(list);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SGPrecipitation constructor
|
* @brief SGPrecipitation constructor
|
||||||
*
|
*
|
||||||
* Build a new OSG object from osgParticle.
|
* Build a new OSG object from osgParticle.
|
||||||
*/
|
*/
|
||||||
SGPrecipitation::SGPrecipitation() {
|
SGPrecipitation::SGPrecipitation() :
|
||||||
this->setSnowIntensity(0.0);
|
_freeze(false), _snow_intensity(0.0), _rain_intensity(0.0)
|
||||||
this->setRainIntensity(0.0);
|
{
|
||||||
this->setFreezing(false);
|
_precipitationEffect = new osgParticle::PrecipitationEffect;
|
||||||
this->setWindProperty(0.0, 0.0);
|
|
||||||
|
|
||||||
precipitationEffect = new osgParticle::PrecipitationEffect;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SGPrecipitation destructor
|
|
||||||
*/
|
|
||||||
SGPrecipitation::~SGPrecipitation(void) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,15 +46,16 @@ SGPrecipitation::~SGPrecipitation(void) {
|
|||||||
* This function permits you to create an object precipitationEffect and initialize it.
|
* This function permits you to create an object precipitationEffect and initialize it.
|
||||||
* I define by default the color of water (for raining)
|
* I define by default the color of water (for raining)
|
||||||
*/
|
*/
|
||||||
osg::Group* SGPrecipitation::build(void) {
|
osg::Group* SGPrecipitation::build(void)
|
||||||
group = new osg::Group;
|
{
|
||||||
|
osg::Group* group = new osg::Group;
|
||||||
|
|
||||||
precipitationEffect->snow(0);
|
_precipitationEffect->snow(0);
|
||||||
precipitationEffect->rain(0);
|
_precipitationEffect->rain(0);
|
||||||
|
|
||||||
group->addChild(precipitationEffect.get());
|
group->addChild(_precipitationEffect.get());
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,13 +65,14 @@ osg::Group* SGPrecipitation::build(void) {
|
|||||||
* This function permits you to define and change the snow intensity
|
* This function permits you to define and change the snow intensity
|
||||||
* The param 'intensity' is normed (0 to 1).
|
* The param 'intensity' is normed (0 to 1).
|
||||||
*/
|
*/
|
||||||
void SGPrecipitation::setSnowIntensity(float intensity) {
|
void SGPrecipitation::setSnowIntensity(float intensity)
|
||||||
if (this->_snow_intensity < intensity-0.001)
|
{
|
||||||
this->_snow_intensity += 0.001;
|
if (this->_snow_intensity < intensity-0.001)
|
||||||
else if (this->_snow_intensity > intensity+0.001)
|
this->_snow_intensity += 0.001;
|
||||||
this->_snow_intensity -= 0.001;
|
else if (this->_snow_intensity > intensity+0.001)
|
||||||
else
|
this->_snow_intensity -= 0.001;
|
||||||
this->_snow_intensity = intensity;
|
else
|
||||||
|
this->_snow_intensity = intensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,13 +82,14 @@ void SGPrecipitation::setSnowIntensity(float intensity) {
|
|||||||
* This function permits you to define and change the rain intensity
|
* This function permits you to define and change the rain intensity
|
||||||
* The param 'intensity' is normed (0 to 1).
|
* The param 'intensity' is normed (0 to 1).
|
||||||
*/
|
*/
|
||||||
void SGPrecipitation::setRainIntensity(float intensity) {
|
void SGPrecipitation::setRainIntensity(float intensity)
|
||||||
if (this->_rain_intensity < intensity-0.001)
|
{
|
||||||
this->_rain_intensity += 0.001;
|
if (this->_rain_intensity < intensity-0.001)
|
||||||
else if (this->_rain_intensity > intensity+0.001)
|
this->_rain_intensity += 0.001;
|
||||||
this->_rain_intensity -= 0.001;
|
else if (this->_rain_intensity > intensity+0.001)
|
||||||
else
|
this->_rain_intensity -= 0.001;
|
||||||
this->_rain_intensity = intensity;
|
else
|
||||||
|
this->_rain_intensity = intensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -126,8 +100,9 @@ void SGPrecipitation::setRainIntensity(float intensity) {
|
|||||||
*
|
*
|
||||||
* This function permits you to turn off the rain to snow.
|
* This function permits you to turn off the rain to snow.
|
||||||
*/
|
*/
|
||||||
void SGPrecipitation::setFreezing(bool freeze) {
|
void SGPrecipitation::setFreezing(bool freeze)
|
||||||
this->_freeze = freeze;
|
{
|
||||||
|
this->_freeze = freeze;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -140,17 +115,18 @@ void SGPrecipitation::setFreezing(bool freeze) {
|
|||||||
* x points full south... From wind heading and speed, we can calculate
|
* x points full south... From wind heading and speed, we can calculate
|
||||||
* the wind vector.
|
* the wind vector.
|
||||||
*/
|
*/
|
||||||
void SGPrecipitation::setWindProperty(double heading, double speed) {
|
void SGPrecipitation::setWindProperty(double heading, double speed)
|
||||||
double x, y, z;
|
{
|
||||||
|
double x, y, z;
|
||||||
|
|
||||||
heading = (heading + 180) * SGD_DEGREES_TO_RADIANS;
|
heading = (heading + 180) * SGD_DEGREES_TO_RADIANS;
|
||||||
speed = speed * SG_FEET_TO_METER;
|
speed = speed * SG_FEET_TO_METER;
|
||||||
|
|
||||||
x = -cos(heading) * speed;
|
x = -cos(heading) * speed;
|
||||||
y = sin(heading) * speed;
|
y = sin(heading) * speed;
|
||||||
z = 0;
|
z = 0;
|
||||||
|
|
||||||
this->_wind_vec = osg::Vec3(x, y, z);
|
this->_wind_vec = osg::Vec3(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -163,43 +139,41 @@ void SGPrecipitation::setWindProperty(double heading, double speed) {
|
|||||||
*
|
*
|
||||||
* The settings come from the osgParticule/PrecipitationEffect.cpp exemple.
|
* The settings come from the osgParticule/PrecipitationEffect.cpp exemple.
|
||||||
*/
|
*/
|
||||||
bool SGPrecipitation::update(void) {
|
bool SGPrecipitation::update(void)
|
||||||
if (this->_freeze) {
|
{
|
||||||
if (this->_rain_intensity > 0)
|
if (this->_freeze) {
|
||||||
this->_snow_intensity = this->_rain_intensity;
|
if (this->_rain_intensity > 0)
|
||||||
}
|
this->_snow_intensity = this->_rain_intensity;
|
||||||
|
}
|
||||||
|
|
||||||
if (this->_snow_intensity > 0) {
|
if (this->_snow_intensity > 0) {
|
||||||
precipitationEffect->setWind(_wind_vec);
|
_precipitationEffect->setWind(_wind_vec);
|
||||||
precipitationEffect->setParticleSpeed( -0.75f - 0.25f*_snow_intensity);
|
_precipitationEffect->setParticleSpeed( -0.75f - 0.25f*_snow_intensity);
|
||||||
|
|
||||||
precipitationEffect->setParticleSize(0.02f + 0.03f*_snow_intensity);
|
_precipitationEffect->setParticleSize(0.02f + 0.03f*_snow_intensity);
|
||||||
precipitationEffect->setMaximumParticleDensity(_snow_intensity * 7.2f);
|
_precipitationEffect->setMaximumParticleDensity(_snow_intensity * 7.2f);
|
||||||
precipitationEffect->setCellSize(osg::Vec3(5.0f / (0.25f+_snow_intensity), 5.0f / (0.25f+_snow_intensity), 5.0f));
|
_precipitationEffect->setCellSize(osg::Vec3(5.0f / (0.25f+_snow_intensity), 5.0f / (0.25f+_snow_intensity), 5.0f));
|
||||||
|
|
||||||
precipitationEffect->setNearTransition(25.f);
|
_precipitationEffect->setNearTransition(25.f);
|
||||||
precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_snow_intensity));
|
_precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_snow_intensity));
|
||||||
|
|
||||||
precipitationEffect->setParticleColor(osg::Vec4(0.85, 0.85, 0.85, 1.0) - osg::Vec4(0.1, 0.1, 0.1, 1.0) * _snow_intensity);
|
_precipitationEffect->setParticleColor(osg::Vec4(0.85, 0.85, 0.85, 1.0) - osg::Vec4(0.1, 0.1, 0.1, 1.0) * _snow_intensity);
|
||||||
}
|
} else if (this->_rain_intensity > 0){
|
||||||
else if (this->_rain_intensity > 0){
|
_precipitationEffect->setWind(_wind_vec);
|
||||||
precipitationEffect->setWind(_wind_vec);
|
_precipitationEffect->setParticleSpeed( -2.0f + -5.0f*_rain_intensity);
|
||||||
precipitationEffect->setParticleSpeed( -2.0f + -5.0f*_rain_intensity);
|
|
||||||
|
|
||||||
precipitationEffect->setParticleSize(0.01 + 0.02*_rain_intensity);
|
_precipitationEffect->setParticleSize(0.01 + 0.02*_rain_intensity);
|
||||||
precipitationEffect->setMaximumParticleDensity(_rain_intensity * 7.5f);
|
_precipitationEffect->setMaximumParticleDensity(_rain_intensity * 7.5f);
|
||||||
precipitationEffect->setCellSize(osg::Vec3(5.0f / (0.25f+_rain_intensity), 5.0f / (0.25f+_rain_intensity), 5.0f));
|
_precipitationEffect->setCellSize(osg::Vec3(5.0f / (0.25f+_rain_intensity), 5.0f / (0.25f+_rain_intensity), 5.0f));
|
||||||
|
|
||||||
precipitationEffect->setNearTransition(25.f);
|
_precipitationEffect->setNearTransition(25.f);
|
||||||
precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_rain_intensity));
|
_precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_rain_intensity));
|
||||||
|
|
||||||
precipitationEffect->setParticleColor( osg::Vec4(0x7A, 0xCE, 0xFF, 0x80));
|
_precipitationEffect->setParticleColor( osg::Vec4(0x7A, 0xCE, 0xFF, 0x80));
|
||||||
}
|
} else {
|
||||||
else {
|
_precipitationEffect->snow(0);
|
||||||
precipitationEffect->snow(0);
|
_precipitationEffect->rain(0);
|
||||||
precipitationEffect->rain(0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,51 +22,39 @@
|
|||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @par CVS
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PRECIPITATION_HXX
|
#ifndef _PRECIPITATION_HXX
|
||||||
#define _PRECIPITATION_HXX
|
#define _PRECIPITATION_HXX
|
||||||
|
|
||||||
#include <osgDB/ReadFile>
|
#include <osg/Group>
|
||||||
#include <osgDB/FileUtils>
|
#include <osg/Referenced>
|
||||||
#include <osgUtil/Optimizer>
|
|
||||||
#include <osgUtil/CullVisitor>
|
|
||||||
#include <osgViewer/Viewer>
|
|
||||||
|
|
||||||
#include <osg/Depth>
|
|
||||||
#include <osg/Stencil>
|
|
||||||
#include <osg/ClipPlane>
|
|
||||||
#include <osg/ClipNode>
|
|
||||||
#include <osg/MatrixTransform>
|
|
||||||
#include <osgUtil/TransformCallback>
|
|
||||||
#include <osgParticle/PrecipitationEffect>
|
#include <osgParticle/PrecipitationEffect>
|
||||||
|
|
||||||
|
|
||||||
class SGPrecipitation {
|
class SGPrecipitation : public osg::Referenced
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
bool _freeze;
|
bool _freeze;
|
||||||
|
|
||||||
float _snow_intensity;
|
float _snow_intensity;
|
||||||
float _rain_intensity;
|
float _rain_intensity;
|
||||||
|
|
||||||
int _wind_dir;
|
int _wind_dir;
|
||||||
osg::Vec3 _wind_vec;
|
osg::Vec3 _wind_vec;
|
||||||
|
|
||||||
osg::Group *group;
|
osg::ref_ptr<osgParticle::PrecipitationEffect> _precipitationEffect;
|
||||||
osg::ref_ptr<osgParticle::PrecipitationEffect> precipitationEffect;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SGPrecipitation();
|
SGPrecipitation();
|
||||||
~SGPrecipitation();
|
virtual ~SGPrecipitation() {}
|
||||||
osg::Group* build(void);
|
osg::Group* build(void);
|
||||||
bool update(void);
|
bool update(void);
|
||||||
|
|
||||||
void setWindProperty(double, double);
|
void setWindProperty(double, double);
|
||||||
void setFreezing(bool);
|
void setFreezing(bool);
|
||||||
void setRainIntensity(float);
|
void setRainIntensity(float);
|
||||||
void setSnowIntensity(float);
|
void setSnowIntensity(float);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user