1 #ifndef PNP_HXX
 2 #define PNP_HXX
 3 
 4 #include "Primitive.hxx"
 5 
 6 /**
 7  * Procedural Normal Perturbation
 8  * Take all methods from the primitive and adapt only the GetNormal function
 9  */
10 class Perturbation : public Primitive
11 {
12     private:
13         Primitive* primitive;
14         
15         /**
16          * compute the box of the given primitive
17          */
18         Box CalcBounds() 
19         {
20             return (primitive->GetBounds());
21         }
22 
23     public:
24         Perturbation(Primitive* primitive)
25         : primitive(primitive)
26         {};
27         
28         ~Perturbation() 
29         {};
30         
31         /**
32          * intersect the ray with the given primitive
33          */
34         bool Intersect(Ray &ray)
35         {
36             bool hit = primitive->Intersect(ray);
37             
38             if (hit)
39                 {
40                     ray.hit = this;
41                     return true;
42                 }
43             else 
44                 return false;
45         }
46         
47         /**
48          * disturb the normal vector of this primitive randomly
49          * to get new structures
50          */
51         Vec3f GetNormal(Ray &ray)
52         {
53             Vec3f normal = primitive->GetNormal(ray);
54                     
55             if ( normal[1] > drand48() )
56                 {       
57                     normal += 0.15 * Vec3f(drand48(), drand48(), drand48());
58                     Normalize(normal);
59                 }
60 
61             return normal;
62         }
63 };
64 
65 #endif


syntax highlighted by Code2HTML, v. 0.9.1