1 // plane.h
2 //
3 // Copyright (C) 2004 Owen Jacobson
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 ojacobson@lionsanctuary.net
20 //
21 module noise.model.plane;
22 
23 private {
24     import noise.mod.modulebase;
25 }
26 
27 /// @addtogroup libnoise
28 /// @{
29 
30 /// @addtogroup models
31 /// @{
32 
33 /// Model that defines the surface of a plane.
34 ///
35 /// This model returns an output value from a noise module given the
36 /// coordinates of an input value located on the surface of an ( @a x,
37 /// @a z ) plane.
38 ///
39 /// To generate an output value, pass the ( @a x, @a z ) coordinates of
40 /// an input value to the GetValue() method.
41 ///
42 /// This model is useful for creating:
43 /// - two-dimensional textures
44 /// - terrain height maps for local areas
45 ///
46 /// This plane extends infinitely in both directions.
47 class Plane
48 {
49 
50   public:
51 
52     /// Constructor.
53     this ()
54     {
55         m_pMod = null;
56     }
57 
58     /// Constructor
59     ///
60     /// @param module The noise module that is used to generate the output
61     /// values.
62     this (ref const(Mod) mod) {
63         m_pMod = &mod;
64     }
65 
66     /// Returns the noise module that is used to generate the output
67     /// values.
68     ///
69     /// @returns A reference to the noise module.
70     ///
71     /// @pre A noise module was passed to the SetMod() method.
72     ref const(Mod) GetMod () const
73     {
74       assert (m_pMod !is null);
75       return *m_pMod;
76     }
77 
78     /// Returns the output value from the noise module given the
79     /// ( @a x, @a z ) coordinates of the specified input value located
80     /// on the surface of the plane.
81     ///
82     /// @param x The @a x coordinate of the input value.
83     /// @param z The @a z coordinate of the input value.
84     ///
85     /// @returns The output value from the noise module.
86     ///
87     /// @pre A noise module was passed to the SetMod() method.
88     ///
89     /// This output value is generated by the noise module passed to the
90     /// SetMod() method.
91     double GetValue (double x, double z) const
92     {
93         assert (m_pMod !is null);
94         return m_pMod.GetValue (x, 0, z);
95     }
96 
97     /// Sets the noise module that is used to generate the output values.
98     ///
99     /// @param module The noise module that is used to generate the output
100     /// values.
101     ///
102     /// This noise module must exist for the lifetime of this object,
103     /// until you pass a new noise module to this method.
104     void SetMod (ref const(Mod) mod)
105     {
106       m_pMod = &mod;
107     }
108 
109   private:
110 
111     /// A pointer to the noise module used to generate the output values.
112     const(Mod)* m_pMod;
113 
114 }
115 
116 /// @}
117 
118 /// @}