-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.cpp
25 lines (22 loc) · 893 Bytes
/
Field.cpp
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
//
// Field.cpp
// Curvature
//
// Created by Simon Demeule on 2019-10-01.
// Copyright © 2019 Simon Demeule. All rights reserved.
//
#include "Field.hpp"
#include <glm/glm.hpp>
FieldIntersection Field::intersection(Ray ray) {
BoundedObjectIntersection intersectionBox = boundingBox.intersection(ray);
FieldIntersection intersectionField;
// this is necessary because the bounding box intersection function uniquely allows negative distances. we don't want that here.
intersectionField.exists = intersectionBox.exists && intersectionBox.distance >= 0;
if(intersectionBox.exists) {
intersectionField.object = this;
intersectionField.distance = intersectionBox.distance;
intersectionField.origin = ray.origin + ray.direction * intersectionBox.distance;
intersectionField.incident = ray.direction;
}
return intersectionField;
}