-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlane.cpp
More file actions
26 lines (23 loc) · 875 Bytes
/
Copy pathPlane.cpp
File metadata and controls
26 lines (23 loc) · 875 Bytes
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
//
// Created by Jiang Kairong on 3/10/18.
//
#include "Plane.h"
Plane::Plane(const Vector3d &point, const Vector3d &normal, const ColorRGB32f &colorAmbient, const ColorRGB32f &colorDiffuse,
const ColorRGB32f &colorSpecular, double phongExponent) : Surface(colorAmbient, colorDiffuse, colorSpecular,
phongExponent), point(point),
normal(normal.normalize()) {
}
bool Plane::intersect(const Ray &ray, IntersectionInfo &info){
if (ray.getD().dot(normal) == 0.) {
return false;
}
Vector3d k = ray.getS() - point;
double t = -k.dot(normal) / ray.getD().dot(normal);
if (t < 0) {
return false;
}
if (updateIntersectInfo(info, ray, t)) {
info.hitNormal = normal.normalize();
}
return true;
}