1 // cylinder.h
2 //
3 // Copyright 2003, 2004 Jason Bevins
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or (at
8 // your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13 // License (COPYING.txt) for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 //
19 // The developer's email is jlbezigvins@gmzigail.com (for great email, take
20 // off every 'zig'.)
21 //
22 
23 #ifndef NOISE_MODEL_CYLINDER_H
24 #define NOISE_MODEL_CYLINDER_H
25 
26 #include <assert.h>
27 #include <math.h>
28 #include <stdlib.h>
29 #include "../module/modulebase.h"
30 
31 namespace noise
32 {
33 
34   namespace model
35   {
36 
37     /// @addtogroup libnoise
38     /// @{
39 
40     /// @defgroup models Models
41     /// @addtogroup models
42     /// @{
43 
44     /// Model that defines the surface of a cylinder.
45     ///
46     /// @image html modelcylinder.png
47     ///
48     /// This model returns an output value from a noise module given the
49     /// coordinates of an input value located on the surface of a cylinder.
50     ///
51     /// To generate an output value, pass the (angle, height) coordinates of
52     /// an input value to the GetValue() method.
53     ///
54     /// This model is useful for creating:
55     /// - seamless textures that can be mapped onto a cylinder
56     ///
57     /// This cylinder has a radius of 1.0 unit and has infinite height.  It is
58     /// oriented along the @a y axis.  Its center is located at the origin.
59     class Cylinder
60     {
61 
62       public:
63 
64         /// Constructor.
65         Cylinder ();
66 
67         /// Constructor
68         ///
69         /// @param module The noise module that is used to generate the output
70         /// values.
71         Cylinder (const module::Module& module);
72 
73         /// Returns the noise module that is used to generate the output
74         /// values.
75         ///
76         /// @returns A reference to the noise module.
77         ///
78         /// @pre A noise module was passed to the SetModule() method.
GetModule()79         const module::Module& GetModule () const
80         {
81           assert (m_pModule != NULL);
82           return *m_pModule;
83         }
84 
85         /// Returns the output value from the noise module given the
86         /// (angle, height) coordinates of the specified input value located
87         /// on the surface of the cylinder.
88         ///
89         /// @param angle The angle around the cylinder's center, in degrees.
90         /// @param height The height along the @a y axis.
91         ///
92         /// @returns The output value from the noise module.
93         ///
94         /// @pre A noise module was passed to the SetModule() method.
95         ///
96         /// This output value is generated by the noise module passed to the
97         /// SetModule() method.
98         ///
99         /// This cylinder has a radius of 1.0 unit and has infinite height.
100         /// It is oriented along the @a y axis.  Its center is located at the
101         /// origin.
102         double GetValue (double angle, double height) const;
103 
104         /// Sets the noise module that is used to generate the output values.
105         ///
106         /// @param module The noise module that is used to generate the output
107         /// values.
108         ///
109         /// This noise module must exist for the lifetime of this object,
110         /// until you pass a new noise module to this method.
SetModule(const module::Module & module)111         void SetModule (const module::Module& module)
112         {
113           m_pModule = &module;
114         }
115 
116       private:
117 
118         /// A pointer to the noise module used to generate the output values.
119         const module::Module* m_pModule;
120 
121     };
122 
123   /// @}
124 
125   /// @}
126 
127   }
128 
129 }
130 
131 #endif
132