1 #ifndef PROCEDURALCAPRPET_HXX
 2 #define PROCEDURALCARPET_HXX
 3 
 4 #include "Procedural.hxx"
 5 #include "Noise.hxx"
 6 
 7 // This class creates the rice straw mat bumpmapping (a simple sine wave)
 8 class ProceduralCarpet : public Procedural
 9 {
10 private:
11 	float factor,
12 	      weight;
13 
14 	Vec3f Direction,
15 	      LightColor,
16 	      DarkColor;
17 
18 	Vec3f ToColor(float value)
19 	{
20 		return value * (LightColor - DarkColor) + DarkColor;
21 	}
22 	
23 public:
24 	ProceduralCarpet(bool useTexture, bool useBumpMap, float factor, float weight, Vec3f Direction, Vec3f LightColor = Vec3f(0.87f,0.82f,0.67f), Vec3f DarkColor = Vec3f(0.52f,0.49f,0.40f))
25 		: Procedural(useTexture, useBumpMap, true, true), factor(factor), weight(weight), Direction(Direction),
26 		  LightColor(LightColor), DarkColor(DarkColor)
27 	{};
28 
29 	virtual ~ProceduralCarpet()
30 	{};
31 
32 	// Returns the different color values of the rice straw grains
33 	virtual Vec3f GetColor (Vec3f coordinate)
34 	{
35 		return ToColor((sin(Dot(coordinate,Direction)*factor) + 1) / 0.5);
36 	};
37 
38 	// Perturb the normal
39 	virtual void BumpMap(Vec3f &normal, Vec3f coordinate)
40 	{
41 		normal += Direction * weight * (sin(Dot(coordinate,Direction)*factor) + 1) / 0.5;
42 		Normalize(normal);
43 	};
44 };
45 
46 #endif


syntax highlighted by Code2HTML, v. 0.9.1