-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSphere.h
71 lines (54 loc) · 1.49 KB
/
Sphere.h
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
/*
* File: Sphere.h
* Author: caos
*
* Created on June 18, 2015, 12:22 PM
*/
#ifndef SPHERE_H
#define SPHERE_H
#include <cstdlib>
#include <cmath>
#include "Surface.h"
#include "Ray.h"
#include "Vector.h"
#include "Vector.h"
#include "Color.h"
#include "BoundingBox.h"
class Sphere : public Surface
{
public:
Sphere(float _radius, const Point& _center, const Material& _material) \
: radius(_radius), center(_center), material(_material) { bb = NULL; };
Sphere(const Sphere& s) : radius(s.radius), center(s.center), material(s.material), bb(s.bb) {};
bool hit(Ray& r, float& t, Surface** who, Vector& normal, Point& intersect);
bool isHit(Ray& r);
Material getMaterial() { return material; };
virtual BoundingBox getBoundingBox()
{
if(bb==NULL)
{
Vector rad = Vector(radius, radius, radius);
Vector maxV = Vector::add(center, rad);
rad = Vector::multiply(rad, -1.f);
Vector minV = Vector::add(center, rad);
bb = new BoundingBox(minV, maxV);
}
return *bb;
};
virtual Sphere* clone()
{
Sphere* s = new Sphere(radius, center, material);
return s;
};
virtual ~Sphere()
{
if(bb!=NULL) delete bb;
};
private:
float radius;
Point center;
Material material;
BoundingBox* bb;
float delta(Ray& r);
};
#endif /* SPHERE_H */