1 // sphere.h 2 // 3 // Copyright (C) 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 module noise.model.sphere; 23 24 private { 25 import noise.mod.modulebase; 26 import noise.latlon; 27 } 28 /// @addtogroup libnoise 29 /// @{ 30 31 /// @addtogroup models 32 /// @{ 33 34 /// Model that defines the surface of a sphere. 35 /// 36 /// @image html modelsphere.png 37 /// 38 /// This model returns an output value from a noise module given the 39 /// coordinates of an input value located on the surface of a sphere. 40 /// 41 /// To generate an output value, pass the (latitude, longitude) 42 /// coordinates of an input value to the GetValue() method. 43 /// 44 /// This model is useful for creating: 45 /// - seamless textures that can be mapped onto a sphere 46 /// - terrain height maps for entire planets 47 /// 48 /// This sphere has a radius of 1.0 unit and its center is located at 49 /// the origin. 50 class Sphere 51 { 52 53 public: 54 55 /// Constructor. 56 this () 57 { 58 m_pMod = null; 59 } 60 61 /// Constructor 62 /// 63 /// @param module The noise module that is used to generate the output 64 /// values. 65 this (ref const(Mod) mod) 66 { 67 m_pMod = &mod; 68 } 69 70 /// Returns the noise module that is used to generate the output 71 /// values. 72 /// 73 /// @returns A reference to the noise module. 74 /// 75 /// @pre A noise module was passed to the SetMod() method. 76 ref const(Mod) GetMod () const 77 { 78 assert (m_pMod !is null); 79 return *m_pMod; 80 } 81 82 /// Returns the output value from the noise module given the 83 /// (latitude, longitude) coordinates of the specified input value 84 /// located on the surface of the sphere. 85 /// 86 /// @param lat The latitude of the input value, in degrees. 87 /// @param lon The longitude of the input value, in degrees. 88 /// 89 /// @returns The output value from the noise module. 90 /// 91 /// @pre A noise module was passed to the SetMod() method. 92 /// 93 /// This output value is generated by the noise module passed to the 94 /// SetMod() method. 95 /// 96 /// Use a negative latitude if the input value is located on the 97 /// southern hemisphere. 98 /// 99 /// Use a negative longitude if the input value is located on the 100 /// western hemisphere. 101 double GetValue (double lat, double lon) const 102 { 103 assert (m_pMod !is null); 104 105 double x, y, z; 106 LatLonToXYZ (lat, lon, x, y, z); 107 return m_pMod.GetValue (x, y, z); 108 } 109 110 /// Sets the noise module that is used to generate the output values. 111 /// 112 /// @param module The noise module that is used to generate the output 113 /// values. 114 /// 115 /// This noise module must exist for the lifetime of this object, 116 /// until you pass a new noise module to this method. 117 void SetMod (ref const(Mod) mod) 118 { 119 m_pMod = &mod; 120 } 121 122 private: 123 124 /// A pointer to the noise module used to generate the output values. 125 const(Mod)* m_pMod; 126 127 }; 128 129 /// @} 130 131 /// @}