2002-06-05 20:44:55 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
|
|
|
#ifndef OSGPARTICLE_RANGE_
|
|
|
|
#define OSGPARTICLE_RANGE_ 1
|
|
|
|
|
2002-06-05 22:14:32 +08:00
|
|
|
// include Export simply to disable Visual Studio silly warnings.
|
|
|
|
#include <osgParticle/Export>
|
|
|
|
|
2002-06-07 22:54:33 +08:00
|
|
|
#ifndef __sgi
|
2002-06-05 20:44:55 +08:00
|
|
|
#include <cstdlib>
|
2002-06-07 22:54:33 +08:00
|
|
|
#else
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
|
|
|
|
2002-06-05 22:14:32 +08:00
|
|
|
//using std::rand;
|
|
|
|
|
2002-06-05 20:44:55 +08:00
|
|
|
namespace osgParticle
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
A simple struct template useful to store ranges of values as min/max pairs.
|
|
|
|
This struct template helps storing min/max ranges for values of any kind; class <CODE>T_</CODE> is
|
|
|
|
the type of values to be stored, and it must support operations <CODE>T_ + T_</CODE>, <CODE>T_ - T_</CODE>,
|
|
|
|
and <CODE>T_ * float</CODE>, otherwise the <CODE>get_random()</CODE> method will not compile.
|
|
|
|
This struct could be extended to customize the random number generator (now it uses only
|
|
|
|
<CODE>std::rand()</CODE>).
|
|
|
|
*/
|
|
|
|
template<class T_> struct range {
|
|
|
|
|
|
|
|
/// Lower bound.
|
2002-08-04 02:03:40 +08:00
|
|
|
T_ minimum;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Higher bound.
|
2002-08-04 02:03:40 +08:00
|
|
|
T_ maximum;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Construct the object by calling default constructors for min and max.
|
2002-08-04 02:03:40 +08:00
|
|
|
range() : minimum(T_()), maximum(T_()) {}
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Construct and initialize min and max directly.
|
2002-08-04 02:03:40 +08:00
|
|
|
range(const T_ &mn, const T_ &mx) : minimum(mn), maximum(mx) {}
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set min and max.
|
2002-08-04 02:03:40 +08:00
|
|
|
void set(const T_ &mn, const T_ &mx) { minimum = mn; maximum = mx; }
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get a random value between min and max.
|
|
|
|
T_ get_random() const
|
|
|
|
{
|
2002-08-04 02:03:40 +08:00
|
|
|
return minimum + (maximum - minimum) * rand() / RAND_MAX;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Range of floats.
|
|
|
|
typedef range<float> rangef;
|
|
|
|
|
|
|
|
/// Range of osg::Vec2s.
|
|
|
|
typedef range<osg::Vec2> rangev2;
|
|
|
|
|
|
|
|
/// Range of osg::Vec3s.
|
|
|
|
typedef range<osg::Vec3> rangev3;
|
|
|
|
|
|
|
|
/// Range of osg::Vec4s.
|
|
|
|
typedef range<osg::Vec4> rangev4;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|