chore: Cleanup
This commit is contained in:
parent
023a1db4f1
commit
d9cf26902e
12 changed files with 93 additions and 85 deletions
|
@ -1 +0,0 @@
|
|||
'cause Git doesn't like empty directories.
|
|
@ -2,11 +2,10 @@
|
|||
#include "Ray.h"
|
||||
|
||||
bool Plane::intersect(
|
||||
const Ray & ray, const double min_t, double & t, Eigen::Vector3d & n) const
|
||||
{
|
||||
const Ray &ray, const double min_t, double &t, Eigen::Vector3d &n) const {
|
||||
/* Based on
|
||||
* Computer Graphics, Chapter 4. Ray Tracing
|
||||
* Peter Lamber & Glenn Van Wallendael
|
||||
* Peter Lambert & Glenn Van Wallendael
|
||||
*/
|
||||
|
||||
t = -1;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "Sphere.h"
|
||||
#include "Ray.h"
|
||||
|
||||
bool Sphere::intersect(
|
||||
const Ray & ray, const double min_t, double & t, Eigen::Vector3d & n) const
|
||||
{
|
||||
const Ray &ray, const double min_t, double &t, Eigen::Vector3d &n) const {
|
||||
/* Based on
|
||||
* Fundamentals in Computer Graphics - Fourth Edition, Chapter 4.4.1. Ray-Sphere Intersection.
|
||||
* Steve Marschner & Peter Shirley
|
||||
|
@ -10,17 +10,17 @@ bool Sphere::intersect(
|
|||
|
||||
/* Intersection points occur when points on the ray satisfy the implicit equation. */
|
||||
|
||||
double a = ray.direction.dot(ray.direction);
|
||||
double b = ray.direction.dot(ray.origin - center);
|
||||
double c = (ray.origin - center).dot(ray.origin - center) - radius * radius;
|
||||
double discriminant = (2 * b) * (2 * b) - 4 * a * c;
|
||||
const double a = ray.direction.dot(ray.direction);
|
||||
const double b = ray.direction.dot(ray.origin - center);
|
||||
const double c = (ray.origin - center).dot(ray.origin - center) - radius * radius;
|
||||
const double discriminant = (2 * b) * (2 * b) - 4 * a * c;
|
||||
|
||||
/* If the discriminant is less than zero, the ray does not intersect with the sphere. */
|
||||
if (discriminant < 0) return false;
|
||||
|
||||
/* Calculate the first intersection t. */
|
||||
double under_root = b * b - a * c;
|
||||
double ta = (0 - b - sqrt(under_root)) / a;
|
||||
const double under_root = b * b - a * c;
|
||||
const double ta = (0 - b - sqrt(under_root)) / a;
|
||||
double tb = (0 - b + sqrt(under_root)) / a;
|
||||
/* Choose the smallest that is still larger than min_t. */
|
||||
if (ta < min_t && tb < min_t) {
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
#include <Eigen/Geometry> // hint
|
||||
|
||||
bool Triangle::intersect(
|
||||
const Ray & ray, const double min_t, double & t, Eigen::Vector3d & n) const
|
||||
{
|
||||
const Ray &ray, const double min_t, double &t, Eigen::Vector3d &n) const {
|
||||
/* Based on
|
||||
* Fundamentals in Computer Graphics - Fourth Edition, Chapter 4.4.2. Ray-Triangle Intersection.
|
||||
* Steve Marschner & Peter Shirley
|
||||
|
@ -23,7 +22,7 @@ bool Triangle::intersect(
|
|||
A.col(0) = a - b;
|
||||
A.col(1) = a - c;
|
||||
A.col(2) = d;
|
||||
double determinant_A = A.determinant();
|
||||
const double determinant_A = A.determinant();
|
||||
|
||||
Eigen::Matrix3d t_matrix;
|
||||
t_matrix.col(0) = a - b;
|
||||
|
@ -56,4 +55,4 @@ bool Triangle::intersect(
|
|||
n = edge1.cross(edge2).normalized(); /* Don't forget to normalize the vector. */
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include "first_hit.h"
|
||||
|
||||
bool TriangleSoup::intersect(
|
||||
const Ray & ray, const double min_t, double & t, Eigen::Vector3d & n) const
|
||||
{
|
||||
const Ray &ray, const double min_t, double &t, Eigen::Vector3d &n) const {
|
||||
int hit_id; /* Ignored. */
|
||||
return first_hit(ray, min_t, triangles, hit_id, t, n);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
#include "first_hit.h"
|
||||
|
||||
bool first_hit(
|
||||
const Ray & ray,
|
||||
const Ray &ray,
|
||||
const double min_t,
|
||||
const std::vector< std::shared_ptr<Object> > & objects,
|
||||
int & hit_id,
|
||||
double & t,
|
||||
Eigen::Vector3d & n)
|
||||
{
|
||||
const std::vector<std::shared_ptr<Object> > &objects,
|
||||
int &hit_id,
|
||||
double &t,
|
||||
Eigen::Vector3d &n) {
|
||||
double t_temp;
|
||||
Eigen::Vector3d n_temp;
|
||||
|
||||
bool hit = false;
|
||||
/* Initialize to a value that will never be used. */
|
||||
t = -1;
|
||||
/* Alternatively, use a max integer value, and remove the check t == -1. */
|
||||
|
||||
/* Store intermediate results that are not necessarily the first hit. */
|
||||
double t_temp;
|
||||
Eigen::Vector3d n_temp;
|
||||
|
||||
for (int i = 0; i < objects.size(); ++i) {
|
||||
if (objects[i]->intersect(ray, min_t, t_temp, n_temp)) {
|
||||
hit = true;
|
||||
|
@ -30,4 +29,3 @@ bool first_hit(
|
|||
|
||||
return hit;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include "viewing_ray.h"
|
||||
|
||||
void viewing_ray(
|
||||
const Camera & camera,
|
||||
const Camera &camera,
|
||||
const int i,
|
||||
const int j,
|
||||
const int width,
|
||||
const int height,
|
||||
Ray & ray)
|
||||
{
|
||||
Ray &ray) {
|
||||
/* Based on
|
||||
* Fundamentals in Computer Graphics - Fourth Edition, Chapter 4.3.2 Perspective views.
|
||||
* Steve Marschner & Peter Shirley
|
||||
|
|
Reference in a new issue