source: GTP/trunk/App/Demos/Illum/pathmap/Sphere.hpp @ 2197

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