1 // cylinder.cpp 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.cylinder; 23 24 private { 25 import noise.mathconsts; 26 import std.math; 27 import noise.mod.modulebase; 28 } 29 30 class Cylinder { 31 public this () 32 { 33 m_pMod = null; 34 } 35 36 public this (ref const(Mod) mod) 37 { 38 m_pMod = &mod; 39 } 40 41 /// Returns the noise module that is used to generate the output 42 /// values. 43 /// 44 /// @returns A reference to the noise module. 45 /// 46 /// @pre A noise module was passed to the SetMod() method. 47 public ref const(Mod) GetMod () const 48 { 49 assert (m_pMod !is null); 50 return *m_pMod; 51 } 52 53 /// Returns the output value from the noise module given the 54 /// (angle, height) coordinates of the specified input value located 55 /// on the surface of the cylinder. 56 /// 57 /// @param angle The angle around the cylinder's center, in degrees. 58 /// @param height The height along the @a y axis. 59 /// 60 /// @returns The output value from the noise module. 61 /// 62 /// @pre A noise module was passed to the SetMod() method. 63 /// 64 /// This output value is generated by the noise module passed to the 65 /// SetMod() method. 66 /// 67 /// This cylinder has a radius of 1.0 unit and has infinite height. 68 /// It is oriented along the @a y axis. Its center is located at the 69 /// origin. 70 public double GetValue (double angle, double height) const 71 { 72 assert (m_pMod !is null); 73 74 double x, y, z; 75 x = cos (angle * DEG_TO_RAD); 76 y = height; 77 z = sin (angle * DEG_TO_RAD); 78 return m_pMod.GetValue (x, y, z); 79 } 80 81 /// Sets the noise module that is used to generate the output values. 82 /// 83 /// @param module The noise module that is used to generate the output 84 /// values. 85 /// 86 /// This noise module must exist for the lifetime of this object, 87 /// until you pass a new noise module to this method. 88 public void SetMod (ref const(Mod) mod) 89 { 90 m_pMod = &mod; 91 } 92 93 /// A pointer to the noise module used to generate the output values. 94 private const(Mod)* m_pMod; 95 }