blob: d7e57adecfb435a28431932d149840ade3f74c38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System.Diagnostics;
namespace LibNoise.Operator
{
/// <summary>
/// Provides a noise module that outputs a weighted blend of the output values from
/// two source modules given the output value supplied by a control module. [OPERATOR]
/// </summary>
public class Blend : ModuleBase
{
#region Constructors
/// <summary>
/// Initializes a new instance of Blend.
/// </summary>
public Blend()
: base(3)
{
}
/// <summary>
/// Initializes a new instance of Blend.
/// </summary>
/// <param name="lhs">The left hand input module.</param>
/// <param name="rhs">The right hand input module.</param>
/// <param name="controller">The controller of the operator.</param>
public Blend(ModuleBase lhs, ModuleBase rhs, ModuleBase controller)
: base(3)
{
Modules[0] = lhs;
Modules[1] = rhs;
Modules[2] = controller;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the controlling module.
/// </summary>
public ModuleBase Controller
{
get { return Modules[2]; }
set
{
Debug.Assert(value != null);
Modules[2] = value;
}
}
#endregion
#region ModuleBase Members
/// <summary>
/// Returns the output value for the given input coordinates.
/// </summary>
/// <param name="x">The input coordinate on the x-axis.</param>
/// <param name="y">The input coordinate on the y-axis.</param>
/// <param name="z">The input coordinate on the z-axis.</param>
/// <returns>The resulting output value.</returns>
public override double GetValue(double x, double y, double z)
{
Debug.Assert(Modules[0] != null);
Debug.Assert(Modules[1] != null);
Debug.Assert(Modules[2] != null);
var a = Modules[0].GetValue(x, y, z);
var b = Modules[1].GetValue(x, y, z);
var c = (Modules[2].GetValue(x, y, z) + 1.0) / 2.0;
return Utils.InterpolateLinear(a, b, c);
}
#endregion
}
}
|