-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.cc
40 lines (34 loc) · 836 Bytes
/
Plane.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
#include "Plane.h"
#include "HitRecord.h"
#include "Math.h"
#include "Ray.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
Plane::Plane(Material* material, const Vector& normal, const Point& point)
: Primitive(material), n(normal)
{
n.normalize();
d = Dot(n, point);
}
Plane::~Plane()
{
}
void Plane::intersect(HitRecord& hit, const RenderContext& context, const Ray& ray) const
{
double denom = Dot(n, ray.direction());
if(Abs(denom) > 1.e-6){
double t = (d-Dot(n, ray.origin()))/denom;
hit.hit(t, this, matl);
}
}
void Plane::normal(Vector& normal, const RenderContext&,
const Point&, const Ray&, const HitRecord&) const
{
normal = n;
}
void Plane::getBounds(BoundingBox& bbox, const RenderContext&) const
{
cerr << "Plane::getBounds() called!" << endl;
exit( 1 );
}