-
Notifications
You must be signed in to change notification settings - Fork 0
/
Disc.cc
47 lines (41 loc) · 1.1 KB
/
Disc.cc
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
#include "Disc.h"
#include "HitRecord.h"
#include "BoundingBox.h"
#include "Math.h"
#include "Ray.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
Disc::Disc(Material* material, const Vector& normal, double r, const Point& q)
: Primitive(material), n(normal), r(r), q(q)
{
n.normalize();
d = Dot(n, q);
}
Disc::~Disc()
{
}
void Disc::intersect(HitRecord& hit, const RenderContext& context, const Ray& ray) const
{
double denom = Dot(n, ray.direction());
if(Abs(denom) > 1.e-6){ //hit plane
double t = (d-Dot(n, ray.origin()))/denom;
Point hitpos = ray.origin()+ray.direction()*t;
if((hitpos - q).length() < r)
hit.hit(t, this, matl);
}
}
void Disc::normal(Vector& normal, const RenderContext&,
const Point&, const Ray&, const HitRecord&) const
{
normal = n;
}
void Disc::getBounds(BoundingBox& bbox, const RenderContext&) const
{
//double time = context.time();
double radiusT = r;//(time);
Point centerT = q;//(time);
Vector diag(radiusT, radiusT, radiusT);
bbox.extend(centerT+diag);
bbox.extend(centerT-diag);
}