1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_RANGE
16#define OSGPARTICLE_RANGE 1
18// include Export simply to disable Visual Studio silly warnings.
19#include <osgParticle/Export>
31 A simple struct template useful to store ranges of values as min/max pairs.
32 This struct template helps storing min/max ranges for values of any kind; class <CODE>ValueType</CODE> is
33 the type of values to be stored, and it must support operations <CODE>ValueType + ValueType</CODE>, <CODE>ValueType - ValueType</CODE>,
34 and <CODE>ValueType * float</CODE>, otherwise the <CODE>geValueTyperandom()</CODE> method will not compile.
35 This struct could be extended to customize the random number generator (now it uses only
36 <CODE>std::rand()</CODE>).
38 template<class ValueType> struct range
47 /// Construct the object by calling default constructors for min and max.
48 range() : minimum(ValueType()), maximum(ValueType()) {}
50 /// Construct and initialize min and max directly.
51 range(const ValueType& mn, const ValueType& mx) : minimum(mn), maximum(mx) {}
54 void set(const ValueType& mn, const ValueType& mx) { minimum = mn; maximum = mx; }
56 /// Get a random value between min and max.
57 ValueType get_random() const
59 return minimum + (maximum - minimum) * rand() / RAND_MAX;
62 /// Get a random square root value between min and max.
63 ValueType get_random_sqrtf() const
65 return minimum + (maximum - minimum) * sqrtf( static_cast<float>(rand()) / static_cast<float>(RAND_MAX) );
70 return (minimum+maximum)*0.5f;
76 typedef range<float> rangef;
78 /// Range of osg::Vec2s.
79 typedef range<osg::Vec2> rangev2;
81 /// Range of osg::Vec3s.
82 typedef range<osg::Vec3> rangev3;
84 /// Range of osg::Vec4s.
85 typedef range<osg::Vec4> rangev4;