1 // const.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.mod.constants; 23 24 private { 25 import noise.mod.modulebase; 26 debug import std.stdio; 27 } 28 29 /// @addtogroup libnoise 30 /// @{ 31 32 /// @addtogroup modules 33 /// @{ 34 35 /// @defgroup generatormodules Generator Mods 36 /// @addtogroup generatormodules 37 /// @{ 38 39 /// Default constant value for the module::Const noise module. 40 const double DEFAULT_CONST_VALUE = 0.0; 41 42 /// Noise module that outputs a constant value. 43 /// 44 /// @image html moduleconst.png 45 /// 46 /// To specify the constant value, call the SetConstValue() method. 47 /// 48 /// This noise module is not useful by itself, but it is often used as a 49 /// source module for other noise modules. 50 /// 51 /// This noise module does not require any source modules. 52 class Constant : Mod 53 { 54 55 public: 56 57 /// Constructor. 58 /// 59 /// The default constant value is set to 60 /// module::DEFAULT_CONST_VALUE. 61 this() 62 { 63 super(this.GetSourceModCount()); 64 m_constValue = DEFAULT_CONST_VALUE; 65 } 66 67 this(double constant) { 68 super(this.GetSourceModCount()); 69 m_constValue = constant; 70 } 71 72 /// Returns the constant output value for this noise module. 73 /// 74 /// @returns The constant output value for this noise module. 75 double GetConstValue () const 76 { 77 return m_constValue; 78 } 79 80 override int GetSourceModCount () const 81 { 82 return 0; 83 } 84 85 override double GetValue (double x, double y, double z) const 86 { 87 return m_constValue; 88 } 89 90 /// Sets the constant output value for this noise module. 91 /// 92 /// @param constValue The constant output value for this noise module. 93 void SetConstValue (double constValue) 94 { 95 m_constValue = constValue; 96 } 97 98 protected: 99 100 /// Constant value. 101 double m_constValue; 102 103 }; 104 105 /// @} 106 107 /// @} 108 109 /// @}