//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 // include Export simply to disable Visual Studio silly warnings. #include #ifndef __sgi #include #else #include #endif #include #include #include //using std::rand; 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 T_ is the type of values to be stored, and it must support operations T_ + T_, T_ - T_, and T_ * float, otherwise the get_random() method will not compile. This struct could be extended to customize the random number generator (now it uses only std::rand()). */ template struct range { /// Lower bound. T_ min; /// Higher bound. T_ max; /// Construct the object by calling default constructors for min and max. range() : min(T_()), max(T_()) {} /// Construct and initialize min and max directly. range(const T_ &mn, const T_ &mx) : min(mn), max(mx) {} /// Set min and max. void set(const T_ &mn, const T_ &mx) { min = mn; max = mx; } /// Get a random value between min and max. T_ get_random() const { return min + (max - min) * rand() / RAND_MAX; } }; /// Range of floats. typedef range rangef; /// Range of osg::Vec2s. typedef range rangev2; /// Range of osg::Vec3s. typedef range rangev3; /// Range of osg::Vec4s. typedef range rangev4; } #endif