source: GTP/trunk/App/Demos/Illum/pathmap/Cylinder.h @ 2197

Revision 2197, 2.0 KB checked in by szirmay, 17 years ago (diff)
Line 
1#pragma once
2#include "Intersectable.hpp"
3#include "Occluder.hpp"
4
5class Cylinder :
6        public Intersectable
7{
8//      const Material*         material;
9        Vector  centre;
10        float   radius;
11        float top;
12        float bottom;
13public:
14        Cylinder(std::istream& isc, Material** materialTable, int nMaterials)
15                :centre(centre),radius(radius), top(top), bottom(bottom)
16        {
17                centre.clear();
18                radius = 1.0f;
19                material = &Material::DIFFUSEWHITE;
20                top = 100.0f;
21                bottom = -100.0f;
22                char key[200];
23                do
24                {
25                        isc >> key;
26                        if(strcmp(key,"radius") == 0)   isc >> radius;
27                        else if(strcmp(key,"centre") == 0)      isc >> centre;
28                        else if(strcmp(key,"top") == 0) isc >> top;
29                        else if(strcmp(key,"bottom") == 0)      isc >> bottom;
30                        else if(strcmp(key,"material") == 0)
31                        {
32                                isc >> key;
33                                for(int i=0; i < nMaterials; i++)
34                                {
35                                        material = materialTable[i];
36                                        if(strcmp(key, material->getName()) == 0) break;
37                                }
38                        }
39                }while(strcmp(key,"end") != 0);
40                Vector diagonal(radius, radius, radius);
41                bbox.minPoint = centre - diagonal;
42                bbox.maxPoint = centre + diagonal;
43                bbox.minPoint.y = bottom;
44                bbox.maxPoint.y = top;
45                nOccluders = 1;
46                occluders = new Occluder(centre, radius);
47        }
48        Cylinder(const Vector& centre, const float radius,
49                const float top, const float bottom,
50                const Material* material)
51                :centre(centre),radius(radius), top(top), bottom(bottom)
52        {
53                this->material = material;
54                Vector diagonal(radius, radius, radius);
55                bbox.minPoint = centre - diagonal;
56                bbox.maxPoint = centre + diagonal;
57                bbox.minPoint.y = bottom;
58                bbox.maxPoint.y = top;
59                nOccluders = 1;
60                occluders = new Occluder(centre, radius);
61        }
62        bool intersectBackSide(const Ray& ray, float& depth, float rayMin, float rayMax );
63        bool intersect(const Ray& ray, float& depth, float rayMin, float rayMax);
64        Vector getShadingNormal(const Vector& point)
65        {
66                if(point.y >= top - 0.000001f)
67                        return Vector(0.0f, 1.0f, 0.0f);
68                if(point.y <= bottom + 0.000001f)
69                        return Vector(0.0f, -1.0f, 0.0f);
70                Vector normal = point - centre;
71                normal.y = 0.0f;
72                normal *= 1.0f / radius;
73                return normal;
74        }
75};
Note: See TracBrowser for help on using the repository browser.