-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsphere.h
43 lines (31 loc) · 1.25 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
#ifndef _SPHERE_H_
#define _SPHERE_H_
#include "primitive.h"
#include "vectors.h"
// ====================================================================
// ====================================================================
// Simple implicit repesentation of a sphere, that can also be
// rasterized for use in radiosity.
class Sphere : public Primitive {
public:
// CONSTRUCTOR & DESTRUCTOR
Sphere(const Vec3f &c, double r, Material *m) {
center = c; radius = r; material = m;
assert (radius >= 0); }
// for ray tracing
virtual bool intersect(const Ray &r, Hit &h) const;
// for OpenGL rendering & radiosity
void addRasterizedFaces(Mesh *m, ArgParser *args);
double getRadius() { return radius; }
Vec3f getCenter() { return center; }
friend std::ostream& operator<< (std::ostream &ostr, const Sphere &s) {
ostr << "sphere centered at (" << s.center.x() << ", " << s.center.y() << ", " << s.center.z() << "), radius " << s.radius;
return ostr; }
private:
// REPRESENTATION
Vec3f center;
double radius;
};
// ====================================================================
// ====================================================================
#endif