OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
range.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
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.
7  *
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.
12 */
13 //osgParticle - Copyright (C) 2002 Marco Jez
14 
15 #ifndef OSGPARTICLE_RANGE
16 #define OSGPARTICLE_RANGE 1
17 
18 // include Export simply to disable Visual Studio silly warnings.
19 #include <osgParticle/Export>
20 
21 #include <stdlib.h>
22 
23 #include <osg/Vec2>
24 #include <osg/Vec3>
25 #include <osg/Vec4>
26 
27 namespace osgParticle
28 {
29 
38  template<class ValueType> struct range
39  {
40 
42  ValueType minimum;
43 
45  ValueType maximum;
46 
48  range() : minimum(ValueType()), maximum(ValueType()) {}
49 
51  range(const ValueType& mn, const ValueType& mx) : minimum(mn), maximum(mx) {}
52 
54  void set(const ValueType& mn, const ValueType& mx) { minimum = mn; maximum = mx; }
55 
57  ValueType get_random() const
58  {
59  return minimum + (maximum - minimum) * rand() / RAND_MAX;
60  }
61 
63  ValueType get_random_sqrtf() const
64  {
65  return minimum + (maximum - minimum) * sqrtf( static_cast<float>(rand()) / static_cast<float>(RAND_MAX) );
66  }
67 
68  ValueType mid() const
69  {
70  return (minimum+maximum)*0.5f;
71  }
72 
73  };
74 
77 
80 
83 
86 
87 }
88 
89 #endif
range< osg::Vec4 > rangev4
Range of osg::Vec4s.
Definition: range.h:85
range(const ValueType &mn, const ValueType &mx)
Construct and initialize min and max directly.
Definition: range.h:51
ValueType maximum
Higher bound.
Definition: range.h:45
ValueType mid() const
Definition: range.h:68
ValueType get_random() const
Get a random value between min and max.
Definition: range.h:57
range< osg::Vec3 > rangev3
Range of osg::Vec3s.
Definition: range.h:82
ValueType get_random_sqrtf() const
Get a random square root value between min and max.
Definition: range.h:63
range< float > rangef
Range of floats.
Definition: range.h:76
ValueType minimum
Lower bound.
Definition: range.h:42
void set(const ValueType &mn, const ValueType &mx)
Set min and max.
Definition: range.h:54
range< osg::Vec2 > rangev2
Range of osg::Vec2s.
Definition: range.h:79
range()
Construct the object by calling default constructors for min and max.
Definition: range.h:48